-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MMT-3561: Writing tests for pagination
- Loading branch information
1 parent
e0b8e6e
commit a6e54e2
Showing
5 changed files
with
72 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
static/src/js/components/Pagination/__tests__/Pagination.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react' | ||
import { | ||
render, | ||
screen, | ||
fireEvent | ||
} from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import PaginationComponent from '../Pagination' | ||
|
||
const setoffset = jest.fn() | ||
|
||
const setup = () => { | ||
const props = { | ||
limit: 2, | ||
count: 14, | ||
setoffset | ||
} | ||
render( | ||
<PaginationComponent {...props} /> | ||
) | ||
|
||
return { | ||
props, | ||
user: userEvent.setup() | ||
} | ||
} | ||
|
||
describe('Pagination', () => { | ||
describe('when pagination component is passed count < limit', () => { | ||
test('renders pagination bar', () => { | ||
setup() | ||
|
||
expect(screen.queryAllByRole('button')).toHaveLength(3) | ||
|
||
// Check individual buttons work | ||
fireEvent.click(screen.getByRole('button', { name: '2' })) | ||
|
||
// Check the next button works | ||
fireEvent.click(screen.getByRole('button', { name: 'Next' })) | ||
|
||
// // Click on Previous Page | ||
fireEvent.click(screen.getByRole('button', { name: 'Previous' })) | ||
|
||
// // Check pages[0] always stays at 1 and two ellipsis render | ||
fireEvent.click(screen.getByRole('button', { name: 'Next' })) | ||
fireEvent.click(screen.getByRole('button', { name: '4' })) | ||
expect(screen.getByRole('button', { name: '1' })) | ||
expect(screen.queryAllByText('More')).toHaveLength(2) | ||
|
||
// Make sure onclick for pages[0] function above works | ||
fireEvent.click(screen.getByRole('button', { name: '1' })) | ||
|
||
// Can click on last page | ||
fireEvent.click(screen.getByRole('button', { name: '7' })) | ||
fireEvent.click(screen.getByRole('button', { name: 'Previous' })) | ||
fireEvent.click(screen.getByRole('button', { name: 'Previous' })) | ||
expect(screen.queryAllByText('More')).toHaveLength(1) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters