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 364
Expand file tree
/
Copy pathunsupported-aria-attribute-test.js
More file actions
171 lines (157 loc) · 8.68 KB
/
Copy pathunsupported-aria-attribute-test.js
File metadata and controls
171 lines (157 loc) · 8.68 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
// 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 = axs.AuditRules.getRule('unsupportedAriaAttribute');
test('Element with role and global, supported and required attributes', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
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
deepEqual(rule.run({ scope: fixture }), expected);
});
test('Element with no role and global attributes only', function() {
var fixture = document.getElementById('qunit-fixture');
var div = fixture.appendChild(document.createElement('div'));
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
div.setAttribute('aria-hidden', 'false'); // global
div.setAttribute('aria-label', 'bananas'); // global
deepEqual(rule.run({ scope: fixture }), expected);
});
/*
* 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() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-hidden', 'false'); // global (so the audit will encounter this element)
deepEqual(rule.run({ scope: fixture }), expected);
});
test('Element with role and known but unsupported attributes', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
var expected = { elements: [widget], result: axs.constants.AuditResult.FAIL };
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
deepEqual(rule.run({ scope: fixture }), expected);
});
/*
* 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() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('map')); // note, a reserved HTML element
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-hidden', 'false'); // global (so the audit will encounter this element)
deepEqual(rule.run({ scope: fixture }), expected);
});
/*
* This test shouldn't care if there are unknown aria- attributes.
*/
test('Element with a role and unknown aria- attribute', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
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
deepEqual(rule.run({ scope: fixture }), expected);
});
/*
* This rule definitely needs to visit elements with no role attribute.
*/
test('Element with no role and unknown aria- attribute', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('aria-required', 'true'); // unsupported
var expected = { elements: [widget], result: axs.constants.AuditResult.FAIL };
deepEqual(rule.run({ scope: fixture }), expected);
});
/*
* This rule can ignore elements with no aria- attributes.
*/
test('Element with role but no aria- attributes', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
var expected = { result: axs.constants.AuditResult.NA };
deepEqual(rule.run({ scope: fixture }), expected);
});
/*
* This rule can ignore elements with only unknown aria- attributes.
*/
test('Element with role but no aria- attributes', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('div'));
widget.setAttribute('role', 'spinbutton');
widget.setAttribute('aria-cucumber', 'true'); // unknown
var expected = { result: axs.constants.AuditResult.NA };
deepEqual(rule.run({ scope: fixture }), expected);
});
test('Element with no role and some global, some unsupported aria- attributes', function() {
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 expected = { elements: [widget], result: axs.constants.AuditResult.FAIL };
deepEqual(rule.run({ scope: fixture }), expected);
});
test('Element with no role and global aria- attributes', function() {
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 expected = { elements: [], result: axs.constants.AuditResult.PASS };
deepEqual(rule.run({ scope: fixture }), expected);
});
test('Input with no type attribute with no role and aria-required', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.setAttribute('aria-required', 'true');
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
deepEqual(rule.run({ scope: fixture }), expected, 'An input with no type is a textbox');
});
test('Input with type=text attribute with no role and aria-required', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.setAttribute('type', 'text');
widget.setAttribute('aria-required', 'true');
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
deepEqual(rule.run({ scope: fixture }), expected, 'A text input is a textbox');
});
test('Input with type=text property with no role and aria-required', function() {
var fixture = document.getElementById('qunit-fixture');
var widget = fixture.appendChild(document.createElement('input'));
widget.type = 'text';
widget.setAttribute('aria-required', 'true');
var expected = { elements: [], result: axs.constants.AuditResult.PASS };
deepEqual(rule.run({ scope: fixture }), expected, 'A text input is a textbox');
});
})();