From 733c67f19fbf5d5fb3eb2f68a863f805800e6d6d Mon Sep 17 00:00:00 2001 From: Valerie Young Date: Mon, 21 Dec 2020 16:08:27 -0800 Subject: [PATCH] issue 1619: add tests --- test/tests/combobox_autocomplete-list.js | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/test/tests/combobox_autocomplete-list.js b/test/tests/combobox_autocomplete-list.js index c79d5273d2..7cd1535ab0 100644 --- a/test/tests/combobox_autocomplete-list.js +++ b/test/tests/combobox_autocomplete-list.js @@ -14,6 +14,7 @@ const ex = { optionsSelector: '#ex1 [role="option"]', buttonSelector: '#ex1 button', numAOptions: 5, + exampleHeadingSelector: '.example-header', }; const waitForFocusChange = async (t, textboxSelector, originalFocus) => { @@ -850,6 +851,92 @@ ariaTest( } ); +ariaTest( + 'Clicking outside of textbox and listbox when focus is on listbox closes listbox', + exampleFile, + 'test-additional-behavior', + async (t) => { + // Send key "a" to open listbox then key "ARROW_DOWN" to put the focus on the listbox + await t.context.session + .findElement(By.css(ex.textboxSelector)) + .sendKeys('a', Key.ARROW_DOWN); + + // click outside the listbox + await t.context.session + .findElement(By.css(ex.exampleHeadingSelector)) + .click(); + + await t.context.session.wait( + async function () { + let listbox = await t.context.session.findElement( + By.css(ex.listboxSelector) + ); + return !(await listbox.isDisplayed()); + }, + t.context.waitTime, + 'Error waiting for listbox to close after outside click' + ); + + // Confirm the listbox is closed and the textboxed is cleared + await assertAttributeValues( + t, + ex.textboxSelector, + 'aria-expanded', + 'false' + ); + t.is( + await t.context.session + .findElement(By.css(ex.textboxSelector)) + .getAttribute('value'), + 'a', + 'Click outside of a textbox will close the testbox without selecting the highlighted value' + ); + } +); + +ariaTest( + 'Clicking outside of textbox and listbox when focus is on textbox closes listbox', + exampleFile, + 'test-additional-behavior', + async (t) => { + // Send key "a" to open listbox to put focus on textbox + await t.context.session + .findElement(By.css(ex.textboxSelector)) + .sendKeys('a'); + + // click outside the listbox + await t.context.session + .findElement(By.css(ex.exampleHeadingSelector)) + .click(); + + await t.context.session.wait( + async function () { + let listbox = await t.context.session.findElement( + By.css(ex.listboxSelector) + ); + return !(await listbox.isDisplayed()); + }, + t.context.waitTime, + 'Error waiting for listbox to close after outside click' + ); + + // Confirm the listbox is closed and the textboxed is cleared + await assertAttributeValues( + t, + ex.textboxSelector, + 'aria-expanded', + 'false' + ); + t.is( + await t.context.session + .findElement(By.css(ex.textboxSelector)) + .getAttribute('value'), + 'a', + 'Click outside of a textbox will close the testbox without selecting the highlighted value' + ); + } +); + ariaTest( 'left arrow from focus on list puts focus on listbox and moves cursor right', exampleFile,