Skip to content

Commit e3f27d7

Browse files
dbarabashhEsoterikStare
authored andcommitted
[TablePagination] Out of range warning when "count={-1}" (mui#19874)
1 parent a6b66fe commit e3f27d7

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

packages/material-ui/src/TablePagination/TablePagination.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ TablePagination.propTypes = {
246246
*/
247247
page: chainPropTypes(PropTypes.number.isRequired, props => {
248248
const { count, page, rowsPerPage } = props;
249+
250+
if (count === -1) {
251+
return null;
252+
}
253+
249254
const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
250255
if (page < 0 || page > newLastPage) {
251256
return new Error(

packages/material-ui/src/TablePagination/TablePagination.test.js

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as React from 'react';
2-
import { assert } from 'chai';
2+
import { expect, assert } from 'chai';
33
import PropTypes from 'prop-types';
44
import { createMount, getClasses } from '@material-ui/core/test-utils';
5+
import { fireEvent, createClientRender } from 'test/utils/createClientRender';
56
import describeConformance from '../test-utils/describeConformance';
67
import consoleErrorMock from 'test/utils/consoleErrorMock';
78
import 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

Comments
 (0)