testaro 14.11.0 → 14.12.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/testaro/focOp.js +53 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "14.11.0",
3
+ "version": "14.12.0",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/testaro/focOp.js CHANGED
@@ -10,9 +10,12 @@
10
10
  operable, users are likely to be surprised that nothing happens when they try to operate such
11
11
  elements. If operable elements are not focusable, users depending on keyboard navigation are
12
12
  prevented from operating those elements. The test considers an element operable if it has a
13
- non-inherited pointer cursor and is not a 'LABEL' element, or has an operable tag name ('A',
14
- 'BUTTON', 'IFRAME', 'INPUT', 'SELECT', 'TEXTAREA'), or has an 'onclick' attribute. The test
15
- considers an element Tab-focusable if its tabIndex property has the value 0.
13
+ non-inherited pointer cursor and is not a 'LABEL' element, has an operable tag name ('A',
14
+ 'BUTTON', 'IFRAME', 'INPUT', 'SELECT', 'TEXTAREA'), has an interactive explicit role (button,
15
+ link, checkbox, switch, input, textbox, searchbox, combobox, option, treeitem, radio, slider,
16
+ spinbutton, menuitem, menuitemcheckbox, composite, grid, select, listbox, menu, menubar, tree,
17
+ tablist, tab, gridcell, radiogroup, treegrid, widget, or scrollbar), or has an 'onclick'
18
+ attribute. The test considers an element Tab-focusable if its tabIndex property has the value 0.
16
19
  */
17
20
  exports.reporter = async (page, withItems) => {
18
21
  // Get data on focusability-operability-discrepant elements.
@@ -29,10 +32,6 @@ exports.reporter = async (page, withItems) => {
29
32
  onlyOperable: {
30
33
  total: 0,
31
34
  tagNames: {}
32
- },
33
- focusableAndOperable: {
34
- total: 0,
35
- tagNames: {}
36
35
  }
37
36
  }
38
37
  }
@@ -40,22 +39,59 @@ exports.reporter = async (page, withItems) => {
40
39
  if (withItems) {
41
40
  data.items = {
42
41
  onlyFocusable: [],
43
- onlyOperable: [],
44
- focusableAndOperable: []
42
+ onlyOperable: []
45
43
  };
46
44
  }
47
45
  // FUNCTION DEFINITIONS START
48
46
  // Returns data on an element’s operability and prevents it from propagating a pointer.
49
47
  const operabilityOf = element => {
48
+ // Identify the operable tag names.
50
49
  const opTags = new Set(['A', 'BUTTON', 'IFRAME', 'INPUT', 'SELECT', 'TEXTAREA']);
50
+ // Identify the operable roles.
51
+ const opRoles = new Set([
52
+ 'button',
53
+ 'checkbox',
54
+ 'combobox',
55
+ 'composite',
56
+ 'grid',
57
+ 'gridcell',
58
+ 'input',
59
+ 'link',
60
+ 'listbox',
61
+ 'menu',
62
+ 'menubar',
63
+ 'menuitem',
64
+ 'menuitemcheckbox',
65
+ 'option',
66
+ 'radio',
67
+ 'radiogroup',
68
+ 'scrollbar',
69
+ 'searchbox',
70
+ 'select',
71
+ 'slider',
72
+ 'spinbutton',
73
+ 'switch',
74
+ 'tab',
75
+ 'tablist',
76
+ 'textbox',
77
+ 'tree',
78
+ 'treegrid',
79
+ 'treeitem',
80
+ 'widget',
81
+ ]);
82
+ // Identify whether the element has a pointer cursor.
51
83
  const hasPointer = window.getComputedStyle(element).cursor === 'pointer';
84
+ // Identify the bases for considering an element operable.
52
85
  const opBases = [
53
86
  opTags.has(element.tagName),
54
87
  element.hasAttribute('onclick'),
88
+ opRoles.has(element.getAttribute('role')),
55
89
  hasPointer && element.tagName !== 'LABEL'
56
90
  ];
91
+ // If the element is operable:
57
92
  const result = {operable: opBases.some(basis => basis)};
58
93
  if (result.operable) {
94
+ // Add its data to its result.
59
95
  result.byTag = opBases[0];
60
96
  result.byOnClick = opBases[1];
61
97
  result.byPointer = opBases[2];
@@ -65,14 +101,14 @@ exports.reporter = async (page, withItems) => {
65
101
  // Change it to the browser default to prevent pointer propagation.
66
102
  element.style.cursor = 'default';
67
103
  }
104
+ // Return the result.
68
105
  return result;
69
106
  };
70
107
  // Adds facts about an element to data.
71
108
  const addFacts = (element, status, byTag, byOnClick, byPointer) => {
72
109
  const statusNames = {
73
110
  f: 'onlyFocusable',
74
- o: 'onlyOperable',
75
- b: 'focusableAndOperable'
111
+ o: 'onlyOperable'
76
112
  };
77
113
  const statusName = statusNames[status];
78
114
  data.totals.types[statusName].total++;
@@ -100,17 +136,12 @@ exports.reporter = async (page, withItems) => {
100
136
  elements.forEach(element => {
101
137
  // If its tab index is 0, deem it focusable and:
102
138
  if (element.tabIndex === 0) {
103
- // Increment the grand total.
104
- data.totals.total++;
105
139
  // Determine whether and how it is operable.
106
- const {operable, byTag, byOnClick, byPointer} = operabilityOf(element);
107
- // If it is:
108
- if (operable) {
109
- // Add its data to the result.
110
- addFacts(element, 'b', byTag, byOnClick, byPointer);
111
- }
112
- // Otherwise, i.e. if it is not operable:
113
- else {
140
+ const {operable} = operabilityOf(element);
141
+ // If it is not:
142
+ if (! operable) {
143
+ // Increment the total.
144
+ data.totals.total++;
114
145
  // Add its data to the result.
115
146
  addFacts(element, 'f');
116
147
  }
@@ -121,7 +152,7 @@ exports.reporter = async (page, withItems) => {
121
152
  const {operable, byTag, byOnClick, byPointer} = operabilityOf(element);
122
153
  // If it is:
123
154
  if (operable) {
124
- // Increment the grand total.
155
+ // Increment the total.
125
156
  data.totals.total++;
126
157
  // Add its data to the result.
127
158
  addFacts(element, 'o', byTag, byOnClick, byPointer);