Browse Source

fix test case

pull/12271/merge
afc163 6 years ago
committed by 偏右
parent
commit
8feb15ea72
  1. 21
      components/table/Table.tsx
  2. 6
      components/table/__tests__/Table.rowSelection.test.js
  3. 38
      components/table/__tests__/Table.sorter.test.js

21
components/table/Table.tsx

@ -810,26 +810,17 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
[`${prefixCls}-column-sort`]: isSortColumn && sortOrder, [`${prefixCls}-column-sort`]: isSortColumn && sortOrder,
}), }),
title: [ title: [
<div key="title" className={sortButton ? `${prefixCls}-column-sorters` : ''}> <div
key="title"
title={locale.sortTitle}
className={sortButton ? `${prefixCls}-column-sorters` : undefined}
onClick={() => this.toggleSortOrder(column)}
>
{column.title} {column.title}
{sortButton} {sortButton}
</div>, </div>,
filterDropdown, filterDropdown,
], ],
onHeaderCell: sortButton ? (columnProps: ColumnProps<T>) => {
// for onHeaderCell compatibility
const headerCellProps = column.onHeaderCell ? column.onHeaderCell(columnProps) : {};
return {
onClick: (e: MouseEvent) => {
this.toggleSortOrder(column);
if (headerCellProps && headerCellProps.onClick) {
headerCellProps.onClick(e);
}
},
title: locale.sortTitle,
...headerCellProps,
};
} : column.onHeaderCell,
}; };
}); });
} }

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

@ -423,7 +423,7 @@ describe('Table.rowSelection', () => {
}); });
// https://github.com/ant-design/ant-design/issues/11042 // https://github.com/ant-design/ant-design/issues/11042
it('add columnTitle for rowSelection', () => { it.only('add columnTitle for rowSelection', () => {
const wrapper = mount( const wrapper = mount(
<Table <Table
columns={columns} columns={columns}
@ -433,13 +433,13 @@ describe('Table.rowSelection', () => {
}} }}
/> />
); );
expect(wrapper.find('thead tr span').at(0).text()).toBe('多选'); expect(wrapper.find('thead tr div').at(0).text()).toBe('多选');
wrapper.setProps({ wrapper.setProps({
rowSelection: { rowSelection: {
type: 'radio', type: 'radio',
columnTitle: '单选', columnTitle: '单选',
}, },
}); });
expect(wrapper.find('thead tr span').at(0).text()).toBe('单选'); expect(wrapper.find('thead tr div').at(0).text()).toBe('单选');
}); });
}); });

38
components/table/__tests__/Table.sorter.test.js

@ -60,11 +60,13 @@ describe('Table.sorter', () => {
it('sort records', () => { it('sort records', () => {
const wrapper = mount(createTable()); const wrapper = mount(createTable());
wrapper.find('.ant-table-column-sorter-up').simulate('click'); // descent
expect(renderedNames(wrapper)).toEqual(['Jack', 'Jerry', 'Lucy', 'Tom']); wrapper.find('.ant-table-column-sorters').simulate('click');
wrapper.find('.ant-table-column-sorter-down').simulate('click');
expect(renderedNames(wrapper)).toEqual(['Tom', 'Lucy', 'Jack', 'Jerry']); expect(renderedNames(wrapper)).toEqual(['Tom', 'Lucy', 'Jack', 'Jerry']);
// ascent
wrapper.find('.ant-table-column-sorters').simulate('click');
expect(renderedNames(wrapper)).toEqual(['Jack', 'Jerry', 'Lucy', 'Tom']);
}); });
it('can be controlled by sortOrder', () => { it('can be controlled by sortOrder', () => {
@ -92,13 +94,27 @@ describe('Table.sorter', () => {
const handleChange = jest.fn(); const handleChange = jest.fn();
const wrapper = mount(createTable({ onChange: handleChange })); const wrapper = mount(createTable({ onChange: handleChange }));
wrapper.find('.ant-table-column-sorter-up').simulate('click'); // ascent
wrapper.find('.ant-table-column-sorters').simulate('click');
const sorter = handleChange.mock.calls[0][2]; const sorter1 = handleChange.mock.calls[0][2];
expect(sorter.column.dataIndex).toBe('name'); expect(sorter1.column.dataIndex).toBe('name');
expect(sorter.order).toBe('ascend'); expect(sorter1.order).toBe('descend');
expect(sorter.field).toBe('name'); expect(sorter1.field).toBe('name');
expect(sorter.columnKey).toBe('name'); expect(sorter1.columnKey).toBe('name');
wrapper.find('.ant-table-column-sorters').simulate('click');
const sorter2 = handleChange.mock.calls[1][2];
expect(sorter2.column.dataIndex).toBe('name');
expect(sorter2.order).toBe('ascend');
expect(sorter2.field).toBe('name');
expect(sorter2.columnKey).toBe('name');
wrapper.find('.ant-table-column-sorters').simulate('click');
const sorter3 = handleChange.mock.calls[2][2];
expect(sorter3.column).toBe(undefined);
expect(sorter3.order).toBe(undefined);
expect(sorter3.field).toBe(undefined);
expect(sorter3.columnKey).toBe(undefined);
}); });
it('works with grouping columns in controlled mode', () => { it('works with grouping columns in controlled mode', () => {

Loading…
Cancel
Save