mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-05 23:46:28 +08:00
test: add table multi-sort case (#37109)
* test: add table multi-sort case * chore: code clean
This commit is contained in:
parent
ade858c16a
commit
ab4d656b7b
@ -992,4 +992,104 @@ describe('Table.sorter', () => {
|
||||
clickToMatchExpect(1, { field: 'english', order: 'descend' });
|
||||
clickToMatchExpect(1, { field: 'english', order: undefined });
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/37024
|
||||
it('multiple sort should pass array sorter as onChange param', () => {
|
||||
const columns = [
|
||||
{
|
||||
title: 'Name',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: 'Chinese Score',
|
||||
dataIndex: 'chinese',
|
||||
sorter: {
|
||||
compare: (a, b) => a.chinese - b.chinese,
|
||||
multiple: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Math Score',
|
||||
dataIndex: 'math',
|
||||
sorter: {
|
||||
compare: (a, b) => a.math - b.math,
|
||||
multiple: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'English Score',
|
||||
dataIndex: 'english',
|
||||
sorter: {
|
||||
compare: (a, b) => a.english - b.english,
|
||||
multiple: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
const tableData = [
|
||||
{
|
||||
key: '1',
|
||||
name: 'John Brown',
|
||||
chinese: 98,
|
||||
math: 60,
|
||||
english: 70,
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
name: 'Jim Green',
|
||||
chinese: 98,
|
||||
math: 66,
|
||||
english: 89,
|
||||
},
|
||||
{
|
||||
key: '3',
|
||||
name: 'Joe Black',
|
||||
chinese: 98,
|
||||
math: 90,
|
||||
english: 70,
|
||||
},
|
||||
{
|
||||
key: '4',
|
||||
name: 'Jim Red',
|
||||
chinese: 88,
|
||||
math: 99,
|
||||
english: 89,
|
||||
},
|
||||
];
|
||||
|
||||
const onChange = jest.fn();
|
||||
|
||||
const { container } = render(
|
||||
<Table columns={columns} dataSource={tableData} onChange={onChange} />,
|
||||
);
|
||||
const sorterColumns = Array.from(container.querySelectorAll('.ant-table-column-has-sorters'));
|
||||
expect(sorterColumns.length).toBe(3);
|
||||
fireEvent.click(sorterColumns[0]);
|
||||
expect(onChange).toHaveBeenLastCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ field: 'chinese' }),
|
||||
expect.anything(),
|
||||
);
|
||||
fireEvent.click(sorterColumns[1]);
|
||||
expect(onChange).toHaveBeenLastCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ field: 'chinese' }),
|
||||
expect.objectContaining({ field: 'math' }),
|
||||
]),
|
||||
expect.anything(),
|
||||
);
|
||||
fireEvent.click(sorterColumns[2]);
|
||||
expect(onChange).toHaveBeenLastCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ field: 'chinese' }),
|
||||
expect.objectContaining({ field: 'math' }),
|
||||
expect.objectContaining({ field: 'english' }),
|
||||
]),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user