From 6cf978a85d623eb516f28bc86d42c5ed5509b0be Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Thu, 27 Feb 2020 02:52:24 +0200 Subject: [PATCH 1/7] added statement if count negative --- packages/material-ui/src/TablePagination/TablePagination.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/material-ui/src/TablePagination/TablePagination.js b/packages/material-ui/src/TablePagination/TablePagination.js index 62ce0ed1264adc..5f75bc45979db7 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.js +++ b/packages/material-ui/src/TablePagination/TablePagination.js @@ -246,6 +246,11 @@ TablePagination.propTypes = { */ page: chainPropTypes(PropTypes.number.isRequired, props => { const { count, page, rowsPerPage } = props; + + if (count === -1) { + return null; + } + const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1); if (page < 0 || page > newLastPage) { return new Error( From 06e5501c4c4ec6110fcfa94bf11ea47c96221f1b Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Thu, 27 Feb 2020 21:48:05 +0200 Subject: [PATCH 2/7] added test TablaPagination when count is out of range --- .../TablePagination/TablePagination.test.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js index b82fb648cf4f20..ffa39bb7f79759 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.test.js +++ b/packages/material-ui/src/TablePagination/TablePagination.test.js @@ -10,6 +10,7 @@ import TableFooter from '../TableFooter'; import TableCell from '../TableCell'; import Typography from '../Typography'; import TableRow from '../TableRow'; +import TableBody from '../TableBody'; import TablePagination from './TablePagination'; describe('', () => { @@ -200,29 +201,28 @@ describe('', () => { assert.strictEqual(page, 0); }); - it('should display 0 as start number if the table is empty ', () => { + it('should hide console warning when count is out of range', () => { + let page = 0; const wrapper = mount( - + { + page = nextPage; + }} rowsPerPage={10} - onChangePage={noop} - onChangeRowsPerPage={noop} /> - +
, ); - assert.strictEqual( - wrapper - .find(Typography) - .at(1) - .text(), - '0-0 of 0', - ); + + const nextButton = wrapper.find(IconButton).at(1); + nextButton.simulate('click'); + assert.strictEqual(page, 2); }); it('should hide the rows per page selector if there are less than two options', () => { From 01184a5e9428f308a641d671aa33461911098901 Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Thu, 27 Feb 2020 21:48:27 +0200 Subject: [PATCH 3/7] added test TablaPagination when count is out of range --- .../material-ui/src/TablePagination/TablePagination.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js index ffa39bb7f79759..7357d9b8f031cc 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.test.js +++ b/packages/material-ui/src/TablePagination/TablePagination.test.js @@ -201,7 +201,7 @@ describe('', () => { assert.strictEqual(page, 0); }); - it('should hide console warning when count is out of range', () => { + it('should handle when count is out of range', () => { let page = 0; const wrapper = mount( From fbd8ed3d9086035ccf3e1674559a6b384f033c23 Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Thu, 27 Feb 2020 22:06:51 +0200 Subject: [PATCH 4/7] changes for let page value --- .../material-ui/src/TablePagination/TablePagination.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js index 7357d9b8f031cc..f91af032c06bcb 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.test.js +++ b/packages/material-ui/src/TablePagination/TablePagination.test.js @@ -202,7 +202,7 @@ describe('', () => { }); it('should handle when count is out of range', () => { - let page = 0; + let page = 1; const wrapper = mount(
From 59eca5d86f789ebeb40551531c0b9c78115c2d27 Mon Sep 17 00:00:00 2001 From: dbarabashdev Date: Sun, 1 Mar 2020 16:02:20 +0200 Subject: [PATCH 5/7] 'display 0 as ztart number if the table is empty' revert test case --- .../TablePagination/TablePagination.test.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js index f91af032c06bcb..b3ce13df9e5053 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.test.js +++ b/packages/material-ui/src/TablePagination/TablePagination.test.js @@ -201,6 +201,31 @@ describe('', () => { assert.strictEqual(page, 0); }); + it('should display 0 as start number if the table is empty ', () => { + const wrapper = mount( +
+ + + + + +
, + ); + assert.strictEqual( + wrapper + .find(Typography) + .at(1) + .text(), + '0-0 of 0', + ); + }); + it('should handle when count is out of range', () => { let page = 1; const wrapper = mount( From e20cf0d230b27b7b98fd8ace2ebee62255445ec7 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 1 Mar 2020 20:24:40 +0100 Subject: [PATCH 6/7] use testing-library --- .../TablePagination/TablePagination.test.js | 87 +++++++------------ 1 file changed, 33 insertions(+), 54 deletions(-) diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js index b3ce13df9e5053..e3b4660e447a05 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.test.js +++ b/packages/material-ui/src/TablePagination/TablePagination.test.js @@ -1,7 +1,8 @@ import * as React from 'react'; -import { assert } from 'chai'; +import { expect, assert } from 'chai'; import PropTypes from 'prop-types'; import { createMount, getClasses } from '@material-ui/core/test-utils'; +import { fireEvent, createClientRender } from 'test/utils/createClientRender'; import describeConformance from '../test-utils/describeConformance'; import consoleErrorMock from 'test/utils/consoleErrorMock'; import Select from '../Select'; @@ -17,6 +18,7 @@ describe('', () => { const noop = () => {}; let classes; let mount; + const render = createClientRender(); function mountInTable(node) { const wrapper = mount( @@ -226,30 +228,6 @@ describe('', () => { ); }); - it('should handle when count is out of range', () => { - let page = 1; - const wrapper = mount( - - - - { - page = nextPage; - }} - rowsPerPage={10} - /> - - -
, - ); - - const nextButton = wrapper.find(IconButton).at(1); - nextButton.simulate('click'); - assert.strictEqual(page, 2); - }); - it('should hide the rows per page selector if there are less than two options', () => { const wrapper = mount( @@ -273,6 +251,36 @@ describe('', () => { }); }); + describe('prop: count=-1', () => { + it('should display the "of more than" text and keep the nextButton enabled', () => { + const Test = () => { + const [page, setPage] = React.useState(0); + return ( +
+ + + { + setPage(newPage); + }} + /> + + +
+ ); + }; + + const { container, getByLabelText } = render(); + + expect(container).to.have.text('Rows per page:101-10 of more than 10'); + fireEvent.click(getByLabelText('Next page')); + expect(container).to.have.text('Rows per page:1011-20 of more than 20'); + }); + }); + describe('warnings', () => { before(() => { consoleErrorMock.spy(); @@ -307,33 +315,4 @@ describe('', () => { ); }); }); - - it('should display the "of more than" text and keep the nextButton enabled, if count is -1 ', () => { - const wrapper = mount( - - - - - - -
, - ); - - assert.strictEqual( - wrapper - .find(Typography) - .at(0) - .text(), - '1-5 of more than 5', - ); - const nextButton = wrapper.find(IconButton).at(1); - assert.strictEqual(nextButton.props().disabled, false); - }); }); From 76d5dbf6b28c6fd4682784837d5c5e2ebbbc35a0 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 1 Mar 2020 20:45:19 +0100 Subject: [PATCH 7/7] fix CI --- .../src/TablePagination/TablePagination.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js index e3b4660e447a05..c59e1ea5571bcd 100644 --- a/packages/material-ui/src/TablePagination/TablePagination.test.js +++ b/packages/material-ui/src/TablePagination/TablePagination.test.js @@ -11,7 +11,6 @@ import TableFooter from '../TableFooter'; import TableCell from '../TableCell'; import Typography from '../Typography'; import TableRow from '../TableRow'; -import TableBody from '../TableBody'; import TablePagination from './TablePagination'; describe('', () => { @@ -35,11 +34,14 @@ describe('', () => { classes = getClasses( {}} page={0} rowsPerPage={10} />, ); - // StrictModeViolation: test uses #html() + }); + + beforeEach(() => { + // StrictModeViolation: test uses #html()() mount = createMount({ strict: false }); }); - after(() => { + afterEach(() => { mount.cleanUp(); });