Skip to content

Commit

Permalink
Infrastructure: Add missing test for 6 examples (pull #1424)
Browse files Browse the repository at this point in the history
Closes #1378 by adding missing regression tests for the following examples:
button_button-idl.js
combobox_autocomplete-both.js
combobox_autocomplete-list.js
combobox_autocomplete-none.js
combobox_grid-combo.js
spinbutton_datepicker.js
  • Loading branch information
spectranaut authored Nov 8, 2020
1 parent a36649a commit 1b2ae58
Show file tree
Hide file tree
Showing 7 changed files with 797 additions and 2 deletions.
168 changes: 168 additions & 0 deletions test/tests/button_button-idl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');

const exampleFile = 'button/button_idl.html';
const assertDotValue = require('../util/assertDotValue');
const assertAttributeValues = require('../util/assertAttributeValues');

const ex = {
printSelector: '#action',
toggleSelector: '#toggle',
svgSelector: '#example svg',
};

// Attributes

ariaTest(
'Example elements should have role="button" set',
exampleFile,
'button-role',
async (t) => {
await assertDotValue(t, ex.printSelector, 'role', 'button');
await assertDotValue(t, ex.toggleSelector, 'role', 'button');
}
);

ariaTest(
'Button examples should have tabindex="0"',
exampleFile,
'button-tabindex',
async (t) => {
let printEl = await t.context.session.findElement(By.css(ex.printSelector));

t.is(
await printEl.getAttribute('tabindex'),
'0',
'tabindex should be set to "0" on button example: ' + ex.printSelector
);

let toggleEl = await t.context.session.findElement(
By.css(ex.toggleSelector)
);

t.is(
await toggleEl.getAttribute('tabindex'),
'0',
'tabindex should be set to "0" on button example: ' + ex.toggleSelector
);
}
);

ariaTest(
'"aria-pressed" reflects button state',
exampleFile,
'button-aria-pressed',
async (t) => {
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'false');
let toggleButtonEl = await t.context.session.findElement(
By.css(ex.toggleSelector)
);
await toggleButtonEl.click();
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'true');
await toggleButtonEl.click();
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'false');
}
);

ariaTest(
'"aria-hidden" set on SVG',
exampleFile,
'svg-aria-hidden',
async (t) => {
await assertAttributeValues(t, ex.svgSelector, 'aria-hidden', 'true');
}
);

ariaTest('key ENTER activates button', exampleFile, 'key-enter', async (t) => {
let toggleButtonEl = await t.context.session.findElement(
By.css(ex.toggleSelector)
);

// Send ENTER and wait for change of 'aria-pressed'
await toggleButtonEl.sendKeys(Key.ENTER);
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'true');
await toggleButtonEl.sendKeys(Key.ENTER);
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'false');

let actionButtonEl = await t.context.session.findElement(
By.css(ex.printSelector)
);
let oldText = await actionButtonEl.getText();
let newText = oldText + ' - Printed!';

await t.context.session.executeScript(
function () {
let [selector, newText] = arguments;
window.print = function () {
document.querySelector(selector).innerText = newText;
};
},
ex.printSelector,
newText
);

// Send ENTER and wait for change of 'aria-pressed'
await actionButtonEl.sendKeys(Key.ENTER);

await t.context.session.wait(
async function () {
return actionButtonEl.getText('') !== oldText;
},
t.context.waitTime,
'window.print was not executed'
);

t.is(
await actionButtonEl.getText(),
newText,
'window.print should have been triggered after sending ENTER to example: ' +
ex.printSelector
);
});

ariaTest('key SPACE activates button', exampleFile, 'key-space', async (t) => {
let toggleButtonEl = await t.context.session.findElement(
By.css(ex.toggleSelector)
);

// Send SPACE and wait for change of 'aria-pressed'
await toggleButtonEl.sendKeys(Key.SPACE);
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'true');
await toggleButtonEl.sendKeys(Key.SPACE);
await assertDotValue(t, ex.toggleSelector, 'ariaPressed', 'false');

let actionButtonEl = await t.context.session.findElement(
By.css(ex.printSelector)
);
let oldText = await actionButtonEl.getText();
let newText = oldText + ' - Printed!';

await t.context.session.executeScript(
function () {
let [selector, newText] = arguments;
window.print = function () {
document.querySelector(selector).innerText = newText;
};
},
ex.printSelector,
newText
);

// Send SPACE and wait for change of 'aria-pressed'
await actionButtonEl.sendKeys(Key.SPACE);

await t.context.session.wait(
async function () {
return actionButtonEl.getText('') !== oldText;
},
t.context.waitTime,
'window.print was not executed'
);

t.is(
await actionButtonEl.getText(),
newText,
'window.print should have been triggered after sending SPACE to example: ' +
ex.printSelector
);
});
22 changes: 22 additions & 0 deletions test/tests/combobox_autocomplete-both.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ ariaTest(
}
);

ariaTest(
'"id" attribute on combobox element',
exampleFile,
'combobox-id',
async (t) => {
const combobox = await t.context.session.findElement(
By.css(ex.textboxSelector)
);
const id = await combobox.getAttribute('id');

console.log(id);
t.truthy(id, '"id" attribute should exist on combobox');

const label = await t.context.queryElements(t, `[for="${id}"]`);
t.is(
label.length,
1,
`There should be one element that labels the combobox with: [for="${id}"]`
);
}
);

ariaTest(
'role "listbox" on ul element',
exampleFile,
Expand Down
22 changes: 22 additions & 0 deletions test/tests/combobox_autocomplete-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ ariaTest(
}
);

ariaTest(
'"id" attribute on combobox element',
exampleFile,
'combobox-id',
async (t) => {
const combobox = await t.context.session.findElement(
By.css(ex.textboxSelector)
);
const id = await combobox.getAttribute('id');

console.log(id);
t.truthy(id, '"id" attribute should exist on combobox');

const label = await t.context.queryElements(t, `[for="${id}"]`);
t.is(
label.length,
1,
`There should be one element that labels the combobox with: [for="${id}"]`
);
}
);

ariaTest(
'role "listbox" on ul element',
exampleFile,
Expand Down
22 changes: 22 additions & 0 deletions test/tests/combobox_autocomplete-none.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ ariaTest(
}
);

ariaTest(
'"id" attribute on combobox element',
exampleFile,
'combobox-id',
async (t) => {
const combobox = await t.context.session.findElement(
By.css(ex.textboxSelector)
);
const id = await combobox.getAttribute('id');

console.log(id);
t.truthy(id, '"id" attribute should exist on combobox');

const label = await t.context.queryElements(t, `[for="${id}"]`);
t.is(
label.length,
1,
`There should be one element that labels the combobox with: [for="${id}"]`
);
}
);

ariaTest(
'"aria-label" attribute on listbox element',
exampleFile,
Expand Down
4 changes: 2 additions & 2 deletions test/tests/combobox_grid-combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ ariaTest(
ariaTest(
'Test down key press with focus on combobox',
exampleFile,
'popup-key-down-arrow',
'textbox-key-down-arrow',
async (t) => {
// Send ARROW_DOWN to the combobox
await t.context.session
Expand Down Expand Up @@ -433,7 +433,7 @@ ariaTest(
ariaTest(
'Test up key press with focus on combobox',
exampleFile,
'popup-key-up-arrow',
'textbox-key-up-arrow',
async (t) => {
// Send ARROW_UP to the combobox
await t.context.session
Expand Down
Loading

0 comments on commit 1b2ae58

Please sign in to comment.