-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathATTAcomm.js
51 lines (44 loc) · 1.22 KB
/
ATTAcomm.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
const implementation = "ATK";
const descriptionPropertyName = {
ATK: "description",
};
const namePropertyName = {
ATK: "name",
};
/**
* Shim of wpt/wai-aria/scripts/ATTAcomm or rather
* a minimal implementation of https://spec-ops.github.io/atta-api/
* to pass wpt/accname
*/
class ATTAcomm {
constructor({ steps, title }) {
test(() => {
const element = document.getElementById("test");
for (const step of steps) {
const { test } = step;
const assertions = test[implementation];
for (const assertion of assertions) {
const [matcher, name, equality, expected] = assertion;
if (matcher === "property") {
if (name === namePropertyName[implementation]) {
const actual = computeAccessibleName(element) ?? "";
if (equality === "is") {
assert_equals(actual, expected);
continue;
}
} else if (name === descriptionPropertyName[implementation]) {
const actual = computeAccessibleDescription(element) ?? "";
if (equality === "is") {
assert_equals(actual, expected);
continue;
}
}
}
throw new Error(`Don't know how to handle this assertion`);
}
}
done();
}, title);
}
}
window.ATTAcomm = ATTAcomm;