Skip to content

Commit 7c95de2

Browse files
committed
Support dynamic renaming for the aria and htmlAam support.json attributes for aria-at-app imports
1 parent fb175e0 commit 7c95de2

File tree

8 files changed

+70
-119
lines changed

8 files changed

+70
-119
lines changed

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,15 @@ const processTestDirectory = async config => {
496496
return v;
497497
}
498498

499-
function getExampleReferences(test, refs) {
499+
function getExampleReferences() {
500500
let links = '';
501501

502502
test.references.forEach(({ refId }) => {
503-
const { value: link, linkText } = refs[refId];
504-
505-
if (typeof link === 'string' && link.length) {
506-
links += `<link rel="help" href="${link}" title="${linkText}">\n`;
503+
const { value, linkText } = refs[refId];
504+
if (typeof value === 'string' && value.length) {
505+
links += `<link rel="help" href="${value}" title="${linkText}">\n`;
507506
}
508507
});
509-
510508
return links;
511509
}
512510

@@ -536,7 +534,7 @@ const processTestDirectory = async config => {
536534
const testPlanHtmlFileBuildPath = path.join(testPlanBuildDirectory, `${testFileName}.html`);
537535
const testPlanJsonFileBuildPath = path.join(testPlanBuildDirectory, `${testFileName}.json`);
538536

539-
const exampleReferences = getExampleReferences(test, refs);
537+
const exampleReferences = getExampleReferences();
540538
const scriptsContent = [...utils.addSetupScript(testId, test.setupScript.script)];
541539

542540
/** @type {AriaATFile.Behavior} */
@@ -613,7 +611,6 @@ const processTestDirectory = async config => {
613611
}
614612

615613
// Process CSV files
616-
const refs = utils.getRefs(referencesCsv);
617614
const indexOfURLs = [];
618615
const newTestPlan = newBuild.find(`tests/${path.basename(testPlanBuildDirectory)}`);
619616

@@ -648,10 +645,7 @@ const processTestDirectory = async config => {
648645
},
649646
commandsJson
650647
);
651-
const {
652-
references: { aria, htmlAam },
653-
} = supportJson;
654-
const referencesParsed = utils.parseReferencesCSV(referencesCsv, { aria, htmlAam });
648+
const referencesParsed = utils.parseReferencesCSV(referencesCsv);
655649

656650
const keyDefs = utils.getKeyDefs();
657651
const keysParsed = utils.parseKeyMap(keyDefs);
@@ -851,7 +845,7 @@ const processTestDirectory = async config => {
851845
log('Creating the following test files: ');
852846
testsParsed.forEach(function (testParsed, index) {
853847
try {
854-
const [url, applies_to_at] = createTestFile(testParsed, refs, atCommandsMap, {
848+
const [url, applies_to_at] = createTestFile(testParsed, referencesParsed, atCommandsMap, {
855849
emitFile,
856850
scriptsRecord,
857851
exampleScriptedFilesQueryable,

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

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -275,44 +275,6 @@ class Utils {
275275
});
276276
}
277277

278-
getRefs(referencesCsv) {
279-
const refs = {};
280-
281-
if (this.testFormatVersion === 1) {
282-
for (const row of referencesCsv) {
283-
refs[row.refId] = row.value.trim();
284-
}
285-
} else {
286-
for (const row of referencesCsv) {
287-
const {
288-
references: { aria, htmlAam },
289-
} = this.supportJson;
290-
291-
let refId = row.refId.trim();
292-
let type = row.type.trim();
293-
let value = row.value.trim();
294-
let linkText = row.linkText.trim();
295-
296-
if (type === 'aria') {
297-
value = `${aria.baseUrl}${aria.fragmentIds[value]}`;
298-
linkText = `${linkText} ${aria.linkText}`;
299-
}
300-
301-
if (type === 'htmlAam') {
302-
value = `${htmlAam.baseUrl}${htmlAam.fragmentIds[value]}`;
303-
linkText = `${linkText} ${htmlAam.linkText}`;
304-
}
305-
306-
refs[refId] = {
307-
type,
308-
value,
309-
linkText,
310-
};
311-
}
312-
}
313-
return refs;
314-
}
315-
316278
getScriptsJs(scriptsContent = []) {
317279
let js = 'let scripts = {\n';
318280
js += scriptsContent.join(',\n');
@@ -507,44 +469,30 @@ ${exampleReferences}
507469

508470
/**
509471
* @param {AriaATCSV.Reference[]} referenceRows
510-
* @param {AriaATCSV.SupportReference?} aria
511-
* @param {AriaATCSV.SupportReference?} htmlAam
512472
* @returns {AriaATParsed.ReferenceMap}
513473
*/
514-
parseReferencesCSV(referenceRows, { aria, htmlAam } = {}) {
515-
const refMap = {};
474+
parseReferencesCSV(referenceRows) {
475+
const refs = {};
516476

517477
if (this.testFormatVersion === 1) {
518-
for (const { refId, value } of referenceRows) {
519-
refMap[refId] = { refId, value: value.trim() };
478+
for (const row of referenceRows) {
479+
let refId = row.refId?.trim();
480+
let value = row.value?.trim();
481+
482+
refs[refId] = { refId, value };
520483
}
521484
} else {
522-
for (const {
523-
refId: _refId,
524-
type: _type,
525-
value: _value,
526-
linkText: _linkText,
527-
} of referenceRows) {
528-
let refId = _refId?.trim();
529-
let type = _type?.trim();
530-
let value = _value?.trim();
531-
let linkText = _linkText?.trim();
532-
533-
if (type === 'aria') {
534-
value = `${aria.baseUrl}${aria.fragmentIds[value]}`;
535-
linkText = `${linkText} ${aria.linkText}`;
536-
}
485+
for (const row of referenceRows) {
486+
let refId = row.refId?.trim();
487+
let type = row.type?.trim();
488+
let value = row.value?.trim();
489+
let linkText = row.linkText?.trim();
537490

538-
if (type === 'htmlAam') {
539-
value = `${htmlAam.baseUrl}${htmlAam.fragmentIds[value]}`;
540-
linkText = `${linkText} ${htmlAam.linkText}`;
541-
}
542-
543-
refMap[refId] = { refId, type, value, linkText };
491+
refs[refId] = { refId, type, value, linkText };
544492
}
545493
}
546494

547-
return refMap;
495+
return refs;
548496
}
549497

550498
// Miscellaneous

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

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

322322
function getExampleReferences() {
323-
const example = refs.example;
324323
let links = '';
325324

325+
const example = refs.example.value;
326326
if (typeof example === 'string' && example.length) {
327-
links += `<link rel="help" href="${refs.example}">\n`;
327+
links += `<link rel="help" href="${example}">\n`;
328328
}
329329

330-
let items = test.refs.split(' ');
331-
items.forEach(function (item) {
332-
item = item.trim();
333-
334-
if (item.length) {
335-
if (typeof refs[item] === 'string') {
336-
links += `<link rel="help" href="${refs[item]}">\n`;
330+
let refIds = test.refs.split(' ');
331+
refIds.forEach(refId => {
332+
refId = refId.trim();
333+
if (refId.length) {
334+
const { value } = refs[refId];
335+
if (typeof value === 'string') {
336+
links += `<link rel="help" href="${value}">\n`;
337337
} else {
338-
utils.addTestError(test.testId, 'Reference does not exist: ' + item);
338+
utils.addTestError(test.testId, 'Reference does not exist: ' + refId);
339339
}
340340
}
341341
});
342-
343342
return links;
344343
}
345344

@@ -450,7 +449,6 @@ const processTestDirectory = async config => {
450449
}
451450

452451
// Process CSV files
453-
const refs = utils.getRefs(referencesCsv);
454452
const indexOfURLs = [];
455453
const newTestPlan = newBuild.find(`tests/${path.basename(testPlanBuildDirectory)}`);
456454

@@ -590,7 +588,7 @@ const processTestDirectory = async config => {
590588
log('Creating the following test files: ');
591589
testsCsv.forEach(function (test) {
592590
try {
593-
const [url, applies_to_at] = createTestFile(test, refs, atCommandsMap, {
591+
const [url, applies_to_at] = createTestFile(test, referencesParsed, atCommandsMap, {
594592
emitFile,
595593
scriptsRecord,
596594
exampleScriptedFilesQueryable,

scripts/test-reviewer/createReviewPages.mjs

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

9090
// Get test plan's references.csv data
91-
const referencesData = getReferencesData(testPlanDirectory, aria, htmlAam);
91+
const referencesData = getReferencesData(testPlanDirectory);
9292
const referenceFromReferencesCSV = getReferenceForDirectory(referencesData, 'reference');
9393
const titleFromReferencesCSV = getReferenceForDirectory(referencesData, 'title');
9494

@@ -106,7 +106,11 @@ export function createReviewPages(config) {
106106
scripts.push(...scriptsData);
107107

108108
// Get test plan build directory's from `test-{xx}-{testId}.html` files data
109-
const collectedTestsData = getCollectedTestsData(testPlanBuildDirectory);
109+
const collectedTestsData = getCollectedTestsData(testPlanBuildDirectory, {
110+
referencesData,
111+
aria,
112+
htmlAam,
113+
});
110114
collectedTests.push(...collectedTestsData);
111115

112116
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
@@ -13,7 +13,6 @@ const generatePatternPages = ({
1313
allTestsForPattern,
1414
referencesForPattern,
1515
reviewBuildDirectory,
16-
testMode = false,
1716
}) => {
1817
patterns.forEach(pattern => {
1918
const references = referencesForPattern[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/support.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
},
282282
"htmlAam": {
283283
"baseUrl": "https://www.w3.org/TR/html-aam-1.0/",
284-
"linkText": "Accessibility API Mapping",
284+
"linkText": "HTML-AAM Specification",
285285
"fragmentIds": {
286286
"@abbr": "#att-abbr",
287287
"@accept": "#att-accept",

0 commit comments

Comments
 (0)