This repository was archived by the owner on Dec 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathunsupported-aria-attribute-test.js
More file actions
253 lines (223 loc) · 9.77 KB
/
unsupported-aria-attribute-test.js
File metadata and controls
253 lines (223 loc) · 9.77 KB
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
// Copyright 2014 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
(function() {
module('UnupportedAriaAttribute');
var RULE_NAME = 'unsupportedAriaAttribute';
test('Element with role and global, supported and required attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-hidden', 'false'); // global
widget.setAttribute('aria-required', 'true'); // supported
widget.setAttribute('aria-valuemax', '79'); // required
widget.setAttribute('aria-valuemin', '10'); // required
widget.setAttribute('aria-valuenow', '50'); // required
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
test('Element with role and supported attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'tablist');
widget.setAttribute('aria-multiselectable', 'true'); // supported
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
test('Element with no role and global attributes only', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var div = fixture.appendChild(document.createElement('div'));
div.setAttribute('aria-hidden', 'false'); // global
div.setAttribute('aria-label', 'bananas'); // global
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
/*
* This rule shouldn't care if required and/or supported roles are missing.
*/
test('Element with role and global but missing supported and required attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-hidden', 'false'); // global (so the audit will encounter this element)
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
test('Element with role and known but unsupported attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'group');
widget.setAttribute('aria-required', 'true'); // unsupported
widget.setAttribute('aria-valuemax', '79'); // unsupported
widget.setAttribute('aria-valuemin', '10'); // unsupported
widget.setAttribute('aria-valuenow', '50'); // unsupported
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.FAIL,
elements: [widget]
};
assert.runRule(config);
});
/*
* This rule shouldn't care if we put ARIA attributes on elements that shouldn't have them.
*/
test('Element with role and global but missing supported and required attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('meta')); // note, a reserved HTML element
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-hidden', 'false'); // global (so the audit will encounter this element)
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
/*
* This test shouldn't care if there are unknown aria- attributes.
*/
test('Element with a role and unknown aria- attribute', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-labeledby', 'false'); // unknown
widget.setAttribute('aria-hidden', 'false'); // global
widget.setAttribute('aria-required', 'true'); // supported
widget.setAttribute('aria-valuemax', '79'); // required
widget.setAttribute('aria-valuemin', '10'); // required
widget.setAttribute('aria-valuenow', '50'); // required
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
/*
* This rule definitely needs to visit elements with no role attribute.
*/
test('Element with no role and unknown aria- attribute', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('aria-required', 'true'); // unsupported
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.FAIL,
elements: [widget]
};
assert.runRule(config);
});
/*
* This rule can ignore elements with no aria- attributes.
*/
test('Element with role but no aria- attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.NA
};
assert.runRule(config);
});
/*
* This rule can ignore elements with only unknown aria- attributes.
*/
test('Element with role but no aria- attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-cucumber', 'true'); // unknown
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.NA
};
assert.runRule(config);
});
test('Element with no role and some global, some unsupported aria- attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('aria-busy', 'false'); // global
widget.setAttribute('aria-hidden', 'false'); // global
widget.setAttribute('aria-posinset', '10'); // unsupported
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.FAIL,
elements: [widget]
};
assert.runRule(config);
});
test('Element with no role and global aria- attributes', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.type = "text";
widget.setAttribute('aria-label', 'This is my label'); // global
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config);
});
test('Input with no type attribute with no role and aria-required', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.setAttribute('aria-required', 'true');
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config, 'An input with no type is a textbox');
});
test('Input with type=text attribute with no role and aria-required', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.setAttribute('type', 'text');
widget.setAttribute('aria-required', 'true');
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config, 'A text input is a textbox');
});
test('Input with type=text property with no role and aria-required', function(assert) {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.type = 'text';
widget.setAttribute('aria-required', 'true');
var config = {
ruleName: RULE_NAME,
expected: axs.constants.AuditResult.PASS,
elements: []
};
assert.runRule(config, 'A text input is a textbox');
});
})();