testilo 3.9.6-git → 3.9.7
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/procs/score/spA11yMessage.js +82 -0
package/package.json
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
spA11yMessage
|
|
3
|
+
Testilo score proc a11yMessage
|
|
4
|
+
|
|
5
|
+
Computes scores from Testaro script a11yMessage and adds them to a report.
|
|
6
|
+
Usage examples:
|
|
7
|
+
node score a11yMessage 35k1r
|
|
8
|
+
node score a11yMessage
|
|
9
|
+
|
|
10
|
+
This proc computes a score that is intended to represent how accessibly a web page offers
|
|
11
|
+
a user an opportunity to report an accessibility issue about that page.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// CONSTANTS
|
|
15
|
+
|
|
16
|
+
// ID of this proc.
|
|
17
|
+
const scoreProcID = 'a11ymessage';
|
|
18
|
+
|
|
19
|
+
// FUNCTIONS
|
|
20
|
+
|
|
21
|
+
// Scores a report.
|
|
22
|
+
exports.scorer = async report => {
|
|
23
|
+
const {acts} = report;
|
|
24
|
+
report.score = {
|
|
25
|
+
scoreProcID,
|
|
26
|
+
total: 0
|
|
27
|
+
};
|
|
28
|
+
const {score} = report;
|
|
29
|
+
if (Array.isArray(acts)) {
|
|
30
|
+
// Act 1: page load.
|
|
31
|
+
if (acts[1].result.startsWith('http')) {
|
|
32
|
+
score.total += 2;
|
|
33
|
+
// Act 2: click an accessibility link.
|
|
34
|
+
if (acts[2].result.move === 'clicked') {
|
|
35
|
+
score.total += 2;
|
|
36
|
+
// Act 4: next page has an accessibility title.
|
|
37
|
+
const act4Result = acts[4].result;
|
|
38
|
+
if (act4Result && act4Result.toLowerCase().includes('accessibility')) {
|
|
39
|
+
score.total += 2;
|
|
40
|
+
// Act 5: page has exactly 1 h1 heading.
|
|
41
|
+
const act5Result = acts[5].result;
|
|
42
|
+
if (act5Result && act5Result.total === 1) {
|
|
43
|
+
score.total += 2;
|
|
44
|
+
// Act 5: h1 is an accessibility heading.
|
|
45
|
+
if (act5Result.items[0].textContent.toLowerCase().includes('accessibility')) {
|
|
46
|
+
score.total += 2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Act 6: page has accessibility email and telephone links.
|
|
51
|
+
const act6Result = acts[6].result;
|
|
52
|
+
if (act6Result.total) {
|
|
53
|
+
const mailLinks = act6Result.items.filter(item => item.attributes.some(
|
|
54
|
+
attribute => attribute.name === 'href' && attribute.value.startsWith('mailto:')
|
|
55
|
+
));
|
|
56
|
+
const telLinks = act6Result.items.filter(item => item.attributes.some(
|
|
57
|
+
attribute => attribute.name === 'href' && attribute.value.startsWith('tel:')
|
|
58
|
+
));
|
|
59
|
+
[mailLinks, telLinks].forEach(linkArray => {
|
|
60
|
+
if (linkArray.length) {
|
|
61
|
+
score.total += 2;
|
|
62
|
+
if (linkArray.some(link => link.textContent.toLowerCase().includes('accessibility'))) {
|
|
63
|
+
score.total += 2;
|
|
64
|
+
}
|
|
65
|
+
else if (
|
|
66
|
+
linkArray.some(
|
|
67
|
+
link => ['before', 'after'].some(
|
|
68
|
+
side => link.siblings[side].some(
|
|
69
|
+
sib => sib.text.toLowerCase().includes('accessibility')
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
) {
|
|
74
|
+
score.total += 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|