2019-07-22 19:28:23 +08:00
|
|
|
/* eslint-disable react/no-multi-comp */
|
|
|
|
import React from 'react';
|
|
|
|
import Table from '..';
|
2022-06-22 14:57:09 +08:00
|
|
|
import { fireEvent, render } from '../../../tests/utils';
|
2019-07-22 19:28:23 +08:00
|
|
|
|
2019-09-28 15:22:27 +08:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
key: 'name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
},
|
|
|
|
];
|
2019-07-22 19:28:23 +08:00
|
|
|
|
2020-01-09 22:44:31 +08:00
|
|
|
const John = {
|
|
|
|
key: '1',
|
|
|
|
firstName: 'John',
|
|
|
|
lastName: 'Brown',
|
|
|
|
age: 32,
|
|
|
|
};
|
|
|
|
|
|
|
|
const Jim = {
|
|
|
|
key: '2',
|
|
|
|
firstName: 'Jim',
|
|
|
|
lastName: 'Green',
|
|
|
|
age: 42,
|
|
|
|
};
|
|
|
|
|
2019-09-28 15:22:27 +08:00
|
|
|
const data = [
|
|
|
|
{
|
2020-01-09 22:44:31 +08:00
|
|
|
...John,
|
2019-07-22 19:28:23 +08:00
|
|
|
|
2019-09-28 15:22:27 +08:00
|
|
|
children: [
|
|
|
|
{
|
2020-01-09 22:44:31 +08:00
|
|
|
...Jim,
|
2019-07-22 19:28:23 +08:00
|
|
|
},
|
2019-09-28 15:22:27 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2019-07-22 19:28:23 +08:00
|
|
|
|
2019-09-28 15:22:27 +08:00
|
|
|
describe('Table.expand', () => {
|
|
|
|
it('click to expand', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container, asFragment } = render(<Table columns={columns} dataSource={data} />);
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-table-row-expand-icon')!);
|
2022-06-07 10:14:32 +08:00
|
|
|
expect(asFragment().firstChild).toMatchSnapshot();
|
2019-07-22 19:28:23 +08:00
|
|
|
});
|
2019-09-28 15:22:27 +08:00
|
|
|
|
2020-01-09 22:44:31 +08:00
|
|
|
it('expandRowByClick should not block click icon', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container } = render(
|
2020-01-09 22:44:31 +08:00
|
|
|
<Table
|
|
|
|
columns={columns}
|
|
|
|
dataSource={[John, Jim]}
|
|
|
|
expandable={{
|
|
|
|
expandRowByClick: true,
|
|
|
|
expandedRowRender: () => '',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-table-row-expand-icon')!);
|
2022-06-07 10:14:32 +08:00
|
|
|
expect(container.querySelector('.ant-table-row-expand-icon-expanded')).toBeTruthy();
|
2020-01-09 22:44:31 +08:00
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-table-row-expand-icon')!);
|
2022-06-07 10:14:32 +08:00
|
|
|
expect(container.querySelector('.ant-table-row-expand-icon-collapsed')).toBeTruthy();
|
2020-01-09 22:44:31 +08:00
|
|
|
});
|
2020-02-01 22:50:58 +08:00
|
|
|
|
|
|
|
it('show expandIcon', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container } = render(
|
2020-02-01 22:50:58 +08:00
|
|
|
<Table
|
|
|
|
columns={[{ dataIndex: 'key' }]}
|
|
|
|
dataSource={[{ key: 233 }]}
|
|
|
|
expandable={{
|
|
|
|
expandIcon: () => <div className="expand-icon" />,
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
2022-06-07 10:14:32 +08:00
|
|
|
expect(container.querySelectorAll('.expand-icon')).toHaveLength(1);
|
2020-02-01 22:50:58 +08:00
|
|
|
});
|
2020-03-06 00:58:26 +08:00
|
|
|
|
2020-07-30 10:16:44 +08:00
|
|
|
it('row indent padding should be 0px when indentSize defined as 0', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container } = render(<Table indentSize={0} columns={columns} dataSource={data} />);
|
|
|
|
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-table-row-expand-icon')!);
|
|
|
|
expect(container.querySelector<HTMLElement>('.indent-level-1')?.style.paddingLeft).toEqual(
|
|
|
|
'0px',
|
|
|
|
);
|
2020-07-30 10:16:44 +08:00
|
|
|
});
|
2022-08-18 17:40:47 +08:00
|
|
|
|
2022-08-17 12:28:37 +08:00
|
|
|
it('has right aria-expanded state', () => {
|
|
|
|
const { container } = render(<Table columns={columns} dataSource={data} />);
|
|
|
|
expect(container.querySelector('[aria-expanded=false]')).toBeTruthy();
|
2022-09-05 19:41:32 +08:00
|
|
|
fireEvent.click(container.querySelector('.ant-table-row-expand-icon')!);
|
2022-08-17 12:28:37 +08:00
|
|
|
expect(container.querySelector('[aria-expanded=true]')).toBeTruthy();
|
|
|
|
});
|
2020-07-30 10:16:44 +08:00
|
|
|
|
2020-03-06 00:58:26 +08:00
|
|
|
describe('expandIconColumnIndex', () => {
|
|
|
|
it('basic', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container } = render(
|
2020-03-06 00:58:26 +08:00
|
|
|
<Table
|
|
|
|
columns={[{ dataIndex: 'key' }]}
|
|
|
|
dataSource={[{ key: 'bamboo' }]}
|
|
|
|
expandable={{
|
|
|
|
expandIconColumnIndex: 1,
|
|
|
|
expandedRowRender: () => '',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2022-12-15 20:45:58 +08:00
|
|
|
// header has td element (a11y): https://github.com/react-component/table/pull/859
|
2022-06-07 10:14:32 +08:00
|
|
|
const tdNodeList = container.querySelectorAll('td');
|
2022-12-15 20:45:58 +08:00
|
|
|
|
|
|
|
expect(tdNodeList[2].textContent).toEqual('bamboo');
|
|
|
|
expect(tdNodeList[3].querySelector('.ant-table-row-expand-icon')).toBeTruthy();
|
2020-03-06 00:58:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('work with selection', () => {
|
2022-06-07 10:14:32 +08:00
|
|
|
const { container } = render(
|
2020-03-06 00:58:26 +08:00
|
|
|
<Table
|
|
|
|
columns={[{ dataIndex: 'key' }]}
|
|
|
|
dataSource={[{ key: 'bamboo' }]}
|
|
|
|
expandable={{
|
|
|
|
expandIconColumnIndex: 2,
|
|
|
|
expandedRowRender: () => '',
|
|
|
|
}}
|
|
|
|
rowSelection={{}}
|
|
|
|
/>,
|
|
|
|
);
|
2022-06-07 10:14:32 +08:00
|
|
|
const tdNodeList = container.querySelectorAll('td');
|
2022-12-15 20:45:58 +08:00
|
|
|
expect(tdNodeList[2].querySelector('.ant-checkbox-input')).toBeTruthy();
|
|
|
|
expect(tdNodeList[3].textContent).toEqual('bamboo');
|
|
|
|
expect(tdNodeList[4].querySelector('.ant-table-row-expand-icon')).toBeTruthy();
|
2020-03-06 00:58:26 +08:00
|
|
|
});
|
|
|
|
});
|
2019-07-22 19:28:23 +08:00
|
|
|
});
|