-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import Pagination from './pagination'; | ||
|
||
describe('Pagination test cases', () => { | ||
test('renders correctly', () => { | ||
render(<Pagination itemsPerPage={10} totalItems={50} currentPage={1} onPageChange={() => {}} />); | ||
|
||
for (let i = 1; i <= 5; i++) { | ||
expect(screen.getByText(i.toString())).toBeInTheDocument(); | ||
} | ||
}); | ||
|
||
test('calls onPageChange with correct page number when a page button is clicked', async () => { | ||
const onPageChange = jest.fn(); | ||
render(<Pagination itemsPerPage={10} totalItems={50} currentPage={1} onPageChange={onPageChange} />); | ||
|
||
await userEvent.click(screen.getByText('2')); | ||
|
||
expect(onPageChange).toHaveBeenCalledWith(2); | ||
}); | ||
|
||
test('disables the button of the current page', () => { | ||
render(<Pagination itemsPerPage={10} totalItems={50} currentPage={1} onPageChange={() => {}} />); | ||
|
||
expect(screen.getByText('1')).toBeDisabled(); | ||
}); | ||
}); |