-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathColumnGroupTableSpec.tsx
128 lines (107 loc) · 4.09 KB
/
ColumnGroupTableSpec.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
import React from 'react';
import Table from '../src/Table';
import Column from '../src/Column';
import Cell from '../src/Cell';
import ColumnGroup from '../src/ColumnGroup';
import HeaderCell from '../src/HeaderCell';
import { render, screen } from '@testing-library/react';
describe('ColumnGroupTable', () => {
it('Should be aligned in ColumnGroup', () => {
const data = [
{
name: 'test name',
id: 1
}
];
render(
<Table data={data}>
<ColumnGroup header={'Info'} align="right" verticalAlign="top">
<Column width={150} resizable sortable align="left" verticalAlign="bottom">
<HeaderCell>firstName</HeaderCell>
<Cell dataKey="name" />
</Column>
<Column width={150} resizable sortable>
<HeaderCell>lastName</HeaderCell>
<Cell dataKey="name" />
</Column>
<Column width={200} resizable sortable align="center" verticalAlign="middle">
<HeaderCell>Email</HeaderCell>
<Cell dataKey="name" />
</Column>
</ColumnGroup>
</Table>
);
const table = screen.getByRole('grid');
const groupHeader = table.querySelector('.rs-table-column-group-header-content');
const groupChildren = table.querySelectorAll(
'.rs-table-column-group .rs-table-column-group-cell .rs-table-cell-content'
);
expect(groupHeader).to.have.style('justify-content', 'flex-end');
expect(groupHeader).to.have.style('align-items', 'flex-start');
expect(groupChildren).to.have.length(3);
expect(groupChildren[0]).to.have.text('firstName');
expect(groupChildren[1]).to.have.text('lastName');
expect(groupChildren[2]).to.have.text('Email');
expect(groupChildren[0]).to.have.style('justify-content', 'flex-start');
expect(groupChildren[0]).to.have.style('align-items', 'flex-end');
expect(groupChildren[1]).to.have.style('justify-content', 'flex-end');
expect(groupChildren[1]).to.have.style('align-items', 'flex-start');
expect(groupChildren[2]).to.have.style('justify-content', 'center');
expect(groupChildren[2]).to.have.style('align-items', 'center');
const groupBodyChildren = table.querySelectorAll(
'.rs-table-body-row-wrapper .rs-table-cell-content'
);
expect(groupBodyChildren).to.have.length(3);
expect(groupBodyChildren[0]).to.have.style('justify-content', 'flex-start');
expect(groupBodyChildren[0]).to.have.style('align-items', 'flex-end');
expect(groupBodyChildren[1]).to.have.style('justify-content', 'flex-end');
expect(groupBodyChildren[1]).to.have.style('align-items', 'flex-start');
expect(groupBodyChildren[2]).to.have.style('justify-content', 'center');
expect(groupBodyChildren[2]).to.have.style('align-items', 'center');
});
it('Should render 2 ColumnGroup', () => {
const columnData = [
{
name: 'test 1',
id: 1
},
{
name: 'test 2',
id: 2
}
];
render(
<div style={{ width: 300 }}>
<Table data={[]}>
{columnData.map((item, index) => {
return (
<ColumnGroup key={index} header={item.name} fixed>
<Column width={130} sortable>
<HeaderCell>First Name</HeaderCell>
<Cell dataKey="firstName" />
</Column>
<Column width={130} sortable>
<HeaderCell>Last Name</HeaderCell>
<Cell dataKey="lastName" />
</Column>
</ColumnGroup>
);
})}
</Table>
</div>
);
const table = screen.getByRole('grid');
expect(table.querySelectorAll('.rs-table-column-group')).to.have.length(2);
expect(table.querySelectorAll('.rs-table-column-group-header-content')[0]).to.have.text(
'test 1'
);
expect(table.querySelectorAll('.rs-table-column-group-header-content')[1]).to.have.text(
'test 2'
);
expect(
table.querySelectorAll(
'.rs-table-column-group .rs-table-cell-header .rs-table-cell-header-icon-sort'
)
).to.have.length(4);
});
});