-
Notifications
You must be signed in to change notification settings - Fork 674
Expand file tree
/
Copy pathcolumnHeaders.ts
More file actions
202 lines (169 loc) · 6.06 KB
/
Copy pathcolumnHeaders.ts
File metadata and controls
202 lines (169 loc) · 6.06 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import PivotGrid from 'devextreme-testcafe-models/pivotGrid';
import { ClientFunction, Selector } from 'testcafe';
import { createWidget } from '../../../../helpers/createWidget';
import url from '../../../../helpers/getPageUrl';
import { sales } from '../data';
fixture.disablePageReloads`pivotGrid_kbn_columnHeaders`
.page(url(__dirname, '../../../container.html'));
const PIVOT_GRID_SELECTOR = '#container';
const COLUMN_HEADERS_CELL_SELECTOR = 'thead.dx-pivotgrid-horizontal-headers td';
const blurActiveElement = ClientFunction(() => {
const activeElement = document.activeElement as HTMLElement | null;
activeElement?.blur();
});
const createConfig = () => ({
width: 800,
allowExpandAll: true,
fieldChooser: {
enabled: false,
},
dataSource: {
fields: [{
dataField: 'region',
area: 'column',
expanded: true,
}, {
dataField: 'country',
area: 'column',
}, {
dataField: 'city',
area: 'row',
}, {
dataField: 'amount',
area: 'data',
summaryType: 'sum',
dataType: 'number',
}],
store: sales,
},
});
test('Column header cells should form a single tab stop', async (t) => {
const pivotGrid = new PivotGrid(PIVOT_GRID_SELECTOR);
const columnsArea = pivotGrid.getColumnsArea();
await t
.expect(Selector(`${COLUMN_HEADERS_CELL_SELECTOR}[tabindex="0"]`).count)
.eql(1, 'only one column header cell is in the tab order');
await blurActiveElement();
await t
.pressKey('tab')
.expect(columnsArea.getCell(0, 0).focused)
.ok('first column header cell is focused by Tab');
await t
.expect(Selector(`${COLUMN_HEADERS_CELL_SELECTOR} .dx-expand-icon-container[tabindex="0"]`).count)
.eql(0, 'expand icons of column header cells are not in the tab order');
}).before(async () => createWidget('dxPivotGrid', createConfig()));
test('ArrowLeft and ArrowRight should move focus between cells in a level', async (t) => {
const pivotGrid = new PivotGrid(PIVOT_GRID_SELECTOR);
const columnsArea = pivotGrid.getColumnsArea();
await t
.click(columnsArea.getCell(1, 0))
.expect(columnsArea.getCell(1, 0).focused)
.ok('first cell of the second level is focused after click');
await t
.pressKey('right')
.expect(columnsArea.getCell(1, 1).focused)
.ok('next cell in the level is focused after ArrowRight');
await t
.pressKey('left')
.expect(columnsArea.getCell(1, 0).focused)
.ok('previous cell in the level is focused after ArrowLeft');
}).before(async () => createWidget('dxPivotGrid', createConfig()));
test('ArrowUp and ArrowDown should move focus between header levels', async (t) => {
const pivotGrid = new PivotGrid(PIVOT_GRID_SELECTOR);
const columnsArea = pivotGrid.getColumnsArea();
await t
.click(columnsArea.getCell(1, 0));
await t
.pressKey('up')
.expect(columnsArea.getCell(0, 0).focused)
.ok('parent level cell is focused after ArrowUp');
await t
.pressKey('down')
.expect(columnsArea.getCell(1, 0).focused)
.ok('child level cell is focused after ArrowDown');
}).before(async () => createWidget('dxPivotGrid', createConfig()));
test('Roving tabindex should follow the focused cell', async (t) => {
const pivotGrid = new PivotGrid(PIVOT_GRID_SELECTOR);
const columnsArea = pivotGrid.getColumnsArea();
await t
.click(columnsArea.getCell(1, 1))
.expect(columnsArea.getCell(1, 1).getAttribute('tabindex'))
.eql('0', 'focused cell is in the tab order');
await t
.expect(Selector(`${COLUMN_HEADERS_CELL_SELECTOR}[tabindex="0"]`).count)
.eql(1, 'the focused cell is the only tab stop');
await t
.expect(columnsArea.getCell(0, 0).getAttribute('tabindex'))
.eql('-1', 'the first cell is removed from the tab order');
}).before(async () => createWidget('dxPivotGrid', createConfig()));
test('Focus should be preserved after expand and collapse by Enter', async (t) => {
const pivotGrid = new PivotGrid(PIVOT_GRID_SELECTOR);
const columnsArea = pivotGrid.getColumnsArea();
await blurActiveElement();
await t
.pressKey('tab')
.expect(columnsArea.getCell(0, 0).focused)
.ok('expandable cell is focused');
const firstCellText = (await columnsArea.getCell(0, 0).textContent).trim();
await t
.pressKey('enter')
.expect(Selector(':focus').getAttribute('aria-label'))
.eql(firstCellText, 'focus stays on the collapsed item control');
await t
.pressKey('enter')
.expect(Selector(':focus').getAttribute('aria-label'))
.eql(firstCellText, 'focus stays on the expanded item control');
}).before(async () => createWidget('dxPivotGrid', createConfig()));
test('Focused cell should stay in view with virtual scrolling', async (t) => {
const pivotGrid = new PivotGrid(PIVOT_GRID_SELECTOR);
const { getInstance } = pivotGrid;
const getColumnsScrollLeft = ClientFunction(
// eslint-disable-next-line no-underscore-dangle
() => (getInstance() as any)._columnsArea._getScrollable().scrollLeft(),
{ dependencies: { getInstance } },
);
await blurActiveElement();
await t.pressKey('tab');
for (let i = 0; i < 8; i += 1) {
await t.pressKey('right');
}
const focusedCell = Selector(`${COLUMN_HEADERS_CELL_SELECTOR}`).filter((node) => node === document.activeElement);
await t
.expect(focusedCell.count)
.eql(1, 'a column header cell is focused after arrow navigation')
.expect(focusedCell.visible)
.ok('the focused cell is visible')
.expect(getColumnsScrollLeft())
.gt(0, 'the column headers area is scrolled to the focused cell');
}).before(async () => createWidget('dxPivotGrid', {
...createConfig(),
width: 300,
height: 300,
scrolling: {
mode: 'virtual',
},
dataSource: {
fields: [{
dataField: 'region',
area: 'column',
expanded: true,
}, {
dataField: 'country',
area: 'column',
expanded: true,
}, {
dataField: 'city',
area: 'column',
}, {
dataField: 'date',
dataType: 'date',
area: 'row',
}, {
dataField: 'amount',
area: 'data',
summaryType: 'sum',
dataType: 'number',
}],
store: sales,
},
}));