Skip to content

Commit

Permalink
fix: The 'indentSize' in the Table component couldn't be zero value (a…
Browse files Browse the repository at this point in the history
…nt-design#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 <[email protected]>
  • Loading branch information
OmriGM and omri.g authored Jul 30, 2020
1 parent 36ec093 commit 8800b56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 55 deletions.
23 changes: 10 additions & 13 deletions components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,13 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
}

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,
});
}
};

Expand Down Expand Up @@ -409,7 +404,9 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
}

// 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(
Expand Down
60 changes: 18 additions & 42 deletions components/table/__tests__/Table.expand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ const data = [
describe('Table.expand', () => {
it('click to expand', () => {
const wrapper = mount(<Table columns={columns} dataSource={data} />);
wrapper
.find('.ant-table-row-expand-icon')
.last()
.simulate('click');
wrapper.find('.ant-table-row-expand-icon').last().simulate('click');
expect(wrapper.render()).toMatchSnapshot();
});

Expand All @@ -59,21 +56,15 @@ 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')
.first()
.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')
Expand All @@ -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(<Table indentSize={0} columns={columns} dataSource={data} />);
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(
Expand All @@ -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', () => {
Expand All @@ -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();
});
});
});

0 comments on commit 8800b56

Please sign in to comment.