-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve showFirstLastPageButtons (#634)
Co-authored-by: Domino987 <[email protected]>
- Loading branch information
Showing
7 changed files
with
180 additions
and
13 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,130 @@ | ||
import * as React from 'react'; | ||
import { | ||
screen, | ||
render, | ||
waitForElementToBeRemoved | ||
} from '@testing-library/react'; | ||
import MaterialTable from '../src'; | ||
import '@testing-library/jest-dom'; | ||
|
||
describe('Show Pagination Buttons', () => { | ||
test('Show no buttons', async () => { | ||
render( | ||
<MaterialTable | ||
data={[ | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' } | ||
]} | ||
columns={[ | ||
{ title: 'Name', field: 'name', width: 40 }, | ||
{ title: 'Notes', field: 'notes', width: 200 } | ||
]} | ||
options={{ | ||
showFirstLastPageButtons: false | ||
}} | ||
/> | ||
); | ||
screen.getByRole('button', { name: /previous page/i }); | ||
screen.getByRole('button', { name: /next page/i }); | ||
expect(screen.queryByRole('button', { name: /first page/i })).toBeNull(); | ||
expect(screen.queryByRole('button', { name: /last page/i })).toBeNull(); | ||
}); | ||
test('Show first buttons', async () => { | ||
render( | ||
<MaterialTable | ||
data={[ | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' } | ||
]} | ||
columns={[ | ||
{ title: 'Name', field: 'name', width: 40 }, | ||
{ title: 'Notes', field: 'notes', width: 200 } | ||
]} | ||
options={{ | ||
showFirstLastPageButtons: { last: false } | ||
}} | ||
/> | ||
); | ||
screen.getByRole('button', { name: /previous page/i }); | ||
screen.getByRole('button', { name: /next page/i }); | ||
screen.getByRole('button', { name: /first page/i }); | ||
expect(screen.queryByRole('button', { name: /last page/i })).toBeNull(); | ||
}); | ||
test('Show last buttons', async () => { | ||
render( | ||
<MaterialTable | ||
data={[ | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' } | ||
]} | ||
columns={[ | ||
{ title: 'Name', field: 'name', width: 40 }, | ||
{ title: 'Notes', field: 'notes', width: 200 } | ||
]} | ||
options={{ | ||
showFirstLastPageButtons: { first: false } | ||
}} | ||
/> | ||
); | ||
screen.getByRole('button', { name: /previous page/i }); | ||
screen.getByRole('button', { name: /next page/i }); | ||
screen.getByRole('button', { name: /last page/i }); | ||
expect(screen.queryByRole('button', { name: /first page/i })).toBeNull(); | ||
}); | ||
test('Show all buttons', async () => { | ||
render( | ||
<MaterialTable | ||
data={[ | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' }, | ||
{ name: 'Smith', notes: 'A common name' } | ||
]} | ||
columns={[ | ||
{ title: 'Name', field: 'name', width: 40 }, | ||
{ title: 'Notes', field: 'notes', width: 200 } | ||
]} | ||
options={{}} | ||
/> | ||
); | ||
|
||
screen.getByRole('button', { name: /previous page/i }); | ||
screen.getByRole('button', { name: /next page/i }); | ||
screen.getByRole('button', { name: /first page/i }); | ||
screen.getByRole('button', { name: /last page/i }); | ||
}); | ||
}); |
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
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
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