Skip to content

Commit 553b7d3

Browse files
committed
Merge branch 'master' into tests-sub-folder-support-example
# Conflicts: # scripts/test-reviewer/generateReviewPages.mjs
2 parents 4457e4f + 01923da commit 553b7d3

File tree

11 files changed

+552
-601
lines changed

11 files changed

+552
-601
lines changed

__test__/__snapshots__/createAllTests.test.js.snap

Lines changed: 480 additions & 480 deletions
Large diffs are not rendered by default.

lib/data/process-test-directory/index.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,15 @@ const processTestDirectory = async config => {
512512
return v;
513513
}
514514

515-
function getExampleReferences(test, refs) {
515+
function getExampleReferences() {
516516
let links = '';
517517

518518
test.references.forEach(({ refId }) => {
519-
const { value: link, linkText } = refs[refId];
520-
521-
if (typeof link === 'string' && link.length) {
522-
links += `<link rel="help" href="${link}" title="${linkText}">\n`;
519+
const { value, linkText } = refs[refId];
520+
if (typeof value === 'string' && value.length) {
521+
links += `<link rel="help" href="${value}" title="${linkText}">\n`;
523522
}
524523
});
525-
526524
return links;
527525
}
528526

@@ -552,7 +550,7 @@ const processTestDirectory = async config => {
552550
const testPlanHtmlFileBuildPath = path.join(testPlanBuildDirectory, `${testFileName}.html`);
553551
const testPlanJsonFileBuildPath = path.join(testPlanBuildDirectory, `${testFileName}.json`);
554552

555-
const exampleReferences = getExampleReferences(test, refs);
553+
const exampleReferences = getExampleReferences();
556554
const scriptsContent = [...utils.addSetupScript(testId, test.setupScript.script)];
557555

558556
/** @type {AriaATFile.Behavior} */
@@ -629,7 +627,6 @@ const processTestDirectory = async config => {
629627
}
630628

631629
// Process CSV files
632-
const refs = utils.getRefs(referencesCsv);
633630
const indexOfURLs = [];
634631
const testPlanPath = subfolder
635632
? `tests/${subfolder}/${path.basename(testPlanBuildDirectory)}`
@@ -699,10 +696,7 @@ const processTestDirectory = async config => {
699696
},
700697
commandsJson
701698
);
702-
const {
703-
references: { aria, htmlAam },
704-
} = supportJson;
705-
const referencesParsed = utils.parseReferencesCSV(referencesCsv, { aria, htmlAam });
699+
const referencesParsed = utils.parseReferencesCSV(referencesCsv);
706700

707701
const keyDefs = utils.getKeyDefs();
708702
const keysParsed = utils.parseKeyMap(keyDefs);
@@ -902,7 +896,7 @@ const processTestDirectory = async config => {
902896
log('Creating the following test files: ');
903897
testsParsed.forEach(function (testParsed, index) {
904898
try {
905-
const [url, applies_to_at] = createTestFile(testParsed, refs, atCommandsMap, {
899+
const [url, applies_to_at] = createTestFile(testParsed, referencesParsed, atCommandsMap, {
906900
emitFile,
907901
scriptsRecord,
908902
exampleScriptedFilesQueryable,

lib/data/process-test-directory/utils.js

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -290,44 +290,6 @@ class Utils {
290290
});
291291
}
292292

293-
getRefs(referencesCsv) {
294-
const refs = {};
295-
296-
if (this.testFormatVersion === 1) {
297-
for (const row of referencesCsv) {
298-
refs[row.refId] = row.value.trim();
299-
}
300-
} else {
301-
for (const row of referencesCsv) {
302-
const {
303-
references: { aria, htmlAam },
304-
} = this.supportJson;
305-
306-
let refId = row.refId.trim();
307-
let type = row.type.trim();
308-
let value = row.value.trim();
309-
let linkText = row.linkText.trim();
310-
311-
if (type === 'aria') {
312-
value = `${aria.baseUrl}${aria.fragmentIds[value]}`;
313-
linkText = `${linkText} ${aria.linkText}`;
314-
}
315-
316-
if (type === 'htmlAam') {
317-
value = `${htmlAam.baseUrl}${htmlAam.fragmentIds[value]}`;
318-
linkText = `${linkText} ${htmlAam.linkText}`;
319-
}
320-
321-
refs[refId] = {
322-
type,
323-
value,
324-
linkText,
325-
};
326-
}
327-
}
328-
return refs;
329-
}
330-
331293
getScriptsJs(scriptsContent = []) {
332294
let js = 'let scripts = {\n';
333295
js += scriptsContent.join(',\n');
@@ -522,44 +484,30 @@ ${exampleReferences}
522484

523485
/**
524486
* @param {AriaATCSV.Reference[]} referenceRows
525-
* @param {AriaATCSV.SupportReference?} aria
526-
* @param {AriaATCSV.SupportReference?} htmlAam
527487
* @returns {AriaATParsed.ReferenceMap}
528488
*/
529-
parseReferencesCSV(referenceRows, { aria, htmlAam } = {}) {
530-
const refMap = {};
489+
parseReferencesCSV(referenceRows) {
490+
const refs = {};
531491

532492
if (this.testFormatVersion === 1) {
533-
for (const { refId, value } of referenceRows) {
534-
refMap[refId] = { refId, value: value.trim() };
493+
for (const row of referenceRows) {
494+
let refId = row.refId?.trim();
495+
let value = row.value?.trim();
496+
497+
refs[refId] = { refId, value };
535498
}
536499
} else {
537-
for (const {
538-
refId: _refId,
539-
type: _type,
540-
value: _value,
541-
linkText: _linkText,
542-
} of referenceRows) {
543-
let refId = _refId?.trim();
544-
let type = _type?.trim();
545-
let value = _value?.trim();
546-
let linkText = _linkText?.trim();
547-
548-
if (type === 'aria') {
549-
value = `${aria.baseUrl}${aria.fragmentIds[value]}`;
550-
linkText = `${linkText} ${aria.linkText}`;
551-
}
500+
for (const row of referenceRows) {
501+
let refId = row.refId?.trim();
502+
let type = row.type?.trim();
503+
let value = row.value?.trim();
504+
let linkText = row.linkText?.trim();
552505

553-
if (type === 'htmlAam') {
554-
value = `${htmlAam.baseUrl}${htmlAam.fragmentIds[value]}`;
555-
linkText = `${linkText} ${htmlAam.linkText}`;
556-
}
557-
558-
refMap[refId] = { refId, type, value, linkText };
506+
refs[refId] = { refId, type, value, linkText };
559507
}
560508
}
561509

562-
return refMap;
510+
return refs;
563511
}
564512

565513
// Miscellaneous

lib/data/process-test-directory/v1.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,26 +335,25 @@ const processTestDirectory = async config => {
335335
}
336336

337337
function getExampleReferences() {
338-
const example = refs.example;
339338
let links = '';
340339

340+
const example = refs.example.value;
341341
if (typeof example === 'string' && example.length) {
342-
links += `<link rel="help" href="${refs.example}">\n`;
342+
links += `<link rel="help" href="${example}">\n`;
343343
}
344344

345-
let items = test.refs.split(' ');
346-
items.forEach(function (item) {
347-
item = item.trim();
348-
349-
if (item.length) {
350-
if (typeof refs[item] === 'string') {
351-
links += `<link rel="help" href="${refs[item]}">\n`;
345+
let refIds = test.refs.split(' ');
346+
refIds.forEach(refId => {
347+
refId = refId.trim();
348+
if (refId.length) {
349+
const { value } = refs[refId];
350+
if (typeof value === 'string') {
351+
links += `<link rel="help" href="${value}">\n`;
352352
} else {
353-
utils.addTestError(test.testId, 'Reference does not exist: ' + item);
353+
utils.addTestError(test.testId, 'Reference does not exist: ' + refId);
354354
}
355355
}
356356
});
357-
358357
return links;
359358
}
360359

@@ -465,7 +464,6 @@ const processTestDirectory = async config => {
465464
}
466465

467466
// Process CSV files
468-
const refs = utils.getRefs(referencesCsv);
469467
const indexOfURLs = [];
470468
const testPlanPath = subfolder
471469
? `tests/${subfolder}/${path.basename(testPlanBuildDirectory)}`
@@ -642,7 +640,7 @@ const processTestDirectory = async config => {
642640
log('Creating the following test files: ');
643641
testsCsv.forEach(function (test) {
644642
try {
645-
const [url, applies_to_at] = createTestFile(test, refs, atCommandsMap, {
643+
const [url, applies_to_at] = createTestFile(test, referencesParsed, atCommandsMap, {
646644
emitFile,
647645
scriptsRecord,
648646
exampleScriptedFilesQueryable,

scripts/test-reviewer/createReviewPages.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export function createReviewPages(config) {
177177
} = support;
178178

179179
// Get test plan's references.csv data
180-
const referencesData = getReferencesData(testPlanDirectory, aria, htmlAam);
180+
const referencesData = getReferencesData(testPlanDirectory);
181181
const referenceFromReferencesCSV = getReferenceForDirectory(referencesData, 'reference');
182182
const titleFromReferencesCSV = getReferenceForDirectory(referencesData, 'title');
183183

@@ -198,7 +198,11 @@ export function createReviewPages(config) {
198198
scripts.push(...scriptsData);
199199

200200
// Get test plan build directory's from `test-{xx}-{testId}.html` files data
201-
const collectedTestsData = getCollectedTestsData(testPlanBuildDirectory);
201+
const collectedTestsData = getCollectedTestsData(testPlanBuildDirectory, {
202+
referencesData,
203+
aria,
204+
htmlAam,
205+
});
202206
collectedTests.push(...collectedTestsData);
203207

204208
collectedTests.forEach(({ test, testFullName, helpLinks, ...testData }) => {

scripts/test-reviewer/generateReviewPages.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const generatePatternPages = ({
1414
referencesForPattern,
1515
reviewBuildDirectory,
1616
testPlansInfo = {},
17-
testMode = false,
1817
}) => {
1918
patterns.forEach(pattern => {
2019
const info = testPlansInfo[pattern];

scripts/test-reviewer/getCollectedTestsData.mjs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import np from 'node-html-parser';
44

55
/**
66
* @param {string} testPlanBuildDirectory
7+
* @param {*[]} referencesData
8+
* @param aria
9+
* @param htmlAam
710
* @returns {*[]}
811
*/
9-
function getCollectedTestsData(testPlanBuildDirectory) {
12+
function getCollectedTestsData(testPlanBuildDirectory, { referencesData = [], aria, htmlAam }) {
1013
const collectedTests = [];
1114

1215
fse.readdirSync(testPlanBuildDirectory).forEach(function (file) {
@@ -41,6 +44,25 @@ function getCollectedTestsData(testPlanBuildDirectory) {
4144
} else {
4245
text = `APG example: ${href.split('examples/')[1]}`;
4346
}
47+
} else {
48+
// Construct the links using aria and htmlAam for the v2 tests
49+
const reference = referencesData.find(
50+
ref =>
51+
ref.refId === href.trim() ||
52+
ref.refId === text.trim() ||
53+
ref.value === href.trim() ||
54+
ref.value === text.trim()
55+
);
56+
57+
if (reference?.type === 'aria') {
58+
href = `${aria.baseUrl}${aria.fragmentIds[href]}`;
59+
text = `${text} ${aria.linkText}`;
60+
}
61+
62+
if (reference?.type === 'htmlAam') {
63+
href = `${htmlAam.baseUrl}${htmlAam.fragmentIds[href]}`;
64+
text = `${text} ${htmlAam.linkText}`;
65+
}
4466
}
4567

4668
helpLinks.push({

scripts/test-reviewer/getReferencesData.mjs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import fse from 'fs-extra';
33

44
/**
55
* @param {string} testPlanDirectory
6-
* @param aria
7-
* @param htmlAam
86
* @returns {{linkText: *, refId: *, type: *, value: *}[]}
97
*/
10-
const getReferencesData = (testPlanDirectory, aria, htmlAam) => {
8+
const getReferencesData = testPlanDirectory => {
119
const referencesCsv = fse.readFileSync(
1210
path.join(testPlanDirectory, 'data', 'references.csv'),
1311
'UTF-8'
@@ -24,26 +22,14 @@ const getReferencesData = (testPlanDirectory, aria, htmlAam) => {
2422
return obj;
2523
});
2624

27-
return referencesData.map(
28-
({ refId: _refId, type: _type, value: _value, linkText: _linkText }) => {
29-
let refId = _refId?.trim();
30-
let type = _type?.trim();
31-
let value = _value?.trim();
32-
let linkText = _linkText?.trim();
25+
return referencesData.map(referenceData => {
26+
let refId = referenceData.refId?.trim();
27+
let type = referenceData.type?.trim();
28+
let value = referenceData.value?.trim();
29+
let linkText = referenceData.linkText?.trim();
3330

34-
if (type === 'aria') {
35-
value = `${aria.baseUrl}${aria.fragmentIds[value]}`;
36-
linkText = `${linkText} ${aria.linkText}`;
37-
}
38-
39-
if (type === 'htmlAam') {
40-
value = `${htmlAam.baseUrl}${htmlAam.fragmentIds[value]}`;
41-
linkText = `${linkText} ${htmlAam.linkText}`;
42-
}
43-
44-
return { refId, type, value, linkText };
45-
}
46-
);
31+
return { refId, type, value, linkText };
32+
});
4733
};
4834

4935
export default getReferencesData;

tests/apg/disclosure-faq/data/assertions.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ stateButtonCollapsed,1,"State of the button, 'collapsed', is conveyed",convey st
77
stateButtonExpanded,1,"State of the button, 'expanded', is conveyed",convey state of the button 'expanded',aria-expanded
88
stateChangeToCollapsed,1,Change in state to 'collapsed' is conveyed,convey change in state to 'collapsed',aria-expanded
99
stateChangeToExpanded,1,Change in state to 'expanded' is conveyed,convey change in state to 'expanded',aria-expanded
10-
textAnswer1,1,"Some or all the answer text, 'Park at the nearest available parking meter without paying the meter and call 999-999-9999 to report the problem. We will note and approve your alternate location and will investigate the cause of the shortage in your assigned facility.', is conveyed","convey some or all the answer text, 'Park at the nearest available parking meter without paying the meter and call 999-999-9999 to report the problem. We will note and approve your alternate location and will investigate the cause of the shortage in your assigned facility.'",generic
10+
textAnswer1,1,"Some or all the answer text, 'Park at the nearest available parking meter without paying the meter and call 999-999-9999 to report the problem. We will note and approve your alternate location and will investigate the cause of the shortage in your assigned facility.', is conveyed","convey some or all the answer text, 'Park at the nearest available parking meter without paying the meter and call 999-999-9999 to report the problem. We will note and approve your alternate location and will investigate the cause of the shortage in your assigned facility.'",div

tests/apg/disclosure-faq/data/references.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ designPattern,metadata,https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/,APG
77
example,metadata,https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-faq/,APG Example: Disclosure (Show/Hide) for Answers to Frequently Asked Questions
88
aria-expanded,aria,aria-expanded,aria-expanded
99
button,htmlAam,button,button
10-
generic,aria,generic,generic
10+
div,htmlAam,div,div
1111
ul,htmlAam,ul,ul

0 commit comments

Comments
 (0)