2019-01-12 11:33:27 +08:00
|
|
|
import { shallowMount as shallow, mount } from '@vue/test-utils';
|
|
|
|
import Table from '..';
|
|
|
|
import Vue from 'vue';
|
2020-03-07 19:45:13 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2018-05-26 22:48:16 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const { Column, ColumnGroup } = Table;
|
2018-05-26 22:48:16 +08:00
|
|
|
|
|
|
|
describe('Table', () => {
|
2020-03-07 19:45:13 +08:00
|
|
|
mountTest(Table);
|
2019-07-22 11:11:20 +08:00
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
key: '1',
|
|
|
|
firstName: 'John',
|
|
|
|
lastName: 'Brown',
|
|
|
|
age: 32,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '2',
|
|
|
|
firstName: 'Jim',
|
|
|
|
lastName: 'Green',
|
|
|
|
age: 42,
|
|
|
|
},
|
|
|
|
];
|
2018-05-26 22:48:16 +08:00
|
|
|
|
2019-07-22 11:11:20 +08:00
|
|
|
it('renders JSX correctly', done => {
|
2019-01-12 11:33:27 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Table dataSource={data} pagination={false}>
|
|
|
|
<ColumnGroup title="Name">
|
|
|
|
<Column title="First Name" dataIndex="firstName" key="firstName" />
|
|
|
|
<Column title="Last Name" dataIndex="lastName" key="lastName" />
|
|
|
|
</ColumnGroup>
|
|
|
|
<Column title="Age" dataIndex="age" key="age" />
|
|
|
|
</Table>
|
|
|
|
);
|
|
|
|
},
|
2018-05-26 22:48:16 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
{ sync: false },
|
|
|
|
);
|
2018-05-26 22:48:16 +08:00
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-26 22:48:16 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
it('updates columns when receiving props', done => {
|
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
key: 'name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
},
|
|
|
|
];
|
2018-05-26 22:48:16 +08:00
|
|
|
const wrapper = shallow(Table, {
|
|
|
|
propsData: {
|
|
|
|
columns,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
const newColumns = [
|
|
|
|
{
|
|
|
|
title: 'Title',
|
|
|
|
key: 'title',
|
|
|
|
dataIndex: 'title',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
wrapper.setProps({ columns: newColumns });
|
2018-05-26 22:48:16 +08:00
|
|
|
Vue.nextTick(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(wrapper.vm.columns).toBe(newColumns);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-26 22:48:16 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
it('loading with Spin', done => {
|
2018-05-26 22:48:16 +08:00
|
|
|
const loading = {
|
|
|
|
spinning: false,
|
|
|
|
delay: 500,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-05-26 22:48:16 +08:00
|
|
|
const wrapper = mount(Table, {
|
|
|
|
propsData: {
|
|
|
|
loading,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-05-26 22:48:16 +08:00
|
|
|
Vue.nextTick(async () => {
|
2019-01-12 11:33:27 +08:00
|
|
|
expect(wrapper.findAll('.ant-spin')).toHaveLength(0);
|
|
|
|
expect(wrapper.find('.ant-table-placeholder').text()).not.toEqual('');
|
2018-05-26 22:48:16 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
loading.spinning = true;
|
|
|
|
wrapper.setProps({ loading });
|
|
|
|
expect(wrapper.findAll('.ant-spin')).toHaveLength(0);
|
2018-05-26 22:48:16 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
expect(wrapper.findAll('.ant-spin')).toHaveLength(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-07-22 11:11:20 +08:00
|
|
|
|
2019-10-17 19:27:21 +08:00
|
|
|
it('align column should not override cell style', done => {
|
2019-07-22 11:11:20 +08:00
|
|
|
const columns = [
|
|
|
|
{ title: 'Name', dataIndex: 'name', key: 'name' },
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
key: 'age',
|
|
|
|
align: 'center',
|
2020-03-18 14:52:02 +08:00
|
|
|
customCell: () => {
|
2019-07-22 11:11:20 +08:00
|
|
|
return {
|
|
|
|
style: {
|
|
|
|
color: 'red',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const wrapper = mount(Table, {
|
|
|
|
propsData: {
|
|
|
|
columns,
|
|
|
|
dataSource: data,
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
});
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|