2021-11-26 17:50:41 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Table from '..';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
2022-05-10 15:43:29 +08:00
|
|
|
import { resetWarned } from '../../_util/warning';
|
2021-11-26 17:50:41 +08:00
|
|
|
|
|
|
|
describe('Table.order', () => {
|
|
|
|
window.requestAnimationFrame = callback => window.setTimeout(callback, 16);
|
|
|
|
window.cancelAnimationFrame = window.clearTimeout;
|
|
|
|
|
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
errorSpy.mockReset();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
errorSpy.mockRestore();
|
|
|
|
});
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const data = [
|
|
|
|
{ key: 0, name: 'Jack' },
|
|
|
|
{ key: 1, name: 'Lucy' },
|
|
|
|
{ key: 2, name: 'Tom' },
|
|
|
|
{ key: 3, name: 'Jerry' },
|
|
|
|
];
|
|
|
|
|
|
|
|
function createTable(props = {}) {
|
|
|
|
return <Table columns={columns} dataSource={data} {...props} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('warning if duplicated SELECTION_COLUMN', () => {
|
|
|
|
resetWarned();
|
2022-06-07 10:14:32 +08:00
|
|
|
render(
|
2021-11-26 17:50:41 +08:00
|
|
|
createTable({
|
|
|
|
columns: [Table.SELECTION_COLUMN, Table.SELECTION_COLUMN],
|
|
|
|
rowSelection: {},
|
|
|
|
expandable: {
|
|
|
|
expandedRowRender: () => null,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(errorSpy).toHaveBeenCalledWith(
|
|
|
|
'Warning: [antd: Table] Multiple `SELECTION_COLUMN` exist in `columns`.',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('auto fixed', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container } = render(
|
2021-11-26 17:50:41 +08:00
|
|
|
createTable({
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
dataIndex: 'name',
|
|
|
|
fixed: true,
|
|
|
|
},
|
|
|
|
Table.SELECTION_COLUMN,
|
|
|
|
{
|
|
|
|
dataIndex: 'key',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
rowSelection: {},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2022-06-07 10:14:32 +08:00
|
|
|
expect(container.querySelectorAll('tr')[1].querySelectorAll('td')).toHaveLength(3);
|
|
|
|
expect(
|
|
|
|
container.querySelectorAll('tr')[1].querySelectorAll('td.ant-table-cell-fix-left'),
|
|
|
|
).toHaveLength(2);
|
2021-11-26 17:50:41 +08:00
|
|
|
});
|
|
|
|
});
|