From 8800b56e47705ecced11dc97cc6f944ad0627d00 Mon Sep 17 00:00:00 2001 From: Omri Grossman Date: Thu, 30 Jul 2020 05:16:44 +0300 Subject: [PATCH] fix: The 'indentSize' in the Table component couldn't be zero value (#25890) * - Fixed the indentSize prop of Table.tsx to also accept 0 values * - Undo Cascader component test snapshots * - Added test case - Used check with typeof === number instead of `undefined` and `null` Co-authored-by: omri.g --- components/table/Table.tsx | 23 ++++--- .../table/__tests__/Table.expand.test.js | 60 ++++++------------- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index cc9f57675a..be99cdb5ee 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -222,18 +222,13 @@ function Table(props: TableProps) { } if (onChange) { - onChange( - changeInfo.pagination!, - changeInfo.filters!, - changeInfo.sorter!, - { - currentDataSource: getFilterData( - getSortData(rawData, changeInfo.sorterStates!, childrenColumnName), - changeInfo.filterStates!, - ), - action, - }, - ); + onChange(changeInfo.pagination!, changeInfo.filters!, changeInfo.sorter!, { + currentDataSource: getFilterData( + getSortData(rawData, changeInfo.sorterStates!, childrenColumnName), + changeInfo.filterStates!, + ), + action, + }); } }; @@ -409,7 +404,9 @@ function Table(props: TableProps) { } // Indent size - mergedExpandable.indentSize = mergedExpandable.indentSize || indentSize || 15; + if (typeof mergedExpandable.indentSize !== 'number') { + mergedExpandable.indentSize = typeof indentSize === 'number' ? indentSize : 15; + } // ============================ Render ============================ const transformColumns = React.useCallback( diff --git a/components/table/__tests__/Table.expand.test.js b/components/table/__tests__/Table.expand.test.js index 37444f1b7c..858a834ec0 100644 --- a/components/table/__tests__/Table.expand.test.js +++ b/components/table/__tests__/Table.expand.test.js @@ -40,10 +40,7 @@ const data = [ describe('Table.expand', () => { it('click to expand', () => { const wrapper = mount(); - wrapper - .find('.ant-table-row-expand-icon') - .last() - .simulate('click'); + wrapper.find('.ant-table-row-expand-icon').last().simulate('click'); expect(wrapper.render()).toMatchSnapshot(); }); @@ -59,10 +56,7 @@ describe('Table.expand', () => { />, ); - wrapper - .find('.ant-table-row-expand-icon') - .first() - .simulate('click'); + wrapper.find('.ant-table-row-expand-icon').first().simulate('click'); expect( wrapper .find('.ant-table-row-expand-icon') @@ -70,10 +64,7 @@ describe('Table.expand', () => { .hasClass('ant-table-row-expand-icon-expanded'), ).toBeTruthy(); - wrapper - .find('.ant-table-row-expand-icon') - .first() - .simulate('click'); + wrapper.find('.ant-table-row-expand-icon').first().simulate('click'); expect( wrapper .find('.ant-table-row-expand-icon') @@ -96,6 +87,16 @@ describe('Table.expand', () => { expect(wrapper.find('.expand-icon')).toHaveLength(1); }); + it('row indent padding should be 0px when indentSize defined as 0', () => { + const wrapper = mount(
); + const button = wrapper.find('.ant-table-row-expand-icon').at(0); + button.simulate('click'); + expect(wrapper.find('.indent-level-1').at(0).prop('style')).toHaveProperty( + 'paddingLeft', + '0px', + ); + }); + describe('expandIconColumnIndex', () => { it('basic', () => { const wrapper = mount( @@ -109,18 +110,8 @@ describe('Table.expand', () => { />, ); - expect( - wrapper - .find('td') - .at(0) - .text(), - ).toEqual('bamboo'); - expect( - wrapper - .find('td') - .at(1) - .find('.ant-table-row-expand-icon').length, - ).toBeTruthy(); + expect(wrapper.find('td').at(0).text()).toEqual('bamboo'); + expect(wrapper.find('td').at(1).find('.ant-table-row-expand-icon').length).toBeTruthy(); }); it('work with selection', () => { @@ -136,24 +127,9 @@ describe('Table.expand', () => { />, ); - expect( - wrapper - .find('td') - .at(0) - .find('.ant-checkbox-input').length, - ).toBeTruthy(); - expect( - wrapper - .find('td') - .at(1) - .text(), - ).toEqual('bamboo'); - expect( - wrapper - .find('td') - .at(2) - .find('.ant-table-row-expand-icon').length, - ).toBeTruthy(); + expect(wrapper.find('td').at(0).find('.ant-checkbox-input').length).toBeTruthy(); + expect(wrapper.find('td').at(1).text()).toEqual('bamboo'); + expect(wrapper.find('td').at(2).find('.ant-table-row-expand-icon').length).toBeTruthy(); }); }); });