Skip to content

Commit 7674591

Browse files
committed
Updated test cases
1 parent d9b2ee5 commit 7674591

File tree

3 files changed

+84
-63
lines changed

3 files changed

+84
-63
lines changed
Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,77 @@
1-
import { isValidAutocomplete } from "../../commons/text";
1+
import { isValidAutocomplete } from '../../commons/text';
2+
import { ErrorHandler } from '../../../../a11y-engine-core/lib/core/errors/error-handler';
23

34
function checkIsElementValidAutocomplete(node, options, virtualNode) {
4-
const autocomplete = virtualNode.attr('autocomplete')?.toLowerCase().trim();
5-
// if element has autocomplete attribute as off then it is not a violation
6-
if(autocomplete === "off" || autocomplete==="chrome-off") {
7-
return true;
8-
}
9-
10-
// if it is on then we check whether name / id have valid autocomplete value or not
11-
// same for the case if autocomplete is not present or has a non-standard value
12-
if(!autocomplete || autocomplete === "on" || !isValidAutocomplete(autocomplete, options)) {
13-
const name = virtualNode.attr('name');
14-
const id = virtualNode.attr('id');
15-
if((name && isValidAutocomplete(name, options)) || (id && isValidAutocomplete(id, options)))
16-
return true;
17-
return false;
18-
}
19-
20-
// if element autocomplete attribute is neither off nor on then we check if its a standard value
21-
if(isValidAutocomplete(autocomplete, options)) {
5+
const autocomplete = virtualNode
6+
.attr('autocomplete')
7+
?.toLowerCase()
8+
.trim();
9+
// if element has autocomplete attribute as off then it is not a violation
10+
if (autocomplete === 'off' || autocomplete === 'chrome-off') {
11+
return true;
12+
}
13+
14+
// if it is on then we check whether name / id have valid autocomplete value or not
15+
// same for the case if autocomplete is not present or has a non-standard value
16+
if (
17+
!autocomplete ||
18+
autocomplete === 'on' ||
19+
!isValidAutocomplete(autocomplete, options)
20+
) {
21+
const name = virtualNode.attr('name');
22+
const id = virtualNode.attr('id');
23+
if (
24+
(name && isValidAutocomplete(name, options)) ||
25+
(id && isValidAutocomplete(id, options))
26+
) {
2227
return true;
2328
}
24-
2529
return false;
2630
}
27-
28-
function autocompleteA11yEvaluate(node, options, virtualNode) {
29-
try {
30-
const autocomplete = virtualNode.attr('autocomplete');
31-
32-
// check if the autocomplete applicable element is inside form or exist freely
33-
const closestForm = virtualNode.actualNode.closest("form");
34-
35-
//if it exists inside the form and autocomplete for form is off
36-
if(closestForm && (closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "off"
37-
|| closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "chrome-off")) {
38-
// if autocomplete attribute is not present for element then its a pass in this scenario
39-
// otherwise check all posibilities with the method
40-
return autocomplete ? checkIsElementValidAutocomplete(node, options, virtualNode) : true;
41-
} else {
42-
// The else case is if form is present and it has autocomplete as on or not set and
43-
// the other case this handles is that element exists independently
44-
45-
// this method would check for all posibilities
46-
return checkIsElementValidAutocomplete(node, options, virtualNode);
47-
}
48-
}
49-
catch(err) {
50-
ErrorHandler.addCheckError("autocomplete-attribute-valid-check", err);
51-
return undefined;
31+
32+
// if element autocomplete attribute is neither off nor on then we check if its a standard value
33+
if (isValidAutocomplete(autocomplete, options)) {
34+
return true;
35+
}
36+
37+
return false;
38+
}
39+
40+
function autocompleteA11yEvaluate(node, options, virtualNode) {
41+
try {
42+
const autocomplete = virtualNode.attr('autocomplete');
43+
44+
// check if the autocomplete applicable element is inside form or exist freely
45+
const closestForm = virtualNode.actualNode.closest('form');
46+
47+
//if it exists inside the form and autocomplete for form is off
48+
if (
49+
closestForm &&
50+
(closestForm
51+
.getAttribute('autocomplete')
52+
?.toLowerCase()
53+
.trim() === 'off' ||
54+
closestForm
55+
.getAttribute('autocomplete')
56+
?.toLowerCase()
57+
.trim() === 'chrome-off')
58+
) {
59+
// if autocomplete attribute is not present for element then its a pass in this scenario
60+
// otherwise check all posibilities with the method
61+
return autocomplete
62+
? checkIsElementValidAutocomplete(node, options, virtualNode)
63+
: true;
64+
} else {
65+
// The else case is if form is present and it has autocomplete as on or not set and
66+
// the other case this handles is that element exists independently
67+
68+
// this method would check for all posibilities
69+
return checkIsElementValidAutocomplete(node, options, virtualNode);
5270
}
71+
} catch (err) {
72+
ErrorHandler.addCheckError('autocomplete-attribute-valid-check', err);
73+
return undefined;
5374
}
54-
55-
export default autocompleteA11yEvaluate;
75+
}
76+
77+
export default autocompleteA11yEvaluate;

test/integration/rules/autocomplete-valid/autocomplete-valid.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@
152152
<input autocomplete="cc-csc" type="tel" id="pass77" />
153153

154154
<!-- Attribute values that contains synonyms of on/off -->
155-
<input autocomplete="none" id="fail11" />
156-
<input autocomplete="false" id="fail12" />
157-
<input autocomplete="true" id="fail13" />
158-
<input autocomplete="disabled" id="fail14" />
159-
<input autocomplete="enabled" id="fail15" />
160-
<input autocomplete="undefined" id="fail16" />
161-
<input autocomplete="null" id="fail17" />
155+
<input autocomplete="none" id="pass78" />
156+
<input autocomplete="false" id="pass79" />
157+
<input autocomplete="true" id="pass80" />
158+
<input autocomplete="disabled" id="pass81" />
159+
<input autocomplete="enabled" id="pass82" />
160+
<input autocomplete="undefined" id="pass83" />
161+
<input autocomplete="null" id="pass84" />

test/integration/rules/autocomplete-valid/autocomplete-valid.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
["#fail7"],
1212
["#fail8"],
1313
["#fail9"],
14-
["#fail10"],
15-
["#fail11"],
16-
["#fail12"],
17-
["#fail13"],
18-
["#fail14"],
19-
["#fail15"],
20-
["#fail16"],
21-
["#fail17"]
14+
["#fail10"]
2215
],
2316
"passes": [
2417
["#pass1"],
@@ -98,6 +91,12 @@
9891
["#pass75"],
9992
["#pass76"],
10093
["#pass77"],
101-
["#pass78"]
94+
["#pass78"],
95+
["#pass79"],
96+
["#pass80"],
97+
["#pass81"],
98+
["#pass82"],
99+
["#pass83"],
100+
["#pass84"]
102101
]
103102
}

0 commit comments

Comments
 (0)