testaro 18.6.0 → 18.7.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "18.6.0",
3
+ "version": "18.7.0",
4
4
  "description": "Run 920 web accessibility tests from 9 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,12 +5,14 @@
5
5
 
6
6
  // ########## IMPORTS
7
7
 
8
+ // Module to perform common operations.
9
+ const {init, report} = require('../procs/testaro');
8
10
  // Module to get locator data.
9
11
  const {getLocatorData} = require('../procs/getLocatorData');
10
12
 
11
13
  // ########## FUNCTIONS
12
14
 
13
- // Runs the test and returns the results.
15
+ // Runs the test and returns the result.
14
16
  exports.reporter = async (
15
17
  page,
16
18
  withItems,
@@ -18,23 +20,18 @@ exports.reporter = async (
18
20
  familyLabels = ['last name', 'surname', 'family name'],
19
21
  emailLabels = ['email']
20
22
  ) => {
23
+ // Initialize the locators and result.
24
+ const all = await init(page, 'input[type=text], input[type=email], input:not([type])');
25
+ // For each locator:
21
26
  const autoValues = {
22
27
  'given-name': givenLabels,
23
28
  'family-name': familyLabels,
24
29
  'email': emailLabels
25
30
  };
26
- // Get locators for all input elements of type text or email.
27
- const locAll = page.locator('input[type=text], input[type=email], input:not([type])');
28
- const locsAll = await locAll.all();
29
- // Initialize the result.
30
- const data = {};
31
- const totals = [0, 0, 0, 0];
32
- const standardInstances = [];
33
- // For each of the inputs:
34
- for (const loc of locsAll) {
35
- // If it requires an autocomplete attribute but does not have it:
36
- const data = await getLocatorData(loc);
37
- const lcText = data.excerpt.toLowerCase();
31
+ for (const loc of all.allLocs) {
32
+ // Get which autocomplete value, if any, its element needs.
33
+ const elData = await getLocatorData(loc);
34
+ const lcText = elData.excerpt.toLowerCase();
38
35
  const neededAutos = Object.keys(autoValues)
39
36
  .filter(autoValue => autoValues[autoValue].some(typeLabel => lcText.includes(typeLabel)));
40
37
  let neededAuto;
@@ -44,49 +41,21 @@ exports.reporter = async (
44
41
  else if (! neededAutos.length && await loc.getAttribute('type') === 'email') {
45
42
  neededAuto = 'email';
46
43
  }
44
+ // If it needs one:
47
45
  if (neededAuto) {
46
+ // If it does not have the one it needs:
48
47
  const actualAuto = await loc.getAttribute('autocomplete');
49
- if (actualAuto !== neededAuto) {
50
- // Add to the totals.
51
- totals[2]++;
52
- // If itemization is required:
53
- if (withItems) {
54
- // Add a standard instance.
55
- standardInstances.push({
56
- ruleID: 'autocomplete',
57
- what: `Input is missing an autocomplete attribute with value ${neededAuto}`,
58
- ordinalSeverity: 2,
59
- tagName: 'INPUT',
60
- id: data.id,
61
- location: data.location,
62
- excerpt: data.excerpt
63
- });
64
- }
48
+ const isBad = actualAuto !== neededAuto;
49
+ if (isBad) {
50
+ // Add the locator to the array of violators.
51
+ all.locs.push([loc, neededAuto]);
65
52
  }
66
53
  }
67
54
  }
68
- // If itemization is not required and there are any instances:
69
- if (! withItems && totals[2]) {
70
- // Add a summary standard instance.
71
- standardInstances.push({
72
- ruleID: 'autocomplete',
73
- what: 'Inputs are missing applicable autocomplete attributes',
74
- ordinalSeverity: 2,
75
- count: totals[2],
76
- tagName: 'INPUT',
77
- id: '',
78
- location: {
79
- doc: '',
80
- type: '',
81
- spec: ''
82
- },
83
- excerpt: ''
84
- });
85
- }
86
- // Return the data.
87
- return {
88
- data,
89
- totals,
90
- standardInstances
91
- };
55
+ // Populate and return the result.
56
+ const whats = [
57
+ 'Input is missing an autocomplete attribute with value __param__',
58
+ 'Inputs are missing applicable autocomplete attributes'
59
+ ];
60
+ return await report(withItems, all, 'autocomplete', whats, 2);
92
61
  };
@@ -104,6 +104,7 @@ exports.reporter = async (page, withItems, trialKeySpecs = []) => {
104
104
  const mbLocAll = page.locator(
105
105
  'button[aria-controls][aria-expanded][aria-haspopup=true], button[aria-controls][aria-expanded][aria-haspopup=menu]'
106
106
  );
107
+ // For each menu button:
107
108
  const mbLocsAll = await mbLocAll.all();
108
109
  for (const mbLoc of mbLocsAll) {
109
110
  // Get a locator for its menu.