-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathTableHeightSpec.tsx
109 lines (94 loc) · 2.78 KB
/
TableHeightSpec.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
import React from 'react';
import { render, screen } from '@testing-library/react';
import Table from '../src/Table';
import Column from '../src/Column';
import Cell from '../src/Cell';
import HeaderCell from '../src/HeaderCell';
import '../src/less/index.less';
const columns = (
<>
<Column>
<HeaderCell>id</HeaderCell>
<Cell dataKey="id" />
</Column>
<Column>
<HeaderCell>name</HeaderCell>
<Cell dataKey="name" />
</Column>
</>
);
const mockData = (size = 10) => {
return Array.from({ length: size }, (_, i) => ({ id: i, name: `name${i}` }));
};
describe('Table - Height ', () => {
it('Should be automatic height', () => {
render(
<Table autoHeight data={mockData(2)}>
{columns}
</Table>
);
// 2 rows + header row
const height = 46 * 2 + 40;
expect(screen.getByRole('grid')).to.have.style('height', `${height}px`);
});
it('Should fill the height of the container', () => {
render(
<div style={{ height: 300 }}>
<Table fillHeight height={200} data={[]}>
{columns}
</Table>
</div>
);
expect(screen.getByRole('grid')).to.have.style('height', '300px');
});
it('Should be automatic height when there is a horizontal scroll bar', () => {
render(
<Table autoHeight width={100} data={mockData(2)}>
{columns}
</Table>
);
// 2 rows + header row + scrollbar
const height = 46 * 2 + 40 + 10;
expect(screen.getByRole('grid')).to.have.style('height', `${height}px`);
});
it('Should have a maximum height', () => {
render(
<Table minHeight={200} height={100} data={mockData(2)}>
{columns}
</Table>
);
expect(screen.getByRole('grid')).to.have.style('height', '200px');
});
it('Should have a minimum height, when the number of data rows is less than the minimum height', () => {
render(
<Table autoHeight minHeight={500} data={mockData(2)}>
{columns}
</Table>
);
expect(screen.getByRole('grid')).to.have.style('height', '500px');
});
it('Should have a default height when the data is empty', () => {
render(
<Table autoHeight data={[]}>
{columns}
</Table>
);
expect(screen.getByRole('grid')).to.have.style('height', '200px');
});
it('Should not exceed the maximum height', () => {
render(
<Table data={mockData(2)} maxHeight={300} height={500}>
{columns}
</Table>
);
expect(screen.getByRole('grid')).to.have.style('height', '300px');
});
it('Should not exceed the maximum height even if autoHeight is set', () => {
render(
<Table autoHeight data={mockData(10)} maxHeight={300}>
{columns}
</Table>
);
expect(screen.getByRole('grid')).to.have.style('height', '300px');
});
});