2019-07-22 19:28:23 +08:00
|
|
|
/* eslint-disable react/no-multi-comp */
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Table from '..';
|
|
|
|
|
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', () => {
|
2019-07-22 19:28:23 +08:00
|
|
|
const wrapper = mount(<Table columns={columns} dataSource={data} />);
|
2020-07-30 10:16:44 +08:00
|
|
|
wrapper.find('.ant-table-row-expand-icon').last().simulate('click');
|
2019-07-22 19:28:23 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-09-28 15:22:27 +08:00
|
|
|
|
2020-01-09 22:44:31 +08:00
|
|
|
it('expandRowByClick should not block click icon', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Table
|
|
|
|
columns={columns}
|
|
|
|
dataSource={[John, Jim]}
|
|
|
|
expandable={{
|
|
|
|
expandRowByClick: true,
|
|
|
|
expandedRowRender: () => '',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2020-07-30 10:16:44 +08:00
|
|
|
wrapper.find('.ant-table-row-expand-icon').first().simulate('click');
|
2020-01-09 22:44:31 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-table-row-expand-icon')
|
|
|
|
.first()
|
|
|
|
.hasClass('ant-table-row-expand-icon-expanded'),
|
|
|
|
).toBeTruthy();
|
|
|
|
|
2020-07-30 10:16:44 +08:00
|
|
|
wrapper.find('.ant-table-row-expand-icon').first().simulate('click');
|
2020-01-09 22:44:31 +08:00
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.ant-table-row-expand-icon')
|
|
|
|
.first()
|
|
|
|
.hasClass('ant-table-row-expand-icon-collapsed'),
|
|
|
|
).toBeTruthy();
|
|
|
|
});
|
2020-02-01 22:50:58 +08:00
|
|
|
|
|
|
|
it('show expandIcon', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Table
|
|
|
|
columns={[{ dataIndex: 'key' }]}
|
|
|
|
dataSource={[{ key: 233 }]}
|
|
|
|
expandable={{
|
|
|
|
expandIcon: () => <div className="expand-icon" />,
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('.expand-icon')).toHaveLength(1);
|
|
|
|
});
|
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', () => {
|
|
|
|
const wrapper = mount(<Table indentSize={0} columns={columns} dataSource={data} />);
|
|
|
|
const button = wrapper.find('.ant-table-row-expand-icon').at(0);
|
|
|
|
button.simulate('click');
|
|
|
|
expect(wrapper.find('.indent-level-1').at(0).prop('style')).toHaveProperty(
|
|
|
|
'paddingLeft',
|
|
|
|
'0px',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-03-06 00:58:26 +08:00
|
|
|
describe('expandIconColumnIndex', () => {
|
|
|
|
it('basic', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Table
|
|
|
|
columns={[{ dataIndex: 'key' }]}
|
|
|
|
dataSource={[{ key: 'bamboo' }]}
|
|
|
|
expandable={{
|
|
|
|
expandIconColumnIndex: 1,
|
|
|
|
expandedRowRender: () => '',
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2020-07-30 10:16:44 +08:00
|
|
|
expect(wrapper.find('td').at(0).text()).toEqual('bamboo');
|
|
|
|
expect(wrapper.find('td').at(1).find('.ant-table-row-expand-icon').length).toBeTruthy();
|
2020-03-06 00:58:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('work with selection', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Table
|
|
|
|
columns={[{ dataIndex: 'key' }]}
|
|
|
|
dataSource={[{ key: 'bamboo' }]}
|
|
|
|
expandable={{
|
|
|
|
expandIconColumnIndex: 2,
|
|
|
|
expandedRowRender: () => '',
|
|
|
|
}}
|
|
|
|
rowSelection={{}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2020-07-30 10:16:44 +08:00
|
|
|
expect(wrapper.find('td').at(0).find('.ant-checkbox-input').length).toBeTruthy();
|
|
|
|
expect(wrapper.find('td').at(1).text()).toEqual('bamboo');
|
|
|
|
expect(wrapper.find('td').at(2).find('.ant-table-row-expand-icon').length).toBeTruthy();
|
2020-03-06 00:58:26 +08:00
|
|
|
});
|
|
|
|
});
|
2019-07-22 19:28:23 +08:00
|
|
|
});
|