-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathcombobox_grid-combo.js
959 lines (822 loc) · 26.9 KB
/
combobox_grid-combo.js
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const assertAriaLabelledby = require('../util/assertAriaLabelledby');
const assertAttributeValues = require('../util/assertAttributeValues');
const assertAttributeDNE = require('../util/assertAttributeDNE');
const assertAriaRoles = require('../util/assertAriaRoles');
const isMacOS = require('../util/isMacOS');
const exampleFile = 'content/patterns/combobox/examples/grid-combo.html';
const ex = {
labelSelector: '#ex1 label',
comboboxSelector: '#ex1 input[type="text"]',
gridSelector: '#ex1 [role="grid"]',
rowSelector: '#ex1 [role="row"]',
gridcellSelector: '#ex1 [role="gridcell"]',
gridcellFocusedClass: 'focused-cell',
numAOptions: 3,
};
const waitForFocusChange = async (t, comboboxSelector, originalFocus) => {
await t.context.session.wait(
async function () {
let newFocus = await t.context.session
.findElement(By.css(comboboxSelector))
.getAttribute('aria-activedescendant');
return newFocus != originalFocus;
},
t.context.waitTime,
'Timeout waiting for "aria-activedescendant" value to change from "' +
originalFocus +
'". '
);
};
const confirmCursorIndex = async (t, selector, cursorIndex) => {
return t.context.session.executeScript(
function () {
const [selector, cursorIndex] = arguments;
let item = document.querySelector(selector);
return item.selectionStart === cursorIndex;
},
selector,
cursorIndex
);
};
const gridcellId = (row, column) => {
return 'result-item-' + row + 'x' + column;
};
// Attributes
ariaTest(
'Test for role="combobox"',
exampleFile,
'combobox-role',
async (t) => {
await assertAriaRoles(t, 'ex1', 'combobox', '1', 'input');
}
);
ariaTest(
'"aria-haspopup"=grid on combobox element',
exampleFile,
'combobox-aria-haspopup',
async (t) => {
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-haspopup',
'grid'
);
}
);
ariaTest(
'"aria-expanded" on combobox element',
exampleFile,
'combobox-aria-expanded',
async (t) => {
const combobox = await t.context.session.findElement(
By.css(ex.comboboxSelector)
);
// Check that aria-expanded is false and the grid is not visible before interacting
t.is(
await combobox.getAttribute('aria-expanded'),
'false',
'combobox element should have attribute "aria-expanded" set to false by default.'
);
const popupId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-controls');
const popupElement = await t.context.session
.findElement(By.id('ex1'))
.findElement(By.id(popupId));
t.false(
await popupElement.isDisplayed(),
"Popup element should not be displayed when 'aria-expanded' is false'"
);
// Send key "a" to combobox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a');
// Check that aria-expanded is true and the grid is visible
t.is(
await combobox.getAttribute('aria-expanded'),
'true',
'combobox element should have attribute "aria-expand" set to true after typing.'
);
t.true(
await popupElement.isDisplayed(),
"Popup element should be displayed when 'aria-expanded' is true'"
);
}
);
ariaTest(
'"id" attribute on textbox used to discover accessible name',
exampleFile,
'combobox-id',
async (t) => {
const labelForTextboxId = await t.context.session
.findElement(By.css(ex.labelSelector))
.getAttribute('for');
t.truthy(
labelForTextboxId,
'"for" attribute with id value should exist on label: ' + ex.labelSelector
);
const textboxElementId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('id');
t.true(
labelForTextboxId === textboxElementId,
'Id on textbox element (' +
ex.comboboxSelector +
') should match the "for" attribute of the label (' +
labelForTextboxId +
')'
);
}
);
ariaTest(
'"aria-autocomplete" on grid element',
exampleFile,
'combobox-aria-autocomplete',
async (t) => {
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-autocomplete',
'list'
);
}
);
ariaTest(
'"aria-controls" attribute on grid element',
exampleFile,
'combobox-aria-controls',
async (t) => {
const popupId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-controls');
t.truthy(
popupId,
'"aria-controls" attribute should exist on: ' + ex.comboboxSelector
);
const popupElements = await t.context.queryElements(t, `#ex1 #${popupId}`);
t.is(
popupElements.length,
1,
'There should be a element with id "' +
popupId +
'" as referenced by the aria-controls attribute'
);
}
);
ariaTest(
'"aria-activedescendant" on combobox element',
exampleFile,
'combobox-aria-activedescendant',
async (t) => {
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-activedescendant',
null
);
}
);
ariaTest('role "grid" on div element', exampleFile, 'grid-role', async (t) => {
await assertAriaRoles(t, 'ex1', 'grid', '1', 'div');
});
ariaTest(
'"aria-labelledby" attribute on grid element',
exampleFile,
'grid-aria-labelledby',
async (t) => {
await assertAriaLabelledby(t, ex.gridSelector);
}
);
ariaTest(
'role "row" exists within grid element',
exampleFile,
'row-role',
async (t) => {
// Send key "a" then arrow down to reveal all options
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_DOWN);
let gridEl = await t.context.session.findElement(By.css(ex.gridSelector));
let rowElements = await t.context.queryElements(t, '[role="row"]', gridEl);
t.truthy(
await rowElements.length,
'role="row" elements should be found within a gridcell element after opening popup'
);
}
);
// This test fails due to bug: https://github.com/w3c/aria-practices/issues/859
ariaTest.failing(
'"aria-selected" attribute on row element',
exampleFile,
'row-aria-selected',
async (t) => {
// Send key "a"
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a');
await assertAttributeDNE(
t,
ex.rowSelector + ':nth-of-type(1)',
'aria-selected'
);
// Send key ARROW_DOWN to selected first option
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_DOWN);
await assertAttributeValues(
t,
ex.rowSelector + ':nth-of-type(1)',
'aria-selected',
'true'
);
}
);
ariaTest(
'role "gridcell" exists within row element',
exampleFile,
'gridcell-role',
async (t) => {
// Send key "a" then arrow down to reveal all options
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_DOWN);
let rowElement = await t.context.session.findElement(
By.css(ex.rowSelector)
);
let cellElements = await t.context.queryElements(
t,
'[role="gridcell"]',
rowElement
);
t.truthy(
await cellElements.length,
'role="gridcell" elements should be found within a row element after opening popup'
);
}
);
// Keys
ariaTest(
'Test down key press with focus on combobox',
exampleFile,
'textbox-key-down-arrow',
async (t) => {
// Send ARROW_DOWN to the combobox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_DOWN);
// Check that the grid is displayed
t.false(
await t.context.session
.findElement(By.css(ex.gridSelector))
.isDisplayed(),
'In example ex3 grid should not be display after ARROW_DOWN keypress while combobox is empty'
);
// Send "a" then ARROW_DOWN to the combobox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_DOWN);
// Account for race condition
await waitForFocusChange(t, ex.comboboxSelector, '');
// Check that the grid is displayed
t.true(
await t.context.session
.findElement(By.css(ex.gridSelector))
.isDisplayed(),
'In example ex3 grid should display after ARROW_DOWN keypress when combobox has character values'
);
// Check that the active descendent focus is correct
let focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(0, 0),
'After down arrow sent to combobox, aria-activedescendant should be set to the first gridcell element: ' +
gridcellId(0, 0)
);
let focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(0, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' + gridcellId(0, 0) + '" should have visual focus'
);
}
);
ariaTest(
'Test down key press with focus on list',
exampleFile,
'popup-key-down-arrow',
async (t) => {
// Send 'a' to text box, then send ARROW_DOWN to combobox to set focus on grid
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_DOWN);
// Test that ARROW_DOWN moves active descendant focus on item in grid
for (let i = 1; i < ex.numAOptions; i++) {
let oldFocus = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_DOWN);
// Account for race condition
await waitForFocusChange(t, ex.comboboxSelector, oldFocus);
// Check that the active descendent focus is correct
let focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(i, 0),
'After down up sent to combobox, aria-activedescendant should be set to this gridcell element: ' +
gridcellId(i, 0)
);
let focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(i, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' + gridcellId(i, 0) + '" should have visual focus'
);
}
// Sending ARROW_DOWN to the last item should put focus on the first
let oldFocus = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_DOWN);
// Account for race condition
await waitForFocusChange(t, ex.comboboxSelector, oldFocus);
// Focus should be on the first item
let focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(0, 0),
'After down arrow sent to last grid row, aria-activedescendant should be set to the first gridcell element: ' +
gridcellId(0, 0)
);
let focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(0, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' + gridcellId(0, 0) + '" should have visual focus'
);
}
);
ariaTest(
'Test up key press with focus on combobox',
exampleFile,
'textbox-key-up-arrow',
async (t) => {
// Send ARROW_UP to the combobox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_UP);
// Check that the grid is displayed
t.false(
await t.context.session
.findElement(By.css(ex.gridSelector))
.isDisplayed(),
'In example ex3 grid should not be display after ARROW_UP keypress while combobox is empty'
);
// Send "a" then ARROW_UP to the combobox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_UP);
// Account for race condition
await waitForFocusChange(t, ex.comboboxSelector, '');
// Check that the grid is displayed
t.true(
await t.context.session
.findElement(By.css(ex.gridSelector))
.isDisplayed(),
'In example ex3 grid should display after ARROW_UP keypress when combobox has character values'
);
// Check that the active descendent focus is correct
let focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(ex.numAOptions - 1, 0),
'After up arrow sent to combobox, aria-activedescendant should be set to the last row first gridcell element: ' +
gridcellId(ex.numAOptions - 1, 0)
);
let focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(ex.numAOptions - 1, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' +
gridcellId(ex.numAOptions - 1, 0) +
'" should have visual focus'
);
}
);
ariaTest(
'Test up key press with focus on grid',
exampleFile,
'popup-key-up-arrow',
async (t) => {
// Send 'a' to text box, then send ARROW_UP to combobox to put focus in combobox
// Up arrow should move selection to the last item in the list
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_UP);
// Test that ARROW_UP moves active descendant focus up one item in the grid
for (let index = ex.numAOptions - 2; index >= 0; index--) {
let oldFocus = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
// Send Key
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_UP);
await waitForFocusChange(t, ex.comboboxSelector, oldFocus);
// Check that the active descendent focus is correct
let focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(index, 0),
'After up arrow sent to combobox, aria-activedescendant should be set to gridcell element: ' +
gridcellId(index, 0)
);
let focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(index, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' +
gridcellId(index, 0) +
'" should have visual focus'
);
}
// Test that ARROW_UP, when on the first item, returns focus to the last item in the list
let oldFocus = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
// Send Key
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ARROW_UP);
await waitForFocusChange(t, ex.comboboxSelector, oldFocus);
// Check that the active descendent focus is correct
let focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(ex.numAOptions - 1, 0),
'After up arrow sent to first element in popup, aria-activedescendant should be set to the last row first gridcell element: ' +
gridcellId(ex.numAOptions - 1, 0)
);
let focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(ex.numAOptions - 1, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' +
gridcellId(ex.numAOptions - 1, 0) +
'" should have visual focus'
);
}
);
ariaTest(
'Test enter key press with focus on grid',
exampleFile,
'popup-key-enter',
async (t) => {
// Send key "a" to the combobox, then key ARROW_DOWN to select the first item
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_DOWN);
// Get the value of the first option in the grid
const firstOption = await t.context.session
.findElement(By.css(ex.gridcellSelector))
.getText();
// Send key ENTER
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ENTER);
// Confirm that the grid is closed
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-expanded',
'false'
);
// Confirm that the value of the combobox is now set to the first option
t.is(
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('value'),
firstOption,
'key press "ENTER" should result in first option in combobox'
);
}
);
ariaTest(
'Test escape key press with focus on combobox',
exampleFile,
'textbox-key-escape',
async (t) => {
// Send key "a" then key "ARROW_DOWN to put the focus on the listbox,
// then key ESCAPE to the textbox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ESCAPE);
// Confirm the listbox is closed and the textbox is cleared
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-expanded',
'false'
);
t.is(
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('value'),
'a',
'In listbox key press "ESCAPE" should result in "a" in textbox'
);
}
);
ariaTest(
'Test double escape key press with focus on combobox',
exampleFile,
'textbox-key-escape',
async (t) => {
// Send key "a", then key ESCAPE twice to the textbox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ESCAPE, Key.ESCAPE);
// Confirm the listbox is closed and the textbox is cleared
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-expanded',
'false'
);
t.is(
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('value'),
'',
'In key press "ESCAPE" should result in clearing the textbox'
);
}
);
ariaTest(
'Test escape key press with focus on popup',
exampleFile,
'popup-key-escape',
async (t) => {
// Send key "a" then key "ARROW_DOWN to put the focus on the grid,
// then key ESCAPE to the combobox
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys('a', Key.ARROW_DOWN);
await waitForFocusChange(t, ex.comboboxSelector, '');
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.sendKeys(Key.ESCAPE);
// Wait for gridbox to close
await t.context.session.wait(
async function () {
return !(await t.context.session
.findElement(By.css(ex.gridSelector))
.isDisplayed());
},
t.context.waitTime,
'Timeout waiting for gridbox to close after escape'
);
// Confirm the grid is closed and the textbox is cleared
await assertAttributeValues(
t,
ex.comboboxSelector,
'aria-expanded',
'false'
);
t.is(
await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('value'),
'a',
'In grid key press "ESCAPE" should result the "a" in the combobox'
);
}
);
ariaTest(
'left arrow from focus on list puts focus on grid and moves cursor right',
exampleFile,
'popup-key-left-arrow',
async (t) => {
// Send key "a" then key "ARROW_DOWN" to put the focus on the grid
const combobox = t.context.session.findElement(By.css(ex.comboboxSelector));
await combobox.sendKeys('a', Key.ARROW_DOWN);
// Send key "ARROW_LEFT"
await combobox.sendKeys(Key.ARROW_LEFT);
// Check that the active descendent focus is correct
let lastRow = ex.numAOptions - 1;
var focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(lastRow, 1),
'After left arrow sent to popup, aria-activedescendant should be set to the last row, last gridcell: ' +
gridcellId(lastRow, 1)
);
var focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(lastRow, 1)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' +
gridcellId(lastRow, 1) +
'" should have visual focus'
);
// Send key "ARROW_LEFT" a second time
await combobox.sendKeys(Key.ARROW_LEFT);
// Check that the active descendent focus is correct
focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(lastRow, 0),
'After left arrow sent twice to popup, aria-activedescendant should be set to the last row first gridcell: ' +
gridcellId(lastRow, 0)
);
focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(lastRow, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' +
gridcellId(lastRow, 0) +
'" should have visual focus'
);
}
);
ariaTest(
'Right arrow from focus on list puts focus on grid',
exampleFile,
'popup-key-right-arrow',
async (t) => {
// Send key "a" then key "ARROW_DOWN" to put the focus on the grid
const combobox = t.context.session.findElement(By.css(ex.comboboxSelector));
await combobox.sendKeys('a', Key.ARROW_DOWN);
// Send key "RIGHT_ARROW"
await combobox.sendKeys(Key.ARROW_RIGHT);
// Check that the active descendent focus is correct
var focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(0, 1),
'After right arrow sent to popup, aria-activedescendant should be set to the first row second gridcell element: ' +
gridcellId(0, 1)
);
var focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(0, 1)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' + gridcellId(0, 1) + '" should have visual focus'
);
// Send key "ARROW_RIGHT" a second time
await combobox.sendKeys(Key.ARROW_RIGHT);
// Check that the active descendent focus is correct
focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(1, 0),
'After right arrow send twice to popup, aria-activedescendant should be set to the second row first gridcell element: ' +
gridcellId(1, 0)
);
focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(1, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' + gridcellId(1, 0) + '" should have visual focus'
);
// Send key "ARROW_RIGHT" four more times
await combobox.sendKeys(
Key.ARROW_RIGHT,
Key.ARROW_RIGHT,
Key.ARROW_RIGHT,
Key.ARROW_RIGHT
);
// Check that the active descendent focus is correct
focusedId = await t.context.session
.findElement(By.css(ex.comboboxSelector))
.getAttribute('aria-activedescendant');
t.is(
focusedId,
gridcellId(0, 0),
'After right arrow to the popup 6 times in total, aria-activedescendant should be back on the first row, first gridcell: ' +
gridcellId(0, 0)
);
focusedElementClasses = await t.context.session
.findElement(By.id(gridcellId(0, 0)))
.getAttribute('class');
t.true(
focusedElementClasses.includes(ex.gridcellFocusedClass),
'Gridcell with id "' + gridcellId(0, 0) + '" should have visual focus'
);
}
);
ariaTest(
'Home from focus on list puts focus on grid and moves cursor',
exampleFile,
'popup-key-home',
async (t) => {
// Send key "a" then key "ARROW_DOWN" to put the focus on the grid
const combobox = t.context.session.findElement(By.css(ex.comboboxSelector));
await combobox.sendKeys('a', Key.ARROW_DOWN);
// Send key "ARROW_HOME"
await combobox.sendKeys(Key.HOME);
// On macOS, the HOME key deselects the grid popup
// but it doesn't move the cursor.
// This is being tracked in issue #3191
// https://github.com/w3c/aria-practices/issues/3191
// TODO: Remove this once the issue is fixed
if (!isMacOS()) {
t.true(
await confirmCursorIndex(t, ex.comboboxSelector, 0),
'Cursor should be at index 0 after one ARROW_HOME key'
);
}
t.is(
await combobox.getAttribute('aria-activedescendant'),
'',
'Focus should be on the combobox after one ARROW_HOME key'
);
}
);
ariaTest(
'End from focus on list puts focus on grid',
exampleFile,
'popup-key-end',
async (t) => {
// Send key "a" then key "ARROW_DOWN" to put the focus on the grid
const combobox = t.context.session.findElement(By.css(ex.comboboxSelector));
await combobox.sendKeys('a', Key.ARROW_DOWN);
// Send key "END_ARROW"
await combobox.sendKeys(Key.END);
t.true(
await confirmCursorIndex(t, ex.comboboxSelector, 1),
'Cursor should be at index 1 after one ARROW_END key'
);
t.is(
await combobox.getAttribute('aria-activedescendant'),
'',
'Focus should be on the combobox after on ARROW_END key'
);
}
);
ariaTest(
'Sending character keys while focus is on grid moves focus',
exampleFile,
'popup-key-char',
async (t) => {
// Send key "ARROW_DOWN" to put the focus on the grid
const combobox = t.context.session.findElement(By.css(ex.comboboxSelector));
await combobox.sendKeys(Key.ARROW_DOWN);
// Send key "a"
await combobox.sendKeys('a');
t.is(
await combobox.getAttribute('value'),
'a',
'Value of the combobox should be "a" after sending key "a" to the combobox while the focus ' +
'is on the grid'
);
t.is(
await combobox.getAttribute('aria-activedescendant'),
'',
'Focus should be on the combobox after sending a character key while the focus is on the grid'
);
}
);
ariaTest.failing(
'Expected behavior for all other standard single line editing keys',
exampleFile,
'standard-single-line-editing-keys',
async (t) => {
t.fail();
}
);