11import * as React from 'react' ;
2- import { assert } from 'chai' ;
2+ import { expect , assert } from 'chai' ;
33import PropTypes from 'prop-types' ;
44import { createMount , getClasses } from '@material-ui/core/test-utils' ;
5+ import { fireEvent , createClientRender } from 'test/utils/createClientRender' ;
56import describeConformance from '../test-utils/describeConformance' ;
67import consoleErrorMock from 'test/utils/consoleErrorMock' ;
78import Select from '../Select' ;
@@ -16,6 +17,7 @@ describe('<TablePagination />', () => {
1617 const noop = ( ) => { } ;
1718 let classes ;
1819 let mount ;
20+ const render = createClientRender ( ) ;
1921
2022 function mountInTable ( node ) {
2123 const wrapper = mount (
@@ -32,11 +34,14 @@ describe('<TablePagination />', () => {
3234 classes = getClasses (
3335 < TablePagination count = { 1 } onChangePage = { ( ) => { } } page = { 0 } rowsPerPage = { 10 } /> ,
3436 ) ;
35- // StrictModeViolation: test uses #html()
37+ } ) ;
38+
39+ beforeEach ( ( ) => {
40+ // StrictModeViolation: test uses #html()()
3641 mount = createMount ( { strict : false } ) ;
3742 } ) ;
3843
39- after ( ( ) => {
44+ afterEach ( ( ) => {
4045 mount . cleanUp ( ) ;
4146 } ) ;
4247
@@ -248,6 +253,36 @@ describe('<TablePagination />', () => {
248253 } ) ;
249254 } ) ;
250255
256+ describe ( 'prop: count=-1' , ( ) => {
257+ it ( 'should display the "of more than" text and keep the nextButton enabled' , ( ) => {
258+ const Test = ( ) => {
259+ const [ page , setPage ] = React . useState ( 0 ) ;
260+ return (
261+ < table >
262+ < TableFooter >
263+ < TableRow >
264+ < TablePagination
265+ page = { page }
266+ rowsPerPage = { 10 }
267+ count = { - 1 }
268+ onChangePage = { ( _ , newPage ) => {
269+ setPage ( newPage ) ;
270+ } }
271+ />
272+ </ TableRow >
273+ </ TableFooter >
274+ </ table >
275+ ) ;
276+ } ;
277+
278+ const { container, getByLabelText } = render ( < Test /> ) ;
279+
280+ expect ( container ) . to . have . text ( 'Rows per page:101-10 of more than 10' ) ;
281+ fireEvent . click ( getByLabelText ( 'Next page' ) ) ;
282+ expect ( container ) . to . have . text ( 'Rows per page:1011-20 of more than 20' ) ;
283+ } ) ;
284+ } ) ;
285+
251286 describe ( 'warnings' , ( ) => {
252287 before ( ( ) => {
253288 consoleErrorMock . spy ( ) ;
@@ -282,33 +317,4 @@ describe('<TablePagination />', () => {
282317 ) ;
283318 } ) ;
284319 } ) ;
285-
286- it ( 'should display the "of more than" text and keep the nextButton enabled, if count is -1 ' , ( ) => {
287- const wrapper = mount (
288- < table >
289- < TableFooter >
290- < TableRow >
291- < TablePagination
292- page = { 0 }
293- rowsPerPage = { 5 }
294- rowsPerPageOptions = { [ 5 ] }
295- onChangePage = { noop }
296- onChangeRowsPerPage = { noop }
297- count = { - 1 }
298- />
299- </ TableRow >
300- </ TableFooter >
301- </ table > ,
302- ) ;
303-
304- assert . strictEqual (
305- wrapper
306- . find ( Typography )
307- . at ( 0 )
308- . text ( ) ,
309- '1-5 of more than 5' ,
310- ) ;
311- const nextButton = wrapper . find ( IconButton ) . at ( 1 ) ;
312- assert . strictEqual ( nextButton . props ( ) . disabled , false ) ;
313- } ) ;
314320} ) ;
0 commit comments