From 4b1722e95d2e2418b92492a22a74c8328ff7da91 Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Tue, 22 Nov 2016 13:42:45 +0800 Subject: [PATCH] fix: wrong select all checkbox displaying when pagination changes (#3904) --- components/table/SelectionCheckboxAll.tsx | 36 +++++++++++------- tests/table/Table.test.js | 45 ++++++++++++++++++++++- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/components/table/SelectionCheckboxAll.tsx b/components/table/SelectionCheckboxAll.tsx index ad7d78ae88..318f75812a 100644 --- a/components/table/SelectionCheckboxAll.tsx +++ b/components/table/SelectionCheckboxAll.tsx @@ -18,8 +18,8 @@ export default class SelectionCheckboxAll extends React.Component { - const checked = this.getCheckState(); - const indeterminate = this.getIndeterminateState(); - if (checked !== this.state.checked) { - this.setState({ checked }); - } - if (indeterminate !== this.state.indeterminate) { - this.setState({ indeterminate }); - } + this.setCheckState(this.props); }); } @@ -61,8 +58,19 @@ export default class SelectionCheckboxAll extends React.Component { expect(checkboxes[1].disabled).toBe(false); expect(checkboxes[2].disabled).toBe(true); }); + + it('works with pagination', () => { + const columns = [{ + title: 'Name', + dataIndex: 'name', + }]; + + const data = [{ + id: 0, + name: 'Jack', + }, { + id: 1, + name: 'Lucy', + }, { + id: 3, + name: 'Tom', + }, { + id: 4, + name: 'Jerry', + }]; + + const wrapper = mount( + + ); + + const checkboxAll = wrapper.find('SelectionCheckboxAll'); + const pagers = wrapper.find('Pager'); + + checkboxAll.find('input').simulate('change', { target: { checked: true } }); + expect(checkboxAll.node.state).toEqual({ checked: true, indeterminate: false }); + + pagers.at(1).simulate('click'); + expect(checkboxAll.node.state).toEqual({ checked: false, indeterminate: false }); + + pagers.at(0).simulate('click'); + expect(checkboxAll.node.state).toEqual({ checked: true, indeterminate: false }); + }); }); describe('JSX style API', () => {