@@ -6,18 +6,25 @@ import { IgxPivotGridMultipleRowComponent, IgxPivotGridTestBaseComponent } from
6
6
import { UIInteractions , wait } from '../../test-utils/ui-interactions.spec' ;
7
7
import { IgxPivotGridComponent } from './pivot-grid.component' ;
8
8
import { IgxPivotRowDimensionHeaderComponent } from './pivot-row-dimension-header.component' ;
9
+ import { DebugElement } from '@angular/core' ;
10
+ import { IgxPivotHeaderRowComponent } from './pivot-header-row.component' ;
11
+ import { PivotRowLayoutType } from 'igniteui-angular' ;
9
12
10
13
const DEBOUNCE_TIME = 250 ;
11
14
const PIVOT_TBODY_CSS_CLASS = '.igx-grid__tbody' ;
12
15
const PIVOT_ROW_DIMENSION_CONTENT = 'igx-pivot-row-dimension-content' ;
13
16
const PIVOT_HEADER_ROW = 'igx-pivot-header-row' ;
14
17
const HEADER_CELL_CSS_CLASS = '.igx-grid-th' ;
15
18
const ACTIVE_CELL_CSS_CLASS = '.igx-grid-th--active' ;
19
+ const CSS_CLASS_ROW_DIMENSION_CONTAINER = '.igx-grid__tbody-pivot-dimension'
20
+ const CSS_CLASS_TBODY_CONTENT = '.igx-grid__tbody-content' ;
16
21
17
22
describe ( 'IgxPivotGrid - Keyboard navigation #pivotGrid' , ( ) => {
18
23
describe ( 'General Keyboard Navigation' , ( ) => {
19
24
let fixture : ComponentFixture < IgxPivotGridMultipleRowComponent > ;
20
25
let pivotGrid : IgxPivotGridComponent ;
26
+ let rowDimension : DebugElement ;
27
+ let headerRow : DebugElement ;
21
28
22
29
beforeEach ( waitForAsync ( ( ) => {
23
30
TestBed . configureTestingModule ( {
@@ -28,10 +35,14 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
28
35
} ) . compileComponents ( ) ;
29
36
} ) ) ;
30
37
31
- beforeEach ( fakeAsync ( ( ) => {
38
+ beforeEach ( fakeAsync ( async ( ) => {
32
39
fixture = TestBed . createComponent ( IgxPivotGridMultipleRowComponent ) ;
33
40
fixture . detectChanges ( ) ;
34
41
pivotGrid = fixture . componentInstance . pivotGrid ;
42
+ await fixture . whenStable ( ) ;
43
+ rowDimension = fixture . debugElement . query (
44
+ By . css ( CSS_CLASS_ROW_DIMENSION_CONTAINER ) ) ;
45
+ headerRow = fixture . debugElement . query ( By . directive ( IgxPivotHeaderRowComponent ) ) ;
35
46
} ) ) ;
36
47
37
48
it ( 'should allow navigating between row headers' , ( ) => {
@@ -43,24 +54,32 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
43
54
fixture . detectChanges ( ) ;
44
55
45
56
GridFunctions . verifyHeaderIsFocused ( firstCell . parent ) ;
46
- let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
57
+ // for the row dimensions headers, the active descendant is set on the div having
58
+ // tabindex="0" and class '.igx-grid__tbody-pivot-dimension';
59
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , firstCell . nativeElement . id ) ;
60
+ expect ( firstCell . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'rowheader' ) ;
61
+ let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
47
62
expect ( activeCells . length ) . toBe ( 1 ) ;
48
63
49
64
UIInteractions . triggerKeyDownEvtUponElem ( 'ArrowRight' , firstCell . nativeElement ) ;
50
65
fixture . detectChanges ( ) ;
51
66
GridFunctions . verifyHeaderIsFocused ( secondCell . parent ) ;
67
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , secondCell . nativeElement . id ) ;
68
+ expect ( firstCell . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'rowheader' ) ;
52
69
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
53
70
expect ( activeCells . length ) . toBe ( 1 ) ;
54
71
55
72
// should do nothing if wrong key is pressed
56
73
UIInteractions . simulateClickAndSelectEvent ( firstCell ) ;
57
74
fixture . detectChanges ( ) ;
58
75
GridFunctions . verifyHeaderIsFocused ( firstCell . parent ) ;
76
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , firstCell . nativeElement . id ) ;
59
77
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
60
78
expect ( activeCells . length ) . toBe ( 1 ) ;
61
79
UIInteractions . triggerKeyDownEvtUponElem ( 'h' , firstCell . nativeElement ) ;
62
80
fixture . detectChanges ( ) ;
63
81
GridFunctions . verifyHeaderIsFocused ( firstCell . parent ) ;
82
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , firstCell . nativeElement . id ) ;
64
83
} ) ;
65
84
66
85
it ( 'should not go outside of the boundaries of the row dimensions content' , ( ) => {
@@ -75,6 +94,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
75
94
fixture . detectChanges ( ) ;
76
95
77
96
GridFunctions . verifyHeaderIsFocused ( firstCell . parent ) ;
97
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , firstCell . nativeElement . id ) ;
78
98
let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
79
99
expect ( activeCells . length ) . toBe ( 1 ) ;
80
100
@@ -85,6 +105,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
85
105
fixture . detectChanges ( ) ;
86
106
87
107
GridFunctions . verifyHeaderIsFocused ( thirdCell . parent ) ;
108
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , thirdCell . nativeElement . id ) ;
88
109
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
89
110
expect ( activeCells . length ) . toBe ( 1 ) ;
90
111
} ) ;
@@ -100,12 +121,14 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
100
121
UIInteractions . triggerKeyDownEvtUponElem ( 'End' , firstCell . nativeElement ) ;
101
122
fixture . detectChanges ( ) ;
102
123
GridFunctions . verifyHeaderIsFocused ( thirdCell . parent ) ;
124
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , thirdCell . nativeElement . id ) ;
103
125
let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
104
126
expect ( activeCells . length ) . toBe ( 1 ) ;
105
127
106
128
UIInteractions . triggerKeyDownEvtUponElem ( 'Home' , thirdCell . nativeElement ) ;
107
129
fixture . detectChanges ( ) ;
108
130
GridFunctions . verifyHeaderIsFocused ( firstCell . parent ) ;
131
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , firstCell . nativeElement . id ) ;
109
132
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
110
133
expect ( activeCells . length ) . toBe ( 1 ) ;
111
134
} ) ;
@@ -124,6 +147,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
124
147
By . directive ( IgxPivotRowDimensionHeaderComponent ) ) ;
125
148
const lastCell = allGroups [ allGroups . length - 1 ] ;
126
149
GridFunctions . verifyHeaderIsFocused ( lastCell . parent ) ;
150
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , lastCell . nativeElement . id ) ;
127
151
const activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
128
152
expect ( activeCells . length ) . toBe ( 1 ) ;
129
153
} ) ;
@@ -143,6 +167,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
143
167
By . directive ( IgxPivotRowDimensionHeaderComponent ) ) ;
144
168
const firstCell = allGroups [ 0 ] ;
145
169
GridFunctions . verifyHeaderIsFocused ( firstCell . parent ) ;
170
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , firstCell . nativeElement . id ) ;
146
171
let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
147
172
expect ( activeCells . length ) . toBe ( 1 ) ;
148
173
@@ -156,6 +181,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
156
181
By . directive ( IgxPivotRowDimensionHeaderComponent ) ) ;
157
182
const secondCell = allGroups . filter ( x => x . componentInstance . column . field === 'ProductCategory' ) [ 1 ] ;
158
183
GridFunctions . verifyHeaderIsFocused ( secondCell . parent ) ;
184
+ GridFunctions . verifyPivotElementActiveDescendant ( rowDimension , secondCell . nativeElement . id ) ;
159
185
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
160
186
expect ( activeCells . length ) . toBe ( 1 ) ;
161
187
@@ -170,7 +196,9 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
170
196
firstHeader = fixture . debugElement . queryAll (
171
197
By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 0 ] ;
172
198
GridFunctions . verifyHeaderIsFocused ( firstHeader . parent ) ;
173
- let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
199
+ // for the column headers, the active descendant is set on the header row element
200
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , firstHeader . nativeElement . id ) ;
201
+ let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
174
202
expect ( activeCells . length ) . toBe ( 1 ) ;
175
203
176
204
UIInteractions . triggerKeyDownEvtUponElem ( 'ArrowRight' , pivotGrid . theadRow . nativeElement ) ;
@@ -179,6 +207,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
179
207
const secondHeader = fixture . debugElement . queryAll (
180
208
By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 1 ] ;
181
209
GridFunctions . verifyHeaderIsFocused ( secondHeader . parent ) ;
210
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , secondHeader . nativeElement . id ) ;
182
211
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
183
212
expect ( activeCells . length ) . toBe ( 1 ) ;
184
213
} ) ;
@@ -193,6 +222,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
193
222
By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 0 ] ;
194
223
195
224
GridFunctions . verifyHeaderIsFocused ( firstHeader . parent ) ;
225
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , firstHeader . nativeElement . id ) ;
196
226
let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
197
227
expect ( activeCells . length ) . toBe ( 1 ) ;
198
228
@@ -204,6 +234,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
204
234
By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) ;
205
235
const lastHeader = allHeaders [ allHeaders . length - 1 ] ;
206
236
GridFunctions . verifyHeaderIsFocused ( lastHeader . parent ) ;
237
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , lastHeader . nativeElement . id ) ;
207
238
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
208
239
expect ( activeCells . length ) . toBe ( 1 ) ;
209
240
} ) ;
@@ -222,20 +253,58 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
222
253
firstHeader = fixture . debugElement . queryAll (
223
254
By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 0 ] ;
224
255
GridFunctions . verifyHeaderIsFocused ( firstHeader . parent ) ;
225
- let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
256
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , firstHeader . nativeElement . id ) ;
257
+ let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
226
258
expect ( activeCells . length ) . toBe ( 1 ) ;
227
259
228
260
UIInteractions . triggerKeyDownEvtUponElem ( 'ArrowRight' , firstHeader . nativeElement ) ;
229
261
fixture . detectChanges ( ) ;
230
262
const secondHeader = fixture . debugElement . queryAll (
231
263
By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 1 ] ;
232
264
GridFunctions . verifyHeaderIsFocused ( secondHeader . parent ) ;
265
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , secondHeader . nativeElement . id ) ;
266
+ activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
267
+ expect ( activeCells . length ) . toBe ( 1 ) ;
268
+ } ) ;
269
+
270
+ it ( 'should navigate properly among row dimension column headers for horizontal row layout' , ( ) => {
271
+ pivotGrid . pivotUI = {
272
+ ...pivotGrid . pivotUI ,
273
+ rowLayout : PivotRowLayoutType . Horizontal ,
274
+ showRowHeaders : true
275
+ } ;
276
+ fixture . detectChanges ( ) ;
277
+
278
+ let firstHeader = fixture . debugElement . queryAll (
279
+ By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 0 ] ;
280
+ UIInteractions . simulateClickAndSelectEvent ( firstHeader ) ;
281
+ fixture . detectChanges ( ) ;
282
+
283
+ firstHeader = fixture . debugElement . queryAll (
284
+ By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 0 ] ;
285
+ GridFunctions . verifyHeaderIsFocused ( firstHeader . parent ) ;
286
+ // for the row dimensions column headers in horizontal layout,
287
+ // the active descendant is set on the header row element.
288
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , firstHeader . nativeElement . id ) ;
289
+ expect ( firstHeader . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'columnheader' ) ;
290
+ let activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
291
+ expect ( activeCells . length ) . toBe ( 1 ) ;
292
+
293
+ UIInteractions . triggerKeyDownEvtUponElem ( 'ArrowRight' , pivotGrid . theadRow . nativeElement ) ;
294
+ fixture . detectChanges ( ) ;
295
+
296
+ const secondHeader = fixture . debugElement . queryAll (
297
+ By . css ( `${ PIVOT_HEADER_ROW } ${ HEADER_CELL_CSS_CLASS } ` ) ) [ 1 ] ;
298
+ GridFunctions . verifyHeaderIsFocused ( secondHeader . parent ) ;
299
+ GridFunctions . verifyPivotElementActiveDescendant ( headerRow , secondHeader . nativeElement . id ) ;
300
+ expect ( firstHeader . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'columnheader' ) ;
233
301
activeCells = fixture . debugElement . queryAll ( By . css ( `${ ACTIVE_CELL_CSS_CLASS } ` ) ) ;
234
302
expect ( activeCells . length ) . toBe ( 1 ) ;
235
303
} ) ;
236
304
237
305
it ( 'should allow navigating within the cells of the body' , async ( ) => {
238
306
const cell = pivotGrid . rowList . first . cells . first ;
307
+ const tBodyContent = fixture . debugElement . query ( By . css ( CSS_CLASS_TBODY_CONTENT ) ) ;
239
308
GridFunctions . focusFirstCell ( fixture , pivotGrid ) ;
240
309
fixture . detectChanges ( ) ;
241
310
expect ( pivotGrid . navigation . activeNode . row ) . toBeUndefined ( ) ;
@@ -248,8 +317,11 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
248
317
fixture . detectChanges ( ) ;
249
318
expect ( pivotGrid . navigation . activeNode . row ) . toBeDefined ( ) ;
250
319
expect ( pivotGrid . navigation . activeNode . column ) . toBeDefined ( ) ;
320
+ // The activedescendant attribute for cells in the grid body
321
+ // is set on the tbody content div with tabindex='0'
322
+ GridFunctions . verifyPivotElementActiveDescendant ( tBodyContent , cell . nativeElement . id ) ;
251
323
252
- let activeCells = fixture . debugElement . queryAll ( By . css ( `.igx-grid__td--active` ) ) ;
324
+ let activeCells = fixture . debugElement . queryAll ( By . css ( `.igx-grid__td--active` ) ) ;
253
325
expect ( activeCells . length ) . toBe ( 1 ) ;
254
326
expect ( cell . column . field ) . toEqual ( 'Stanley-UnitsSold' ) ;
255
327
@@ -261,6 +333,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
261
333
activeCells = fixture . debugElement . queryAll ( By . css ( `.igx-grid__td--active` ) ) ;
262
334
expect ( activeCells . length ) . toBe ( 1 ) ;
263
335
expect ( activeCells [ 0 ] . componentInstance . column . field ) . toEqual ( 'Stanley-UnitPrice' )
336
+ GridFunctions . verifyPivotElementActiveDescendant ( tBodyContent , activeCells [ 0 ] . nativeElement . id ) ;
264
337
} ) ;
265
338
} ) ;
266
339
describe ( 'Row Dimension Expand/Collapse Keyboard Interactions' , ( ) => {
@@ -282,7 +355,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
282
355
283
356
it ( 'should allow row dimension expand(Alt + ArrowDown/ArrowRight) and collapse(Alt + ArrowUp/ArrowLeft)' , async ( ) => {
284
357
const rowDimension = fixture . debugElement . queryAll (
285
- By . css ( `.igx-grid__tbody-pivot-dimension` ) ) ;
358
+ By . css ( CSS_CLASS_ROW_DIMENSION_CONTAINER ) ) ;
286
359
let allHeaders = fixture . debugElement . queryAll (
287
360
By . directive ( IgxPivotRowDimensionHeaderComponent ) ) ;
288
361
0 commit comments