forked from A11yance/aria-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelementRoleMap-test.js
253 lines (250 loc) · 12.3 KB
/
elementRoleMap-test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import expect from 'expect';
import elementRoleMap from '../../src/elementRoleMap';
const entriesList = [
[{"name": "article"}, ["article"]],
[{"constraints": ["scoped to the body element"], "name": "header"}, ["banner"]],
[{"name": "blockquote"}, ["blockquote"]],
[{"attributes": [{"name": "type", "value": "button"}], "name": "input"}, ["button"]],
[{"attributes": [{"name": "type", "value": "image"}], "name": "input"}, ["button"]],
[{"attributes": [{"name": "type", "value": "reset"}], "name": "input"}, ["button"]],
[{"attributes": [{"name": "type", "value": "submit"}], "name": "input"}, ["button"]],
[{"name": "button"}, ["button"]],
[{"name": "caption"}, ["caption"]],
[{"constraints": ["ancestor table element has table role"], "name": "td"}, ["cell"]],
[{"attributes": [{"name": "type", "value": "checkbox"}], "name": "input"}, ["checkbox"]],
[{"name": "code"}, ["code"]],
[{"name": "th"}, ["columnheader"]],
[{"attributes": [{"name": "scope", "value": "col"}], "name": "th"}, ["columnheader"]],
[{"attributes": [{"name": "scope", "value": "colgroup"}], "name": "th"}, ["columnheader"]],
[{"attributes": [{"constraints": ["set"], "name": "list"}, {"name": "type", "value": "email"}], "name": "input"}, ["combobox"]],
[{"attributes": [{"constraints": ["set"], "name": "list"}, {"name": "type", "value": "search"}], "name": "input"}, ["combobox"]],
[{"attributes": [{"constraints": ["set"], "name": "list"}, {"name": "type", "value": "tel"}], "name": "input"}, ["combobox"]],
[{"attributes": [{"constraints": ["set"], "name": "list"}, {"name": "type", "value": "text"}], "name": "input"}, ["combobox"]],
[{"attributes": [{"constraints": ["set"], "name": "list"}, {"name": "type", "value": "url"}], "name": "input"}, ["combobox"]],
[{"attributes": [{"constraints": ["undefined"], "name": "multiple"}, {"constraints": ["undefined"], "name": "size"}], "constraints": ["the multiple attribute is not set and the size attribute does not have a value greater than 1"], "name": "select"}, ["combobox"]],
[{"constraints": ["scoped to the body element", "scoped to the main element"], "name": "aside"}, ["complementary"]],
[{"attributes": [{"constraints": ["set"], "name": "aria-label"}], "constraints": ["scoped to a sectioning content element", "scoped to a sectioning root element other than body"], "name": "aside"}, ["complementary"]],
[{"attributes": [{"constraints": ["set"], "name": "aria-labelledby"}], "constraints": ["scoped to a sectioning content element", "scoped to a sectioning root element other than body"], "name": "aside"}, ["complementary"]],
[{"constraints": ["scoped to the body element"], "name": "footer"}, ["contentinfo"]],
[{"name": "dd"}, ["definition"]],
[{"name": "del"}, ["deletion"]],
[{"name": "dialog"}, ["dialog"]],
[{"name": "em"}, ["emphasis"]],
[{"name": "html"}, ["document"]],
[{"name": "figure"}, ["figure"]],
[{"attributes": [{"constraints": ["set"], "name": "aria-label"}], "name": "form"}, ["form"]],
[{"attributes": [{"constraints": ["set"], "name": "aria-labelledby"}], "name": "form"}, ["form"]],
[{"attributes": [{"constraints": ["set"], "name": "name"}], "name": "form"}, ["form"]],
[{"name": "a"}, ["generic"]],
[{"name": "area"}, ["generic"]],
[{"name": "aside"}, ["generic"]],
[{"name": "b"}, ["generic"]],
[{"name": "bdo"}, ["generic"]],
[{"name": "body"}, ["generic"]],
[{"name": "data"}, ["generic"]],
[{"name": "div"}, ["generic"]],
[{"constraints": ["scoped to the main element", "scoped to a sectioning content element", "scoped to a sectioning root element other than body"], "name": "footer"}, ["generic"]],
[{"constraints": ["scoped to the main element", "scoped to a sectioning content element", "scoped to a sectioning root element other than body"], "name": "header"}, ["generic"]],
[{"name": "hgroup"}, ["generic"]],
[{"name": "i"}, ["generic"]],
[{"name": "pre"}, ["generic"]],
[{"name": "q"}, ["generic"]],
[{"name": "samp"}, ["generic"]],
[{"name": "section"}, ["generic"]],
[{"name": "small"}, ["generic"]],
[{"name": "span"}, ["generic"]],
[{"name": "u"}, ["generic"]],
[{"constraints": ["ancestor table element has grid role", "ancestor table element has treegrid role"], "name": "td"}, ["gridcell"]],
[{"name": "details"}, ["group"]],
[{"name": "fieldset"}, ["group"]],
[{"name": "optgroup"}, ["group"]],
[{"name": "address"}, ["group"]],
[{"name": "h1"}, ["heading"]],
[{"name": "h2"}, ["heading"]],
[{"name": "h3"}, ["heading"]],
[{"name": "h4"}, ["heading"]],
[{"name": "h5"}, ["heading"]],
[{"name": "h6"}, ["heading"]],
[{"attributes": [{"constraints": ["set"], "name": "alt"}], "name": "img"}, ["img"]],
[{"attributes": [{"constraints": ["undefined"], "name": "alt"}], "name": "img"}, ["img"]],
[{"name": "ins"}, ["insertion"]],
[{"attributes": [{"constraints": ["set"], "name": "href"}], "name": "a"}, ["link"]],
[{"attributes": [{"constraints": ["set"], "name": "href"}], "name": "area"}, ["link"]],
[{"name": "menu"}, ["list"]],
[{"name": "ol"}, ["list"]],
[{"name": "ul"}, ["list"]],
[{"attributes": [{"constraints": [">1"], "name": "size"}], "constraints": ["the size attribute value is greater than 1"], "name": "select"}, ["listbox"]],
[{"attributes": [{"name": "multiple"}], "name": "select"}, ["listbox"]],
[{"name": "datalist"}, ["listbox"]],
[{"attributes": [{"name": "aria-multiselectable", "value": "false"}], "name": "datalist"}, ["listbox"]],
[{"constraints": ["direct descendant of ol", "direct descendant of ul", "direct descendant of menu"], "name": "li"}, ["listitem"]],
[{"name": "main"}, ["main"]],
[{"name": "mark"}, ["mark"]],
[{"name": "math"}, ["math"]],
[{"name": "meter"}, ["meter"]],
[{"name": "nav"}, ["navigation"]],
[{"name": "option"}, ["option"]],
[{"name": "p"}, ["paragraph"]],
[{"attributes": [{"name": "alt", "value": ""}], "name": "img"}, ["presentation"]],
[{"name": "progress"}, ["progressbar"]],
[{"attributes": [{"name": "aria-valuemax"}, {"name": "aria-valuemin", "value": 0}, {"name": "aria-valuenow"}], "constraints": ["the progress bar is determinate"],"name": "progress"}, ["progressbar"]],
[{"attributes": [{"name": "type", "value": "radio"}], "name": "input"}, ["radio"]],
[{"attributes": [{"constraints": ["set"], "name": "aria-label"}], "name": "section"}, ["region"]],
[{"attributes": [{"constraints": ["set"], "name": "aria-labelledby"}], "name": "section"}, ["region"]],
[{"name": "tr"}, ["row"]],
[{"name": "tbody"}, ["rowgroup"]],
[{"constraints": ["ancestor table element has table role"], "name": "td"}, ["cell"]],
[{"name": "tfoot"}, ["rowgroup"]],
[{"name": "thead"}, ["rowgroup"]],
[{"attributes": [{"name": "scope", "value": "row"}], "name": "th"}, ["rowheader"]],
[{"attributes": [{"name": "scope", "value": "rowgroup"}], "name": "th"}, ["rowheader"]],
[{"attributes": [{"constraints": ["undefined"], "name": "list"}, {"name": "type", "value": "search"}], "constraints": ["the list attribute is not set"], "name": "input"}, ["searchbox"]],
[{"attributes": [{"name": "aria-label"}], "name": "section"}, ["section"]],
[{"attributes": [{"name": "aria-labelledby"}], "name": "section"}, ["section"]],
[{"name": "hr"}, ["separator"]],
[{"attributes": [{"name": "type", "value": "range"}], "name": "input"}, ["slider"]],
[{"attributes": [{"name": "type", "value": "number"}], "name": "input"}, ["spinbutton"]],
[{"name": "output"}, ["status"]],
[{"name": "strong"}, ["strong"]],
[{"name": "sub"}, ["subscript"]],
[{"name": "sup"}, ["superscript"]],
[{"attributes": [{"name": "aria-checked"}], "name": "button"}, ["switch"]],
[{"name": "table"}, ["table"]],
[{"name": "dfn"}, ["term"]],
[{"name": "dt"}, ["term"]],
[{"attributes": [{"constraints": ["undefined"], "name": "type"}, {"constraints": ["undefined"], "name": "list"}], "constraints": ["the list attribute is not set"], "name": "input"}, ["textbox"]],
[{"attributes": [{"constraints": ["undefined"], "name": "list"}, {"name": "type", "value": "email"}], "constraints": ["the list attribute is not set"], "name": "input"}, ["textbox"]],
[{"attributes": [{"constraints": ["undefined"], "name": "list"}, {"name": "type", "value": "tel"}], "constraints": ["the list attribute is not set"], "name": "input"}, ["textbox"]],
[{"attributes": [{"constraints": ["undefined"], "name": "list"}, {"name": "type", "value": "text"}], "constraints": ["the list attribute is not set"], "name": "input"}, ["textbox"]],
[{"attributes": [{"constraints": ["undefined"], "name": "list"}, {"name": "type", "value": "url"}], "constraints": ["the list attribute is not set"], "name": "input"}, ["textbox"]],
[{"name": "textarea"}, ["textbox"]],
[{"name": "time"}, ["time"]],
];
describe('elementRoleMap API', function () {
describe('entries()', function () {
test.each(elementRoleMap.entries())('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
expect.arrayContaining([[obj, roles]]),
);
});
test.each([...elementRoleMap.entries()])('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
expect.arrayContaining([[obj, roles]]),
);
});
});
describe('forEach()', function () {
const output = [];
let context;
elementRoleMap.forEach((value, key, map) => {
output.push([key, value]);
if (!context) {
context = map;
}
});
test.each(output)('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
expect.arrayContaining([[obj, roles]]),
);
});
test.each(context)('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
expect.arrayContaining([[obj, roles]]),
);
});
});
it('get()', function () {
expect(elementRoleMap.get({
attributes: [
{ constraints: ["set"], name: 'href' }
],
name: 'a'
})).toEqual(
expect.arrayContaining(["link"]),
);
expect(elementRoleMap.get({
"attributes": [
{
"name": "type",
"value": "radio"
}
], "name": "input"
})).toEqual(
expect.arrayContaining(["radio"]),
);
expect(elementRoleMap.get({
attributes: {
name: 'fake attribute',
},
name: 'fake element',
})).toBeUndefined();
});
it('has()', function () {
expect(elementRoleMap.has({
attributes: [
{ constraints: ["set"], name: 'href' }
],
name: 'a'
})).toEqual(true);
expect(elementRoleMap.has({
attributes: {
name: 'fake attribute',
},
name: 'fake element',
})).toEqual(false);
});
describe('keys()', function () {
const entriesKeys = entriesList.map(entry => entry[0]);
test.each(elementRoleMap.keys())('Testing key: %o', (key) => {
expect(entriesKeys).toEqual(
expect.arrayContaining([key]),
);
});
test.each([...elementRoleMap.keys()])('Testing key: %o', (key) => {
expect(entriesKeys).toEqual(
expect.arrayContaining([key]),
);
});
});
describe('values()', function () {
const entriesValues = entriesList.map(entry => entry[1]);
test.each(elementRoleMap.values().map(value => [value]))('Testing value: %o', (value) => {
expect(entriesValues).toEqual(
expect.arrayContaining([value]),
);
});
test.each([...elementRoleMap.values()].map(value => [value]))('Testing value: %o', (value) => {
expect(entriesValues).toEqual(
expect.arrayContaining([value]),
);
});
});
});
describe('elementRolesMap', function () {
describe('iteration', function () {
it('should have an iterator defined', function () {
expect(elementRoleMap[Symbol.iterator]).not.toBeUndefined();
});
describe('spread operator', function () {
it('should have a specific length', function () {
expect([...elementRoleMap].length).toEqual(113);
});
test.each([...elementRoleMap])('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
expect.arrayContaining([[obj, roles]]),
);
});
});
describe('for..of pattern', function () {
const output = [];
for (const [key, value] of elementRoleMap) {
output.push([key, value]);
}
test.each(output)('Testing element: %o', (obj, roles) => {
expect(entriesList).toEqual(
expect.arrayContaining([[obj, roles]]),
);
});
});
});
});