Skip to content

Commit

Permalink
Add a lint check for findElements and exclude current uses
Browse files Browse the repository at this point in the history
  • Loading branch information
zcorpan authored and mcking65 committed Mar 9, 2020
1 parent 553e545 commit a16af28
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 123 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
},
"rules": {
"no-unused-vars": 0,
"no-undef": 0
"no-undef": 0,
"no-restricted-properties": [2, {
"property": "findElements",
"message": "Please use t.context.queryElements()."
}]
}
}
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint no-restricted-properties: 0 */

'use strict';

const path = require('path');
Expand Down
8 changes: 4 additions & 4 deletions test/tests/checkbox_checkbox-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const uncheckAllSelectedByDefault = async function (t) {
// Attributes

ariaTest('element h3 exists', exampleFile, 'h3', async (t) => {

let header = await t.context.queryElements(t, '#ex1 h3');

t.is(
Expand Down Expand Up @@ -101,7 +101,7 @@ ariaTest('tabindex="0" for checkbox elements', exampleFile, 'checkbox-tabindex',
});

ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-checked', async (t) => {

await uncheckAllSelectedByDefault(t);

// check the aria-checked attribute is false to begin
Expand Down Expand Up @@ -134,12 +134,12 @@ ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-check
});

ariaTest('key TAB moves focus between checkboxes', exampleFile, 'key-tab', async (t) => {

await assertTabOrder(t, ex.checkboxes);
});

ariaTest('key SPACE selects or unselects checkbox', exampleFile, 'key-space', async (t) => {

await uncheckAllSelectedByDefault(t);

for (let checkboxSelector of ex.checkboxes) {
Expand Down
14 changes: 8 additions & 6 deletions test/tests/checkbox_checkbox-2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint no-restricted-properties: 0 */

'use strict';

const { ariaTest } = require('..');
Expand Down Expand Up @@ -40,7 +42,7 @@ ariaTest('"tabindex" on checkbox element', exampleFile, 'checkbox-tabindex', asy
});

ariaTest('"aria-controls" ', exampleFile, 'checkbox-aria-controls', async (t) => {

const checkbox = await t.context.session.findElement(By.css(ex.checkboxSelector));
const controls = (await checkbox.getAttribute('aria-controls')).split(' ');

Expand All @@ -60,7 +62,7 @@ ariaTest('"aria-controls" ', exampleFile, 'checkbox-aria-controls', async (t) =>
});

ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-checked-false', async (t) => {

await uncheckAllConds(t);
let checkbox = t.context.session.findElement(By.css(ex.checkboxSelector));

Expand Down Expand Up @@ -90,7 +92,7 @@ ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-check
});

ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-checked-mixed', async (t) => {

await uncheckAllConds(t);
let checkbox = t.context.session.findElement(By.css(ex.checkboxSelector));

Expand Down Expand Up @@ -124,7 +126,7 @@ ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-check
});

ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-checked-true', async (t) => {

await uncheckAllConds(t);
let checkbox = t.context.session.findElement(By.css(ex.checkboxSelector));

Expand Down Expand Up @@ -159,12 +161,12 @@ ariaTest('"aria-checked" on checkbox element', exampleFile, 'checkbox-aria-check
});

ariaTest('key TAB moves focus between checkboxes', exampleFile, 'key-tab', async (t) => {

await assertTabOrder(t, ex.allCheckboxes);
});

ariaTest('key SPACE selects or unselects checkbox', exampleFile, 'key-space', async (t) => {

// Check one box
await uncheckAllConds(t);
const condiments = await t.context.queryElements(t, ex.condimentsSelector);
Expand Down
42 changes: 22 additions & 20 deletions test/tests/combobox_autocomplete-both.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint no-restricted-properties: 0 */

'use strict';

const { ariaTest } = require('..');
Expand Down Expand Up @@ -48,7 +50,7 @@ ariaTest('"aria-autocomplete" on comboxbox element', exampleFile, 'combobox-aria
});

ariaTest('"aria-controls" attribute on combobox element', exampleFile, 'combobox-aria-controls', async (t) => {

const popupId = await t.context.session
.findElement(By.css(ex.textboxSelector))
.getAttribute('aria-controls');
Expand All @@ -70,7 +72,7 @@ ariaTest('"aria-controls" attribute on combobox element', exampleFile, 'combobox
});

ariaTest('"aria-expanded" on combobox element', exampleFile, 'combobox-aria-expanded', async (t) => {

const combobox = await t.context.session.findElement(By.css(ex.textboxSelector));

// Check that aria-expanded is false and the listbox is not visible before interacting
Expand Down Expand Up @@ -128,14 +130,14 @@ ariaTest('"aria-label" attribute on listbox element', exampleFile, 'listbox-aria
});

ariaTest('role "option" on lu elements', exampleFile, 'option-role', async (t) => {

// Send arrow down to reveal all options
await t.context.session.findElement(By.css(ex.textboxSelector)).sendKeys(Key.ARROW_DOWN);
await assertAriaRoles(t, 'ex1', 'option', '56', 'li');
});

ariaTest('"aria-selected" attribute on options element', exampleFile, 'option-aria-selected', async (t) => {

// Send key "a"
await t.context.session.findElement(By.css(ex.textboxSelector)).sendKeys('a');
await assertAttributeValues(t, ex.optionsSelector + ':nth-of-type(1)', 'aria-selected', 'true');
Expand Down Expand Up @@ -234,7 +236,7 @@ ariaTest('"aria-expanded" on button element', exampleFile, 'button-aria-expanded
ariaTest('Test alt + down key press with focus on textbox',
exampleFile, 'textbox-key-alt-down-arrow', async (t) => {


// Send ARROW_DOWN to the textbox
await t.context.session
.findElement(By.css(ex.textboxSelector))
Expand All @@ -254,7 +256,7 @@ ariaTest('Test alt + down key press with focus on textbox',
ariaTest('Test down key press with focus on textbox',
exampleFile, 'textbox-key-down-arrow', async (t) => {


// Send ARROW_DOWN to the textbox
await t.context.session
.findElement(By.css(ex.textboxSelector))
Expand All @@ -278,7 +280,7 @@ ariaTest('Test down key press with focus on textbox',
ariaTest('Test down key press with focus on list',
exampleFile, 'listbox-key-down-arrow', async (t) => {


// Send 'a' to text box, then send ARROW_DOWN to textbox to set focus on listbox
await t.context.session
.findElement(By.css(ex.textboxSelector))
Expand Down Expand Up @@ -306,7 +308,7 @@ ariaTest('Test down key press with focus on list',
ariaTest('Test up key press with focus on textbox',
exampleFile, 'textbox-key-up-arrow', async (t) => {


// Send ARROW_UP to the textbox
await t.context.session
.findElement(By.css(ex.textboxSelector))
Expand All @@ -330,7 +332,7 @@ ariaTest('Test up key press with focus on textbox',
ariaTest('Test up key press with focus on listbox',
exampleFile, 'listbox-key-up-arrow', async (t) => {


// Send 'a' to text box, then send ARROW_UP to textbox to textbox to put focus in textbox
// Up arrow should move selection to the last item in the list
await t.context.session
Expand Down Expand Up @@ -363,7 +365,7 @@ ariaTest('Test up key press with focus on listbox',
ariaTest('Test enter key press with focus on textbox',
exampleFile, 'textbox-key-enter', async (t) => {


// Send key "a" to the textbox

await t.context.session
Expand Down Expand Up @@ -398,7 +400,7 @@ ariaTest('Test enter key press with focus on textbox',
ariaTest('Test enter key press with focus on listbox',
exampleFile, 'listbox-key-enter', async (t) => {


// Send key "a" to the textbox, then two ARROW_DOWNS

await t.context.session
Expand Down Expand Up @@ -435,7 +437,7 @@ ariaTest('Test enter key press with focus on listbox',

ariaTest('Test single escape key press with focus on textbox',
exampleFile, 'textbox-key-escape', async (t) => {

// Send key "a", then key ESCAPE once to the textbox

await t.context.session
Expand All @@ -457,7 +459,7 @@ ariaTest('Test single escape key press with focus on textbox',

ariaTest('Test double escape key press with focus on textbox',
exampleFile, 'textbox-key-escape', async (t) => {

// Send key "a", then key ESCAPE twice to the textbox

await t.context.session
Expand All @@ -479,7 +481,7 @@ ariaTest('Test double escape key press with focus on textbox',

ariaTest('Test escape key press with focus on textbox',
exampleFile, 'listbox-key-escape', async (t) => {

// Send key "a" then key "ARROW_DOWN to put the focus on the listbox,
// then key ESCAPE to the textbox

Expand All @@ -502,7 +504,7 @@ ariaTest('Test escape key press with focus on textbox',

ariaTest('left arrow from focus on list puts focus on listbox and moves cursor right',
exampleFile, 'listbox-key-left-arrow', async (t) => {

// Send key "a" then key "ARROW_DOWN" to put the focus on the listbox
const textbox = await t.context.session.findElement(By.css(ex.textboxSelector));
await textbox.sendKeys('a', Key.ARROW_DOWN);
Expand All @@ -525,7 +527,7 @@ ariaTest('left arrow from focus on list puts focus on listbox and moves cursor r

ariaTest('Right arrow from focus on list puts focus on listbox',
exampleFile, 'listbox-key-right-arrow', async (t) => {

// Send key "a" then key "ARROW_DOWN" to put the focus on the listbox
const textbox = await t.context.session.findElement(By.css(ex.textboxSelector));
await textbox.sendKeys('a', Key.ARROW_DOWN);
Expand All @@ -547,7 +549,7 @@ ariaTest('Right arrow from focus on list puts focus on listbox',

ariaTest('Home from focus on list puts focus on listbox and moves cursor',
exampleFile, 'listbox-key-home', async (t) => {

// Send key "a" then key "ARROW_DOWN" to put the focus on the listbox
const textbox = await t.context.session.findElement(By.css(ex.textboxSelector));
await textbox.sendKeys('a', Key.ARROW_DOWN);
Expand All @@ -569,7 +571,7 @@ ariaTest('Home from focus on list puts focus on listbox and moves cursor',

ariaTest('End from focus on list puts focus on listbox',
exampleFile, 'listbox-key-end', async (t) => {

// Send key "a" then key "ARROW_DOWN" to put the focus on the listbox
const textbox = await t.context.session.findElement(By.css(ex.textboxSelector));
await textbox.sendKeys('a', Key.ARROW_DOWN);
Expand All @@ -591,7 +593,7 @@ ariaTest('End from focus on list puts focus on listbox',

ariaTest('Sending character keys while focus is on listbox moves focus',
exampleFile, 'listbox-characters', async (t) => {

// Send key "ARROW_DOWN" to put the focus on the listbox
const textbox = await t.context.session.findElement(By.css(ex.textboxSelector));
await textbox.sendKeys(Key.ARROW_DOWN);
Expand Down Expand Up @@ -619,7 +621,7 @@ ariaTest('Sending character keys while focus is on listbox moves focus',

ariaTest('Expected behavior for all other standard single line editing keys',
exampleFile, 'standard-single-line-editing-keys', async (t) => {

// Send key "a"
const textbox = await t.context.session.findElement(By.css(ex.textboxSelector));
await textbox.sendKeys('a');
Expand Down
Loading

0 comments on commit a16af28

Please sign in to comment.