-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathassertAriaLabelledby.js
51 lines (40 loc) · 1.5 KB
/
assertAriaLabelledby.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
'use strict';
const assert = require('assert');
/**
* Confirm the aria-labelledby element.
*
* @param {obj} t - ava execution object
* @param {String} elementSelector - the element with aria-labelledby set
*/
module.exports = async function assertAriaLabelledby (t, elementSelector) {
const elements = await t.context.queryElements(t, elementSelector);
for (let index = 0; index < elements.length; index++) {
const ariaLabelledbyExists = await t.context.session.executeScript(async function () {
const [selector, index] = arguments;
let els = document.querySelectorAll(selector);
return els[index].hasAttribute('aria-labelledby');
}, elementSelector, index);
assert(
ariaLabelledbyExists,
'"aria-labelledby" attribute should exist on element(s): ' + elementSelector
);
const labelValue = await elements[index].getAttribute('aria-labelledby');
assert.ok(
labelValue,
'"aria-labelledby" attribute should have a value on element(s): ' + elementSelector
);
const labelIds = labelValue.split(' ');
for (let labelId of labelIds) {
let labelText = await t.context.session.executeScript(async function () {
const id = arguments[0];
let el = document.querySelector('#' + id);
return el.innerText;
}, labelId);
assert.ok(
labelText,
'Element with id "' + labelId + '" should contain label text to describe element: ' + elementSelector
);
}
}
t.pass();
};