Browse Source

increase Table test coverage

pull/19080/head
afc163 5 years ago
committed by 偏右
parent
commit
d41b5be377
  1. 8
      components/table/SelectionCheckboxAll.tsx
  2. 5
      components/table/Table.tsx
  3. 7
      components/table/__tests__/Table.filter.test.js
  4. 11
      components/table/__tests__/Table.pagination.test.js
  5. 9
      components/table/__tests__/Table.rowSelection.test.js
  6. 1
      components/table/__tests__/Table.test.js
  7. 2
      components/table/filterDropdown.tsx
  8. 2
      components/table/interface.tsx

8
components/table/SelectionCheckboxAll.tsx

@ -19,19 +19,15 @@ function checkSelection<T>({
getCheckboxPropsByItem: SelectionCheckboxAllProps<T>['getCheckboxPropsByItem'];
getRecordKey: SelectionCheckboxAllProps<T>['getRecordKey'];
data: T[];
type: string;
type: 'every' | 'some';
byDefaultChecked: boolean;
}) {
// type should be 'every' | 'some'
if (type === 'every' || type === 'some') {
return byDefaultChecked
? data[type]((item, i) => getCheckboxPropsByItem(item, i).defaultChecked)
: data[type](
(item, i) => store.getState().selectedRowKeys.indexOf(getRecordKey(item, i)) >= 0,
);
}
return false;
}
function getIndeterminateState<T>(props: SelectionCheckboxAllProps<T>) {
const { store, data } = props;
@ -122,12 +118,10 @@ class SelectionCheckboxAll<T> extends React.Component<
{
key: 'all',
text: props.locale.selectAll,
onSelect: () => {},
},
{
key: 'invert',
text: props.locale.selectInvert,
onSelect: () => {},
},
];
}

5
components/table/Table.tsx

@ -841,12 +841,7 @@ class Table<T> extends React.Component<TableProps<T>, TableState<T>> {
};
toggleSortOrder(column: ColumnProps<T>) {
if (!column.sorter) {
return;
}
const pagination = { ...this.state.pagination };
const sortDirections = column.sortDirections || (this.props.sortDirections as SortOrder[]);
const { sortOrder, sortColumn } = this.state;
// 只同时允许一列进行排序,否则会导致排序顺序的逻辑问题

7
components/table/__tests__/Table.filter.test.js

@ -351,6 +351,9 @@ describe('Table.filter', () => {
);
jest.useFakeTimers();
const dropdownWrapper = getDropdownWrapper(wrapper);
expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy', 'Tom', 'Jerry']);
// select
dropdownWrapper
.find('.ant-dropdown-menu-submenu-title')
.at(0)
@ -370,6 +373,10 @@ describe('Table.filter', () => {
dropdownWrapper.find('.confirm').simulate('click');
wrapper.update();
expect(renderedNames(wrapper)).toEqual(['Jack']);
dropdownWrapper
.find('MenuItem')
.last()
.simulate('click');
jest.useRealTimers();
});

11
components/table/__tests__/Table.pagination.test.js

@ -159,6 +159,17 @@ describe('Table.pagination', () => {
);
});
it('should not change page when pagination current is specified', () => {
const wrapper = mount(createTable({ pagination: { current: 2, pageSize: 1 } }));
expect(wrapper.find('.ant-pagination-item-2').hasClass('ant-pagination-item-active')).toBe(
true,
);
wrapper.find('.ant-pagination-item-3').simulate('click');
expect(wrapper.find('.ant-pagination-item-2').hasClass('ant-pagination-item-active')).toBe(
true,
);
});
it('specify the position of pagination', () => {
const wrapper = mount(createTable({ pagination: { position: 'top' } }));
expect(wrapper.find('.ant-spin-container').children()).toHaveLength(2);

9
components/table/__tests__/Table.rowSelection.test.js

@ -758,4 +758,13 @@ describe('Table.rowSelection', () => {
.simulate('click');
}).not.toThrow();
});
it('could hide all selections', () => {
const rowSelection = {
hideDefaultSelections: true,
selections: [],
};
const wrapper = mount(createTable({ rowSelection }));
expect(wrapper.find('Trigger')).toHaveLength(0);
});
});

1
components/table/__tests__/Table.test.js

@ -37,6 +37,7 @@ describe('Table', () => {
<Column title="Last Name" dataIndex="lastName" key="lastName" />
</ColumnGroup>
<Column title="Age" dataIndex="age" key="age" />
{'invalid child'}
</Table>,
);

2
components/table/filterDropdown.tsx

@ -22,7 +22,6 @@ function stopPropagation(e: React.SyntheticEvent<any>) {
class FilterMenu<T> extends React.Component<FilterMenuProps<T>, FilterMenuState<T>> {
static defaultProps = {
handleFilter() {},
column: {},
};
@ -147,6 +146,7 @@ class FilterMenu<T> extends React.Component<FilterMenuProps<T>, FilterMenuState<
const { keyPathOfSelectedItem } = this.state;
if (selectedKeys && selectedKeys.indexOf(info.key) >= 0) {
// deselect SubMenu child
console.log('delete keyPathOfSelectedItem[info.key]');
delete keyPathOfSelectedItem[info.key];
} else {
// select SubMenu child

2
components/table/interface.tsx

@ -237,7 +237,7 @@ type GetPopupContainer = (triggerNode?: HTMLElement) => HTMLElement;
export interface SelectionItem {
key: string;
text: React.ReactNode;
onSelect: SelectionItemSelectFn;
onSelect?: SelectionItemSelectFn;
}
export interface SelectionCheckboxAllProps<T> {

Loading…
Cancel
Save