testaro 60.8.3 → 60.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/testaro/attVal.js +34 -25
package/package.json
CHANGED
package/testaro/attVal.js
CHANGED
|
@@ -24,35 +24,44 @@
|
|
|
24
24
|
|
|
25
25
|
/*
|
|
26
26
|
attVal
|
|
27
|
-
This test reports
|
|
27
|
+
This test reports elements with illicit values of an attribute.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
// Module to perform common operations.
|
|
33
|
-
const {init, getRuleResult} = require('../procs/testaro');
|
|
34
|
-
|
|
35
|
-
// ########## FUNCTIONS
|
|
30
|
+
// FUNCTIONS
|
|
36
31
|
|
|
37
32
|
// Runs the test and returns the result.
|
|
38
33
|
exports.reporter = async (page, withItems, attributeName, areLicit, values) => {
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
// Return totals and standard instances for the rule.
|
|
35
|
+
return await page.evaluate(args => {
|
|
36
|
+
const [withItems, attributeName, areLicit, values] = args;
|
|
37
|
+
// Get all candidates, i.e. elements with the attribute.
|
|
38
|
+
const candidates = document.body.querySelectorAll(`[${attributeName}]`);
|
|
39
|
+
let violationCount = 0;
|
|
40
|
+
const instances = [];
|
|
41
|
+
// For each candidate:
|
|
42
|
+
candidates.forEach(element => {
|
|
43
|
+
const value = element.getAttribute(attributeName);
|
|
44
|
+
// If it violates the rule:
|
|
45
|
+
if (areLicit !== values.includes(value)) {
|
|
46
|
+
// Increment the violation count.
|
|
47
|
+
violationCount++;
|
|
48
|
+
// If itemization is required:
|
|
49
|
+
if (withItems) {
|
|
50
|
+
const what = `Element has attribute ${attributeName} with illicit value ${value}`;
|
|
51
|
+
instances.push(window.getInstance(element, 'attVal', what, 1, 2));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// If there were any violations and itemization is not required:
|
|
56
|
+
if (violationCount && ! withItems) {
|
|
57
|
+
const what = `Elements have attribute ${attributeName} with illicit values`;
|
|
58
|
+
// Add a summary instance to the instances.
|
|
59
|
+
instances.push(window.getInstance(null, 'attVal', what, violationCount, 2));
|
|
50
60
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
];
|
|
57
|
-
return await getRuleResult(withItems, all, 'attVal', whats, 2);
|
|
61
|
+
return {
|
|
62
|
+
data: {},
|
|
63
|
+
totals: [0, 0, violationCount, 0],
|
|
64
|
+
standardInstances: instances
|
|
65
|
+
};
|
|
66
|
+
}, [withItems, attributeName, areLicit, values]);
|
|
58
67
|
};
|