-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vadcDataDictionaryTable): Added working pagination controls test
- Loading branch information
1 parent
53d5a16
commit f516484
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/Analysis/DataDictionary/PaginationControls/PaginationControls.test.tsx
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,49 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import '@mantine/core/styles.css'; // ensure styles are loaded for testing | ||
import PaginationControls from './PaginationControls'; | ||
|
||
describe('PaginationControls', () => { | ||
const defaultProps = { | ||
entriesShown: 10, | ||
setEntriesShown: jest.fn(), | ||
activePage: 1, | ||
setActivePage: jest.fn(), | ||
totalEntriesAvailable: 30, | ||
}; | ||
|
||
it('should render PaginationControls with correct initial state', () => { | ||
const { getByTestId, getByLabelText } = render( | ||
<PaginationControls {...defaultProps} /> | ||
); | ||
|
||
expect(getByTestId('pagination-controls')).toBeInTheDocument(); | ||
expect(getByLabelText('Show')).toBeInTheDocument(); | ||
expect(getByLabelText('entries')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call setEntriesShown when select value changes', () => { | ||
const { getByTestId, getByLabelText } = render( | ||
<PaginationControls {...defaultProps} /> | ||
); | ||
|
||
const entriesSelect = getByTestId('entries-select'); | ||
|
||
fireEvent.change(entriesSelect, { target: { value: '20' } }); | ||
|
||
expect(defaultProps.setEntriesShown).toHaveBeenCalledWith(20); | ||
}); | ||
|
||
it('should call setActivePage when pagination button is clicked', () => { | ||
const { getByTestId, getAllByRole } = render( | ||
<PaginationControls {...defaultProps} /> | ||
); | ||
|
||
const nextButton = getAllByRole('button', { name: /2/i })[0]; | ||
|
||
fireEvent.click(nextButton); | ||
|
||
expect(defaultProps.setActivePage).toHaveBeenCalledWith(2); | ||
}); | ||
}); |
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