@afixt/test-utils 1.0.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 (132) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintrc +78 -0
  3. package/.gitattributes +5 -0
  4. package/.nvmrc +1 -0
  5. package/CLAUDE.md +33 -0
  6. package/README.md +72 -0
  7. package/docs/arrayUtils.js.html +69 -0
  8. package/docs/data/search.json +1 -0
  9. package/docs/domUtils.js.html +182 -0
  10. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  11. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  12. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  13. package/docs/getAccessibleName.js.html +456 -0
  14. package/docs/getAccessibleText.js.html +65 -0
  15. package/docs/getAriaAttributesByElement.js.html +22 -0
  16. package/docs/getCSSGeneratedContent.js.html +62 -0
  17. package/docs/getComputedRole.js.html +172 -0
  18. package/docs/getFocusableElements.js.html +29 -0
  19. package/docs/getGeneratedContent.js.html +18 -0
  20. package/docs/getImageText.js.html +28 -0
  21. package/docs/getStyleObject.js.html +48 -0
  22. package/docs/global.html +3 -0
  23. package/docs/hasAccessibleName.js.html +30 -0
  24. package/docs/hasAttribute.js.html +18 -0
  25. package/docs/hasCSSGeneratedContent.js.html +23 -0
  26. package/docs/hasHiddenParent.js.html +32 -0
  27. package/docs/hasParent.js.html +57 -0
  28. package/docs/hasValidAriaAttributes.js.html +33 -0
  29. package/docs/hasValidAriaRole.js.html +32 -0
  30. package/docs/index.html +3 -0
  31. package/docs/index.js.html +66 -0
  32. package/docs/isAriaAttributesValid.js.html +76 -0
  33. package/docs/isComplexTable.js.html +112 -0
  34. package/docs/isDataTable.js.html +241 -0
  35. package/docs/isFocusable.js.html +37 -0
  36. package/docs/isHidden.js.html +20 -0
  37. package/docs/isOffScreen.js.html +19 -0
  38. package/docs/isValidUrl.js.html +16 -0
  39. package/docs/isVisible.js.html +65 -0
  40. package/docs/module-afixt-test-utils.html +3 -0
  41. package/docs/scripts/core.js +726 -0
  42. package/docs/scripts/core.min.js +23 -0
  43. package/docs/scripts/resize.js +90 -0
  44. package/docs/scripts/search.js +265 -0
  45. package/docs/scripts/search.min.js +6 -0
  46. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  47. package/docs/scripts/third-party/fuse.js +9 -0
  48. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  49. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  50. package/docs/scripts/third-party/hljs-original.js +5171 -0
  51. package/docs/scripts/third-party/hljs.js +1 -0
  52. package/docs/scripts/third-party/popper.js +5 -0
  53. package/docs/scripts/third-party/tippy.js +1 -0
  54. package/docs/scripts/third-party/tocbot.js +672 -0
  55. package/docs/scripts/third-party/tocbot.min.js +1 -0
  56. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  57. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  58. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  59. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  60. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  61. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  62. package/docs/testContrast.js.html +236 -0
  63. package/docs/testLang.js.html +578 -0
  64. package/docs/testOrder.js.html +93 -0
  65. package/jsdoc.json +67 -0
  66. package/package.json +32 -0
  67. package/src/arrayUtils.js +67 -0
  68. package/src/domUtils.js +179 -0
  69. package/src/getAccessibleName.js +454 -0
  70. package/src/getAccessibleText.js +63 -0
  71. package/src/getAriaAttributesByElement.js +19 -0
  72. package/src/getCSSGeneratedContent.js +60 -0
  73. package/src/getComputedRole.js +169 -0
  74. package/src/getFocusableElements.js +26 -0
  75. package/src/getGeneratedContent.js +15 -0
  76. package/src/getImageText.js +25 -0
  77. package/src/getStyleObject.js +45 -0
  78. package/src/hasAccessibleName.js +28 -0
  79. package/src/hasAttribute.js +15 -0
  80. package/src/hasCSSGeneratedContent.js +20 -0
  81. package/src/hasHiddenParent.js +29 -0
  82. package/src/hasParent.js +54 -0
  83. package/src/hasValidAriaAttributes.js +30 -0
  84. package/src/hasValidAriaRole.js +29 -0
  85. package/src/index.js +64 -0
  86. package/src/interactiveRoles.js +20 -0
  87. package/src/isAriaAttributesValid.js +74 -0
  88. package/src/isComplexTable.js +109 -0
  89. package/src/isDataTable.js +239 -0
  90. package/src/isFocusable.js +34 -0
  91. package/src/isHidden.js +17 -0
  92. package/src/isOffScreen.js +16 -0
  93. package/src/isValidUrl.js +13 -0
  94. package/src/isVisible.js +62 -0
  95. package/src/stringUtils.js +150 -0
  96. package/src/testContrast.js +233 -0
  97. package/src/testLang.js +575 -0
  98. package/src/testOrder.js +90 -0
  99. package/test/_template.test.js +21 -0
  100. package/test/arrayUtils.test.js +84 -0
  101. package/test/domUtils.test.js +147 -0
  102. package/test/generate-test-stubs.js +37 -0
  103. package/test/getAccessibleName.test.js +113 -0
  104. package/test/getAccessibleText.test.js +94 -0
  105. package/test/getAriaAttributesByElement.test.js +112 -0
  106. package/test/getCSSGeneratedContent.test.js +102 -0
  107. package/test/getComputedRole.test.js +180 -0
  108. package/test/getFocusableElements.test.js +134 -0
  109. package/test/getGeneratedContent.test.js +321 -0
  110. package/test/getImageText.test.js +21 -0
  111. package/test/getStyleObject.test.js +134 -0
  112. package/test/hasAccessibleName.test.js +59 -0
  113. package/test/hasAttribute.test.js +132 -0
  114. package/test/hasCSSGeneratedContent.test.js +143 -0
  115. package/test/hasHiddenParent.test.js +176 -0
  116. package/test/hasParent.test.js +266 -0
  117. package/test/hasValidAriaAttributes.test.js +79 -0
  118. package/test/hasValidAriaRole.test.js +98 -0
  119. package/test/isAriaAttributesValid.test.js +83 -0
  120. package/test/isComplexTable.test.js +363 -0
  121. package/test/isDataTable.test.js +948 -0
  122. package/test/isFocusable.test.js +182 -0
  123. package/test/isHidden.test.js +157 -0
  124. package/test/isOffScreen.test.js +249 -0
  125. package/test/isValidUrl.test.js +63 -0
  126. package/test/isVisible.test.js +104 -0
  127. package/test/setup.js +11 -0
  128. package/test/stringUtils.test.js +106 -0
  129. package/test/testContrast.test.js +77 -0
  130. package/test/testLang.test.js +21 -0
  131. package/test/testOrder.test.js +157 -0
  132. package/vitest.config.js +25 -0
@@ -0,0 +1,363 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import {
3
+ isComplexTable,
4
+ checkMultiRowsInHeader,
5
+ checkMultiRowsWithColspan,
6
+ checkInconsistent
7
+ } from '../src/isComplexTable.js';
8
+
9
+ describe('isComplexTable and helper functions', () => {
10
+ beforeEach(() => {
11
+ document.body.innerHTML = '';
12
+ });
13
+
14
+ describe('checkMultiRowsInHeader', () => {
15
+ it('should return true when table has multiple rows in header', () => {
16
+ // Arrange
17
+ const table = document.createElement('table');
18
+ table.innerHTML = `
19
+ <thead>
20
+ <tr><th>Header 1</th><th>Header 2</th></tr>
21
+ <tr><th>Subheader 1</th><th>Subheader 2</th></tr>
22
+ </thead>
23
+ <tbody>
24
+ <tr><td>Cell 1</td><td>Cell 2</td></tr>
25
+ </tbody>
26
+ `;
27
+ document.body.appendChild(table);
28
+
29
+ // Act
30
+ const result = checkMultiRowsInHeader(table);
31
+
32
+ // Assert
33
+ expect(result).toBe(true);
34
+ });
35
+
36
+ it('should return false when table has single row in header', () => {
37
+ // Arrange
38
+ const table = document.createElement('table');
39
+ table.innerHTML = `
40
+ <thead>
41
+ <tr><th>Header 1</th><th>Header 2</th></tr>
42
+ </thead>
43
+ <tbody>
44
+ <tr><td>Cell 1</td><td>Cell 2</td></tr>
45
+ </tbody>
46
+ `;
47
+ document.body.appendChild(table);
48
+
49
+ // Act
50
+ const result = checkMultiRowsInHeader(table);
51
+
52
+ // Assert
53
+ expect(result).toBe(false);
54
+ });
55
+
56
+ it('should return false when table has no thead element', () => {
57
+ // Arrange
58
+ const table = document.createElement('table');
59
+ table.innerHTML = `
60
+ <tbody>
61
+ <tr><td>Cell 1</td><td>Cell 2</td></tr>
62
+ </tbody>
63
+ `;
64
+ document.body.appendChild(table);
65
+
66
+ // Act
67
+ const result = checkMultiRowsInHeader(table);
68
+
69
+ // Assert
70
+ expect(result).toBe(false);
71
+ });
72
+ });
73
+
74
+ describe('checkMultiRowsWithColspan', () => {
75
+ it('should return true when multiple rows have cells with colspan', () => {
76
+ // Arrange
77
+ const table = document.createElement('table');
78
+ table.innerHTML = `
79
+ <tbody>
80
+ <tr><td colspan="2">Spanning 2 columns</td></tr>
81
+ <tr><td>Cell 1</td><td colspan="1">Cell 2</td></tr>
82
+ </tbody>
83
+ `;
84
+ document.body.appendChild(table);
85
+
86
+ // Act
87
+ const result = checkMultiRowsWithColspan(table);
88
+
89
+ // Assert
90
+ expect(result).toBe(true);
91
+ });
92
+
93
+ it('should return false when only one row has cells with colspan', () => {
94
+ // Arrange
95
+ const table = document.createElement('table');
96
+ table.innerHTML = `
97
+ <tbody>
98
+ <tr><td colspan="2">Spanning 2 columns</td></tr>
99
+ <tr><td>Cell 1</td><td>Cell 2</td></tr>
100
+ </tbody>
101
+ `;
102
+ document.body.appendChild(table);
103
+
104
+ // Act
105
+ const result = checkMultiRowsWithColspan(table);
106
+
107
+ // Assert
108
+ expect(result).toBe(false);
109
+ });
110
+
111
+ it('should return false when no rows have cells with colspan', () => {
112
+ // Arrange
113
+ const table = document.createElement('table');
114
+ table.innerHTML = `
115
+ <tbody>
116
+ <tr><td>Cell 1</td><td>Cell 2</td></tr>
117
+ <tr><td>Cell 3</td><td>Cell 4</td></tr>
118
+ </tbody>
119
+ `;
120
+ document.body.appendChild(table);
121
+
122
+ // Act
123
+ const result = checkMultiRowsWithColspan(table);
124
+
125
+ // Assert
126
+ expect(result).toBe(false);
127
+ });
128
+ });
129
+
130
+ describe('checkInconsistent', () => {
131
+ it('should handle tables with colspan attributes', () => {
132
+ // Arrange
133
+ const table = document.createElement('table');
134
+ table.innerHTML = `
135
+ <tbody>
136
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
137
+ <tr><td colspan="2">Spans 2 columns</td><td>Cell 3</td></tr>
138
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
139
+ </tbody>
140
+ `;
141
+ document.body.appendChild(table);
142
+
143
+ // Act
144
+ const result = checkInconsistent(table);
145
+
146
+ // Assert
147
+ // The implementation normalizes the table by expanding colspan cells,
148
+ // so the result depends on how the normalization works
149
+ // The current implementation actually results in a consistent table
150
+ expect(result).toBe(false);
151
+ });
152
+
153
+ it('should handle tables with rowspan attributes', () => {
154
+ // Arrange
155
+ const table = document.createElement('table');
156
+ table.innerHTML = `
157
+ <tbody>
158
+ <tr><td rowspan="2">Spans 2 rows</td><td>Cell 2</td><td>Cell 3</td></tr>
159
+ <tr><td>Cell 2</td><td>Cell 3</td></tr>
160
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
161
+ </tbody>
162
+ `;
163
+ document.body.appendChild(table);
164
+
165
+ // Act
166
+ const result = checkInconsistent(table);
167
+
168
+ // Assert
169
+ // The implementation normalizes the table structure
170
+ expect(result).toBe(false);
171
+ });
172
+
173
+ it('should return false when table has consistent structure', () => {
174
+ // Arrange
175
+ const table = document.createElement('table');
176
+ table.innerHTML = `
177
+ <tbody>
178
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
179
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
180
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
181
+ </tbody>
182
+ `;
183
+ document.body.appendChild(table);
184
+
185
+ // Act
186
+ const result = checkInconsistent(table);
187
+
188
+ // Assert
189
+ expect(result).toBe(false);
190
+ });
191
+
192
+ it('should handle empty table', () => {
193
+ // Arrange
194
+ const table = document.createElement('table');
195
+ document.body.appendChild(table);
196
+
197
+ // Act
198
+ const result = checkInconsistent(table);
199
+
200
+ // Assert
201
+ expect(result).toBe(false);
202
+ });
203
+
204
+ it('should properly handle a table with rowspan that creates a new row', () => {
205
+ // Arrange
206
+ const table = document.createElement('table');
207
+ table.innerHTML = `
208
+ <tbody>
209
+ <tr><td rowspan="2">Spans 2 rows</td><td>Cell 2</td></tr>
210
+ <!-- No second row, it will be created by the function -->
211
+ </tbody>
212
+ `;
213
+ document.body.appendChild(table);
214
+
215
+ // Act
216
+ const result = checkInconsistent(table);
217
+
218
+ // Assert
219
+ expect(result).toBe(true); // Should be inconsistent since we're creating a new row
220
+ });
221
+ });
222
+
223
+ describe('isComplexTable', () => {
224
+ it('should return true for null or undefined input', () => {
225
+ // Act & Assert
226
+ expect(isComplexTable(null)).toBe(true);
227
+ expect(isComplexTable(undefined)).toBe(true);
228
+ });
229
+
230
+ it('should identify table with multiple rows in header as complex', () => {
231
+ // Arrange
232
+ const table = document.createElement('table');
233
+ table.innerHTML = `
234
+ <thead>
235
+ <tr><th>Header 1</th><th>Header 2</th></tr>
236
+ <tr><th>Subheader 1</th><th>Subheader 2</th></tr>
237
+ </thead>
238
+ <tbody>
239
+ <tr><td>Cell 1</td><td>Cell 2</td></tr>
240
+ </tbody>
241
+ `;
242
+ document.body.appendChild(table);
243
+
244
+ // Act
245
+ const result = isComplexTable(table);
246
+
247
+ // Assert
248
+ expect(result).toBe(true);
249
+ });
250
+
251
+ it('should identify table with multiple rows with colspan as complex', () => {
252
+ // Arrange
253
+ const table = document.createElement('table');
254
+ table.innerHTML = `
255
+ <tbody>
256
+ <tr><td colspan="2">Spanning 2 columns</td></tr>
257
+ <tr><td>Cell 1</td><td colspan="1">Cell 2</td></tr>
258
+ </tbody>
259
+ `;
260
+ document.body.appendChild(table);
261
+
262
+ // Act
263
+ const result = isComplexTable(table);
264
+
265
+ // Assert
266
+ expect(result).toBe(true);
267
+ });
268
+
269
+ it('should handle tables with complex structure', () => {
270
+ // Arrange - Create a table with irregular structure
271
+ const table = document.createElement('table');
272
+ table.innerHTML = `
273
+ <tbody>
274
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
275
+ <tr><td colspan="2">Spans 2 columns</td><td>Cell 3</td></tr>
276
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
277
+ </tbody>
278
+ `;
279
+ document.body.appendChild(table);
280
+
281
+ // Act
282
+ const result = isComplexTable(table);
283
+
284
+ // Assert
285
+ // The result depends on the implementation of the helper functions
286
+ // In the current implementation, this would be true if checkMultiRowsWithColspan returns true,
287
+ // not because of checkInconsistent
288
+ const expectedResult = checkMultiRowsWithColspan(table);
289
+ expect(result).toBe(expectedResult);
290
+ });
291
+
292
+ it('should identify simple table as not complex', () => {
293
+ // Arrange
294
+ const table = document.createElement('table');
295
+ table.innerHTML = `
296
+ <thead>
297
+ <tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr>
298
+ </thead>
299
+ <tbody>
300
+ <tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>
301
+ <tr><td>Cell 4</td><td>Cell 5</td><td>Cell 6</td></tr>
302
+ </tbody>
303
+ `;
304
+ document.body.appendChild(table);
305
+
306
+ // Act
307
+ const result = isComplexTable(table);
308
+
309
+ // Assert
310
+ expect(result).toBe(false);
311
+ });
312
+
313
+ it('should handle tables with nested tables', () => {
314
+ // Arrange
315
+ const table = document.createElement('table');
316
+ table.innerHTML = `
317
+ <thead>
318
+ <tr><th>Header 1</th><th>Header 2</th></tr>
319
+ </thead>
320
+ <tbody>
321
+ <tr>
322
+ <td>Cell 1</td>
323
+ <td>
324
+ <table>
325
+ <tr><td>Nested Cell 1</td><td>Nested Cell 2</td></tr>
326
+ <tr><td colspan="2">Nested Spanning Cell</td></tr>
327
+ </table>
328
+ </td>
329
+ </tr>
330
+ </tbody>
331
+ `;
332
+ document.body.appendChild(table);
333
+
334
+ // Act
335
+ const result = isComplexTable(table);
336
+
337
+ // Assert
338
+ expect(result).toBe(false); // Should ignore nested tables
339
+ });
340
+
341
+ it('should correctly identify table with multiple complexity factors', () => {
342
+ // Arrange
343
+ const table = document.createElement('table');
344
+ table.innerHTML = `
345
+ <thead>
346
+ <tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr>
347
+ <tr><th>Subheader 1</th><th>Subheader 2</th><th>Subheader 3</th></tr>
348
+ </thead>
349
+ <tbody>
350
+ <tr><td rowspan="2">Spans 2 rows</td><td>Cell 2</td><td>Cell 3</td></tr>
351
+ <tr><td colspan="2">Spans 2 columns</td></tr>
352
+ </tbody>
353
+ `;
354
+ document.body.appendChild(table);
355
+
356
+ // Act
357
+ const result = isComplexTable(table);
358
+
359
+ // Assert
360
+ expect(result).toBe(true);
361
+ });
362
+ });
363
+ });