-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathBaseTable.spec.tsx
171 lines (142 loc) · 4.73 KB
/
BaseTable.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React from 'react';
import renderer from 'react-test-renderer';
import BaseTable, { IBaseTableProps } from './BaseTable';
type TRenderer = () => null;
const RENDERER: TRenderer = () => null;
const columns = [
{
key: 'code',
title: 'code',
dataKey: 'code',
width: 50,
},
{
key: 'name',
title: 'name',
dataKey: 'name',
width: 50,
},
];
const data = [
{
id: '1',
code: '1',
name: '1',
},
{
id: '2',
code: '2',
name: '2',
},
];
type DefaultPropsKeys = keyof typeof BaseTable.defaultProps;
interface TableProps extends Partial<typeof BaseTable.defaultProps> {}
interface MinusDefaultKeys extends Partial<Omit<IBaseTableProps<any>, DefaultPropsKeys>> {}
const Table: React.FunctionComponent<TableProps & MinusDefaultKeys> = ({
width,
height,
...restProps
}) => <BaseTable width={width} height={height} {...restProps} />;
Table.defaultProps = {
width: 100,
height: 100,
data,
columns,
};
describe('Table', () => {
test('renders correctly', () => {
const tree = renderer.create(<Table />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive className', () => {
const tree = renderer.create(<Table className='custom-class' />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive style', () => {
const tree = renderer.create(<Table style={{ color: 'red' }} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive children', () => {
const tree = renderer
.create(
<Table>
<BaseTable.Column key='code' dataKey='code' width={30} />
<BaseTable.Column key='name' dataKey='name' width={30} />
</Table>,
)
.toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive empty data', () => {
const tree = renderer.create(<Table data={[]} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can specific a different rowKey', () => {
const tree = renderer.create(<Table rowKey='code' />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive width', () => {
const tree = renderer.create(<Table width={100} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive height', () => {
const tree = renderer.create(<Table height={100} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive rowHeight', () => {
const tree = renderer.create(<Table rowHeight={30} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive headerHeight', () => {
const tree = renderer.create(<Table headerHeight={30} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can be set to fixed', () => {
const tree = renderer.create(<Table fixed />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can be set to disabled', () => {
const tree = renderer.create(<Table disabled />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can hide the header', () => {
const tree = renderer.create(<Table headerHeight={0} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can freeze rows', () => {
const tree = renderer.create(<Table frozenData={data} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive an emptyRenderer callback', () => {
const tree = renderer.create(<Table emptyRenderer={RENDERER} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive an headerRenderer callback', () => {
const tree = renderer.create(<Table headerRenderer={RENDERER} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive an rowRenderer callback', () => {
const tree = renderer.create(<Table rowRenderer={RENDERER} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive headerClassName', () => {
const tree = renderer.create(<Table headerClassName='custom-class' />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive rowClassName', () => {
const tree = renderer.create(<Table rowClassName='custom-class' />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive expandColumnKey', () => {
const tree = renderer.create(<Table expandColumnKey='code' />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive defaultExpandedRowKeys', () => {
const tree = renderer.create(<Table expandColumnKey='code' defaultExpandedRowKeys={['1']} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('table can receive expandedRowKeys', () => {
const tree = renderer.create(<Table expandColumnKey='code' expandedRowKeys={['1']} />).toJSON();
expect(tree).toMatchSnapshot();
});
});