testaro 60.15.0 → 60.15.1
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/linkAmb.js +0 -5
- package/testaro/targetSmall.js +86 -28
- package/tests/testaro.js +1 -8
- package/testaro/targetTiny.js +0 -47
package/package.json
CHANGED
package/testaro/linkAmb.js
CHANGED
package/testaro/targetSmall.js
CHANGED
|
@@ -10,38 +10,96 @@
|
|
|
10
10
|
|
|
11
11
|
/*
|
|
12
12
|
targetSmall
|
|
13
|
-
Related to Tenon rule 152
|
|
14
|
-
This test reports visible buttons, inputs, and
|
|
15
|
-
|
|
13
|
+
Related to Tenon rule 152.
|
|
14
|
+
This test reports visible pointer targets, i.e. labels, buttons, inputs, and links, that are
|
|
15
|
+
small enough or near enough to other targets to make pointer interaction difficult. This test
|
|
16
|
+
relates to WCAG 2.2 Success Criteria 2.5.5 and 2.5.8, but does not attempt to implement either
|
|
17
|
+
of them precisely. For example, the test reports a small pointer target that is far from all
|
|
18
|
+
other targets, although it conforms to the Success Criteria.
|
|
16
19
|
*/
|
|
17
20
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
// Module to perform common operations.
|
|
21
|
-
const {init, getRuleResult} = require('../procs/testaro');
|
|
22
|
-
// Module to classify links.
|
|
23
|
-
const {isTooSmall} = require('../procs/target');
|
|
24
|
-
|
|
25
|
-
// ########## FUNCTIONS
|
|
21
|
+
// FUNCTIONS
|
|
26
22
|
|
|
27
23
|
// Runs the test and returns the result.
|
|
28
24
|
exports.reporter = async (page, withItems) => {
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Get
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
// Return totals and standard instances for the rule.
|
|
26
|
+
return await page.evaluate(withItems => {
|
|
27
|
+
// Get all pointer targets.
|
|
28
|
+
const allPTs = Array.from(document.body.querySelectorAll('label, button, input, a'));
|
|
29
|
+
// Get the visible ones.
|
|
30
|
+
const visiblePTs = allPTs.filter(pt => pt.checkVisibility({
|
|
31
|
+
contentVisibilityAuto: true,
|
|
32
|
+
opacityProperty: true,
|
|
33
|
+
visibilityProperty: true
|
|
34
|
+
}));
|
|
35
|
+
// Initialize the data.
|
|
36
|
+
const ptsData = [];
|
|
37
|
+
// For each visible pointer target:
|
|
38
|
+
visiblePTs.forEach(element => {
|
|
39
|
+
// Get the coordinates of its centerpoint.
|
|
40
|
+
const rect = element.getBoundingClientRect();
|
|
41
|
+
const centerX = rect.left + rect.width / 2;
|
|
42
|
+
const centerY = rect.top + rect.height / 2;
|
|
43
|
+
// Add them to the data.
|
|
44
|
+
ptsData.push([centerX, centerY]);
|
|
45
|
+
});
|
|
46
|
+
// Initialize the counts of minor and major violations.
|
|
47
|
+
let violationCounts = [0, 0];
|
|
48
|
+
const instances = [];
|
|
49
|
+
// For each visible pointer target:
|
|
50
|
+
visiblePTs.forEach((element, index) => {
|
|
51
|
+
// Get the minimum of the vertical distances of its centerpoint from those of the others.
|
|
52
|
+
const minYDiff = ptsData[index][1] - Math.abs(
|
|
53
|
+
Math.min(...ptsData.splice(index, 1).map(ptData => ptData[1]))
|
|
54
|
+
);
|
|
55
|
+
// If it is close enough to make a violation possible:
|
|
56
|
+
if (minYDiff < 44) {
|
|
57
|
+
// Get the centerpoint coordinates of those within that vertical distance.
|
|
58
|
+
const yNearPTsData = ptsData.splice(index, 1).filter(
|
|
59
|
+
ptData => Math.abs(ptData[1] - ptsData[index][1]) < 44
|
|
60
|
+
);
|
|
61
|
+
// Get the minimum of their planar distances.
|
|
62
|
+
const minPlanarDistance = Math.min(...yNearPTsData.map(ptData => {
|
|
63
|
+
const planarDistance = Math.sqrt(
|
|
64
|
+
Math.pow(centerX - ptData[0], 2) + Math.pow(centerY - ptData[1], 2)
|
|
65
|
+
);
|
|
66
|
+
return planarDistance;
|
|
67
|
+
}));
|
|
68
|
+
// If the minimum planar distance is less than 44px:
|
|
69
|
+
if (minPlanarDistance < 44) {
|
|
70
|
+
const isVeryNear = minPlanarDistance < 24;
|
|
71
|
+
// Get the ordinal severity of the violation.
|
|
72
|
+
const ordinalSeverity = isVeryNear ? 3 : 2;
|
|
73
|
+
// Increment the applicable violation count.
|
|
74
|
+
violationCounts[isVeryNear ? 1 : 0]++;
|
|
75
|
+
// If itemization is required:
|
|
76
|
+
if (withItems) {
|
|
77
|
+
const what = `Pointer-target centerpoint is only ${Math.round(minPlanarDistance)}px from another one`;
|
|
78
|
+
// Add an instance to the instances.
|
|
79
|
+
instances.push(window.getInstance(element, 'targetSmall', what, 1, ordinalSeverity));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// If itemization is not required:
|
|
85
|
+
if (! withItems) {
|
|
86
|
+
// If there were any major violations:
|
|
87
|
+
if (violationCounts[1]) {
|
|
88
|
+
const what = 'Pointer-target centerpoints are less than 24px from others';
|
|
89
|
+
// Add a summary instance to the instances.
|
|
90
|
+
instances.push(window.getInstance(null, 'targetSmall', what, violationCounts[1], 1));
|
|
91
|
+
}
|
|
92
|
+
// If there were any minor violations:
|
|
93
|
+
if (violationCounts[0]) {
|
|
94
|
+
const what = 'Pointer-target centerpoints are less than 44px from others';
|
|
95
|
+
// Add a summary instance to the instances.
|
|
96
|
+
instances.push(window.getInstance(null, 'targetSmall', what, violationCounts[0], 0));
|
|
97
|
+
}
|
|
39
98
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return await getRuleResult(withItems, all, 'targetSmall', whats, 0);
|
|
99
|
+
return {
|
|
100
|
+
data: {},
|
|
101
|
+
totals: [...violationCounts, 0, 0],
|
|
102
|
+
standardInstances: instances
|
|
103
|
+
};
|
|
104
|
+
}, withItems);
|
|
47
105
|
};
|
package/tests/testaro.js
CHANGED
|
@@ -294,14 +294,7 @@ const allRules = [
|
|
|
294
294
|
},
|
|
295
295
|
{
|
|
296
296
|
id: 'targetSmall',
|
|
297
|
-
what: 'buttons, inputs, and
|
|
298
|
-
launchRole: 'sharer',
|
|
299
|
-
timeOut: 10,
|
|
300
|
-
defaultOn: true
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
id: 'targetTiny',
|
|
304
|
-
what: 'buttons, inputs, and non-inline links smaller than 24 pixels wide and high',
|
|
297
|
+
what: 'labels, buttons, inputs, and links too near each other',
|
|
305
298
|
launchRole: 'sharer',
|
|
306
299
|
timeOut: 5,
|
|
307
300
|
defaultOn: true
|
package/testaro/targetTiny.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
© 2023–2025 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
|
-
© 2025 Jonathan Robert Pool.
|
|
4
|
-
|
|
5
|
-
Licensed under the MIT License. See LICENSE file at the project root or
|
|
6
|
-
https://opensource.org/license/mit/ for details.
|
|
7
|
-
|
|
8
|
-
SPDX-License-Identifier: MIT
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/*
|
|
12
|
-
targetTiny
|
|
13
|
-
Related to Tenon rule 152.
|
|
14
|
-
This test reports visible buttons, inputs, and non-inline links with widths or heights smaller
|
|
15
|
-
than 24 pixels.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
// ########## IMPORTS
|
|
19
|
-
|
|
20
|
-
// Module to perform common operations.
|
|
21
|
-
const {init, getRuleResult} = require('../procs/testaro');
|
|
22
|
-
// Module to classify links.
|
|
23
|
-
const {isTooSmall} = require('../procs/target');
|
|
24
|
-
|
|
25
|
-
// ########## FUNCTIONS
|
|
26
|
-
|
|
27
|
-
// Runs the test and returns the result.
|
|
28
|
-
exports.reporter = async (page, withItems) => {
|
|
29
|
-
// Initialize the locators and result.
|
|
30
|
-
const all = await init(100, page, 'a:visible, button:visible, input:visible');
|
|
31
|
-
// For each locator:
|
|
32
|
-
for (const loc of all.allLocs) {
|
|
33
|
-
// Get data on it if illicitly small.
|
|
34
|
-
const sizeData = await isTooSmall(loc, 24);
|
|
35
|
-
// If it is:
|
|
36
|
-
if (sizeData) {
|
|
37
|
-
// Add the locator to the array of violators.
|
|
38
|
-
all.locs.push([loc, `${sizeData.width} wide by ${sizeData.height} high`]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Populate and return the result.
|
|
42
|
-
const whats = [
|
|
43
|
-
'Interactive element pixel size (__param__) is less than 24 by 24',
|
|
44
|
-
'Interactive elements are smaller than 24 pixels wide and high'
|
|
45
|
-
];
|
|
46
|
-
return await getRuleResult(withItems, all, 'targetTiny', whats, 1);
|
|
47
|
-
};
|