Skip to content

Commit cabdfee

Browse files
author
Valerie Young
committed
Add missing tests
1 parent d10a641 commit cabdfee

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

examples/combobox/combobox-select-only.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ <h3 id="kbd_label_combobox">Closed Combobox</h3>
128128
Opens the listbox and moves visual focus to the last option.
129129
</td>
130130
</tr>
131-
<tr data-test-id="standard-single-line-editing-keys">
131+
<tr data-test-id="printable-chars">
132132
<th>Printable Characters</th>
133133
<td>
134134
<ul>
@@ -240,7 +240,7 @@ <h3 id="kbd_label_listbox">Listbox Popup</h3>
240240
<th><kbd>PageDown</kbd></th>
241241
<td>Jumps visual focus down 10 options (or to last option).</td>
242242
</tr>
243-
<tr data-test-id="listbox-key-char">
243+
<tr data-test-id="printable-chars">
244244
<th>Printable Characters</th>
245245
<td>
246246
<ul>

test/tests/combobox_select-only.js

+43-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ariaTest('Alt + down arrow opens listbox', exampleFile, 'combobox-key-alt-down-a
9797
t.false(await listbox.isDisplayed(), 'Listbox should be hidden on load');
9898

9999
// Send ALT + ARROW_DOWN to the combo
100-
await combobox.sendKeys(Key.ALT, Key.ARROW_DOWN);
100+
await combobox.sendKeys(Key.chord(Key.ALT, Key.ARROW_DOWN));
101101

102102
// Check that the listbox is displayed
103103
t.true(await listbox.isDisplayed(), 'alt + down should show the listbox');
@@ -107,7 +107,27 @@ ariaTest('Alt + down arrow opens listbox', exampleFile, 'combobox-key-alt-down-a
107107
t.is(await combobox.getAttribute('aria-activedescendant'), firstOptionId, 'Alt + Down should highlight the first option');
108108
});
109109

110-
ariaTest('Down arrow opens listbox', exampleFile, 'combobox-key-down-arrow', async (t) => {
110+
ariaTest('Up arrow opens listbox', exampleFile, 'combobox-key-up-arrow', async (t) => {
111+
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
112+
const listbox = await t.context.session.findElement(By.css(ex.listboxSelector));
113+
const firstOptionId = await t.context.session.findElement(By.css(`${ex.listboxSelector} [role=option]`)).getAttribute('id');
114+
115+
// listbox starts collapsed
116+
t.false(await listbox.isDisplayed(), 'Listbox should be hidden on load');
117+
118+
// Send ARROW_UP to the combo
119+
await combobox.sendKeys(Key.ARROW_UP);
120+
121+
// Check that the listbox is displayed
122+
t.true(await listbox.isDisplayed(), 'arrow up should show the listbox');
123+
t.is(await combobox.getAttribute('aria-expanded'), 'true', 'aria-expanded should be true when opened');
124+
125+
// the first option should be selected
126+
t.is(await combobox.getAttribute('aria-activedescendant'), firstOptionId, 'arrow up should highlight the first option');
127+
});
128+
129+
130+
ariaTest(' arrow opens listbox', exampleFile, 'combobox-key-down-arrow', async (t) => {
111131
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
112132
const listbox = await t.context.session.findElement(By.css(ex.listboxSelector));
113133
const firstOptionId = await t.context.session.findElement(By.css(`${ex.listboxSelector} [role=option]`)).getAttribute('id');
@@ -215,7 +235,7 @@ ariaTest('End opens listbox to last option', exampleFile, 'combobox-key-end', as
215235
t.is(await combobox.getAttribute('aria-activedescendant'), lastOptionId, 'end should always highlight the last option');
216236
});
217237

218-
ariaTest('character keys open listbox to matching option', exampleFile, 'listbox-key-char', async (t) => {
238+
ariaTest('character keys open listbox to matching option', exampleFile, 'printable-chars', async (t) => {
219239
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
220240
const listbox = await t.context.session.findElement(By.css(ex.listboxSelector));
221241
const secondOptionId = await t.context.session.findElement(By.css(`${ex.listboxSelector} [role=option]:nth-child(2)`)).getAttribute('id');
@@ -291,6 +311,23 @@ ariaTest('Space closes listbox and selects option', exampleFile, 'listbox-key-sp
291311
t.is(await secondOption.getAttribute('aria-selected'), 'true', 'Second option has aria-selected set to true');
292312
});
293313

314+
ariaTest('Space closes listbox and selects option', exampleFile, 'listbox-key-alt-up-arrow', async (t) => {
315+
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
316+
const listbox = await t.context.session.findElement(By.css(ex.listboxSelector));
317+
const secondOption = await t.context.session.findElement(By.css(`${ex.listboxSelector} [role=option]:nth-child(2)`));
318+
319+
// Open, move to third option, send ALT+UP ARROW
320+
await combobox.sendKeys(Key.ENTER, Key.ARROW_DOWN);
321+
const secondOptionText = await secondOption.getText();
322+
await combobox.sendKeys(Key.chord(Key.ALT, Key.ARROW_UP));
323+
324+
// listbox is collapsed and the value is set to the third option
325+
t.false(await listbox.isDisplayed(), 'Listbox should be hidden');
326+
t.is(await combobox.getText(), secondOptionText, 'Combobox inner text should match the second option');
327+
t.is(await secondOption.getAttribute('aria-selected'), 'true', 'Second option has aria-selected set to true');
328+
});
329+
330+
294331
ariaTest('Escape closes listbox without selecting option', exampleFile, 'listbox-key-escape', async (t) => {
295332
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
296333
const listbox = await t.context.session.findElement(By.css(ex.listboxSelector));
@@ -450,7 +487,7 @@ ariaTest('PageUp moves up 10 options, and does not wrap', exampleFile, 'listbox-
450487
t.is(await combobox.getAttribute('aria-activedescendant'), optionId, 'aria-activedescendant points to the first option after second pageup');
451488
});
452489

453-
ariaTest('Multiple single-character presses cycle through options', exampleFile, 'listbox-key-char', async (t) => {
490+
ariaTest('Multiple single-character presses cycle through options', exampleFile, 'printable-chars', async (t) => {
454491
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
455492
const options = await t.context.queryElements(t, `${ex.listboxSelector} [role=option]`);
456493

@@ -484,7 +521,7 @@ ariaTest('Multiple single-character presses cycle through options', exampleFile,
484521
t.is(await combobox.getAttribute('aria-activedescendant'), `${matchingId}`, 'aria-activedescendant points to the second option beginning with "b"');
485522
});
486523

487-
ariaTest('Typing multiple characters refines search', exampleFile, 'listbox-key-char', async (t) => {
524+
ariaTest('Typing multiple characters refines search', exampleFile, 'printable-chars', async (t) => {
488525
const combobox = await t.context.session.findElement(By.css(ex.comboSelector));
489526
const options = await t.context.queryElements(t, `${ex.listboxSelector} [role=option]`);
490527

@@ -505,4 +542,4 @@ ariaTest('Typing multiple characters refines search', exampleFile, 'listbox-key-
505542

506543
// now fourth option should be highlighted
507544
t.is(await combobox.getAttribute('aria-activedescendant'), fourthId, 'The fourth option is highlighted after typing multiple letters');
508-
});
545+
});

0 commit comments

Comments
 (0)