Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Prune unnecessary code and do renames for posterity #1180

Draft
wants to merge 8 commits into
base: fix-1002
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,248 changes: 624 additions & 624 deletions __test__/__snapshots__/createAllTests.test.js.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/data/parse-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function parseSupport(supportRaw) {
return {
ats: supportRaw.ats,
atGroups: [
...Object.entries(supportRaw.applies_to).map(([name, value]) => ({
...Object.entries(supportRaw.appliesTo).map(([name, value]) => ({
key: name.toLowerCase(),
name,
ats: value.map(key => supportRaw.ats.find(at => at.key === key) || { key }),
Expand Down
78 changes: 38 additions & 40 deletions lib/data/process-test-directory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ const processTestDirectory = async config => {
const allAts = supportJson.ats;
const allAtKeys = allAts.map(({ key }) => key);
const allAtNames = allAts.map(({ name }) => name);
const atSettings = allAts
const allAtSettings = allAts
.map(({ settings }) => settings)
.flatMap(setting => Object.keys(setting));

// readingMode and interactionMode are known screen reader 'at modes' found in
// support.json at ats[].assertionTokens. The specific named modes are
// readingMode and interactionMode are known screen reader 'at settings' found in
// support.json at ats[].assertionTokens. The specific named settings are
// stored in ats[].settings
const validModes = ['readingMode', 'interactionMode', 'defaultMode'].concat(atSettings);
const knownSettings = ['readingMode', 'interactionMode', 'defaultMode'].concat(allAtSettings);

utils.checkForMissingPath(testPlanRecord, 'directory', { path: testPlanDirectory });
utils.checkForMissingPath(testPlanRecord, 'file', {
Expand Down Expand Up @@ -373,7 +373,7 @@ const processTestDirectory = async config => {
* @param {object} options
* @param {function(filePath: string, content: any, encoding: string)} options.emitFile
* @param {FileRecordChain} options.scriptsRecord
* @param {Queryable<T>} options.exampleScriptedFilesQueryable
* @param {Queryable<{name: string, path: string, content: string}>} options.exampleScriptedFilesQueryable
* @returns {(string|*[])[]}
*/
function createTestFile(
Expand All @@ -397,9 +397,9 @@ const processTestDirectory = async config => {
return testId;
}

function getModeValue({ settings }) {
function getSettingsValues({ settings }) {
let v = settings.trim().split(' ');
if (!v.every(el => validModes.includes(el))) {
if (!v.every(el => knownSettings.includes(el))) {
utils.addTestError(
test.testId,
'"' +
Expand All @@ -426,7 +426,7 @@ const processTestDirectory = async config => {

// Prepare file name descriptors
let testId = getTestId(test.testId);
let modes = test.target.ats.map(getModeValue).join('_');
let joinedSettings = test.target.ats.map(getSettingsValues).join('_');

test.target.ats.forEach(at => {
if (atCommandsMap[testId]) {
Expand All @@ -435,7 +435,7 @@ const processTestDirectory = async config => {
testId,
'command is missing for the combination of task: "' +
testId +
'", mode: "' +
'", settings: "' +
atCommandsMap[testId][at.settings] +
'", and AT: "' +
at.key.toLowerCase() +
Expand All @@ -456,13 +456,13 @@ const processTestDirectory = async config => {
/** @type {AriaATFile.Behavior} */
let testData = {
task: testId,
mode: modes,
applies_to: [...new Set(test.target.ats.map(({ key }) => key))],
setup_script_description: getSetupScriptDescription(test.setupScript.scriptDescription),
specific_user_instruction: test.instructions,
mode: joinedSettings,
appliesTo: [...new Set(test.target.ats.map(({ key }) => key))],
setupScriptDescription: getSetupScriptDescription(test.setupScript.scriptDescription),
specificUserInstruction: test.instructions,
setupTestPage: test.setupScript.script,
testPlanStrings: supportJson.testPlanStrings,
output_assertions: test.assertions,
outputAssertions: test.assertions,
commandsInfo: test.commandsInfo,
};

Expand All @@ -482,10 +482,10 @@ const processTestDirectory = async config => {
emitFile(testPlanJsonFileBuildPath, JSON.stringify(testData, null, 2), 'utf8');
emitFile(testPlanHtmlFileBuildPath, testHtml, 'utf8');

const applies_to_at = [];
allAtKeys.forEach(at => applies_to_at.push(testData.applies_to.indexOf(at) >= 0));
const appliesToAt = [];
allAtKeys.forEach(at => appliesToAt.push(testData.appliesTo.indexOf(at) >= 0));

return [testFileName, applies_to_at];
return [testFileName, appliesToAt];
}

/**
Expand All @@ -498,7 +498,7 @@ const processTestDirectory = async config => {
* @param {object} tasks.script
* @param {string} tasks.script.script
* @param {string} tasks.script.scriptDescription
* @param {boolean[]} tasks.applies_to_at
* @param {boolean[]} tasks.appliesToAt
* @param {object} options
* @param {function(filePath: string, content: any, encoding: string)} options.emitFile
*/
Expand All @@ -512,7 +512,7 @@ const processTestDirectory = async config => {
rows += `<td>${task.id}</td>`;
rows += `<td scope="row">${task.title}</td>`;
for (let i = 0; i < allAtKeys.length; i++) {
if (task.applies_to_at[i]) {
if (task.appliesToAt[i]) {
rows += `<td class="test"><a href="${task.href}.html?at=${allAtKeys[i]}" aria-label="${allAtNames[i]} test for task ${task.id}">${allAtNames[i]}</a></td>`;
} else {
rows += `<td class="test none">not included</td>`;
Expand Down Expand Up @@ -597,14 +597,14 @@ const processTestDirectory = async config => {

const testLookups = {
command: Queryable.from('command', commandsValidated),
mode: Queryable.from('mode', validModes),
settings: Queryable.from('settings', knownSettings),
script: Queryable.from('script', scriptsSource),
reference: referenceQueryable,
support: supportQueryables,
};
const testsValidated = testsParsed.map(test =>
validateTest(test, testLookups, {
addTestError: utils.addTestError.bind(null, test.testId),
const testsValidated = testsParsed.map(testParsed =>
validateTest(testParsed, testLookups, {
addTestError: utils.addTestError.bind(null, testParsed.testId),
})
);

Expand Down Expand Up @@ -650,8 +650,7 @@ const processTestDirectory = async config => {
testId: test.testId,
target: { at: { key, settings } },
}),
reference: referenceQueryable,
supportAt: supportQueryables.ats,
supportAts: supportQueryables.ats,
example: exampleScriptedFilesQueryable,
modeInstructionTemplate: utils.MODE_INSTRUCTION_TEMPLATES_QUERYABLE(supportJson),
})
Expand Down Expand Up @@ -719,7 +718,7 @@ const processTestDirectory = async config => {
...common,
instructions: {
...common.instructions,
mode: settingsResult, // TODO: Replace 'mode' references with 'settings'
mode: settingsResult,
},
commands: common.commands.map(command => ({
...command,
Expand Down Expand Up @@ -794,7 +793,7 @@ const processTestDirectory = async config => {
log('Creating the following test files: ');
testsParsed.forEach(function (testParsed, index) {
try {
const [url, applies_to_at] = createTestFile(testParsed, refs, atCommandsMap, {
const [url, appliesToAt] = createTestFile(testParsed, refs, atCommandsMap, {
emitFile,
scriptsRecord,
exampleScriptedFilesQueryable,
Expand All @@ -806,7 +805,7 @@ const processTestDirectory = async config => {
title: testParsed.title,
href: url,
script: testParsed.setupScript,
applies_to_at: applies_to_at,
appliesToAt: appliesToAt,
});

log('[Test ' + testParsed.testId + ']: ' + url);
Expand Down Expand Up @@ -855,7 +854,7 @@ exports.processTestDirectory = processTestDirectory;
* @param {object} data
* @param {Queryable<AriaATParsed.Key>} data.key
* @param {object} data.support
* @param {Queryable<{key: string, name: string}>} data.support.at
* @param {Queryable<{key: string, name: string}>} data.support.ats
* @param {object} options
* @param {function(AriaATParsed.Command, string): void} options.addCommandError
* @param {function(AriaATParsed.Command, string): void} options.addCommandAssertionExceptionError
Expand Down Expand Up @@ -922,13 +921,12 @@ function validateCommand(
* @param {AriaATParsed.Test} testParsed
* @param {object} data
* @param {Queryable<AriaATParsed.Command>} data.command
* @param {Queryable<AriaATParsed.Key>} data.key
* @param {Queryable<string>} data.mode
* @param {Queryable<AriaATParsed.Reference>} data.reference
* @param {Queryable<string>} data.settings
* @param {Queryable<AriaATParsed.ScriptSource>} data.script
* @param {Queryable<AriaATParsed.Reference>} data.reference
* @param {object} data.support
* @param {Queryable<{key: string, name: string}>} data.support.at
* @param {Queryable<{key: string, name: string}>} data.support.atGroups
* @param {Queryable<{key: string, name: string}>} data.support.ats
* @param {Queryable<Object[]>} data.support.atGroups
* @param {object} [options]
* @param {function(string): void} [options.addTestError]
* @returns {AriaATValidated.Test}
Expand Down Expand Up @@ -957,14 +955,14 @@ function validateTest(testParsed, data, { addTestError = () => {} } = {}) {
})
) {
addTestError(
`command is missing for the combination of task: "${testParsed.testId}", mode: "${at.settings}", and AT: "${at.key}"`
`command is missing for the combination of task: "${testParsed.testId}", settings: "${at.settings}", and AT: "${at.key}"`
);
}
});

testParsed.target.ats.forEach(at => {
at.settings.split(' ').forEach(setting => {
if (!data.mode.where(setting)) {
if (!data.settings.where(setting)) {
addTestError(`"${at.settings}" is not valid value for "settings" property.`);
}
});
Expand Down Expand Up @@ -1093,12 +1091,12 @@ function validateTest(testParsed, data, { addTestError = () => {} } = {}) {
* @param {object} data
* @param {AriaATValidated.Test} data.test
* @param {AriaATValidated.Command} data.command
* @param {Queryable<{screenText: string, instructions: [string]}>} data.supportAt
* @param {Queryable<{name: string, path: string}>} data.example
* @param {Queryable<{key: string}>} data.supportAts
* @param {Queryable<{name: string}>} data.example
* @param {Queryable<{at: string, mode: string, render: function({key: *}): string}>} data.modeInstructionTemplate
* @returns {AriaATFile.CollectedTest}
*/
function collectTestData({ test, command, supportAt, example, modeInstructionTemplate }) {
function collectTestData({ test, command, supportAts, example, modeInstructionTemplate }) {
return {
info: {
testId: test.testId,
Expand All @@ -1108,7 +1106,7 @@ function collectTestData({ test, command, supportAt, example, modeInstructionTem
},
target: {
...test.target,
at: { ...command.target.at, raw: supportAt.where({ key: command.target.at.key }) },
at: { ...command.target.at, raw: supportAts.where({ key: command.target.at.key }) },
referencePage: example.where({ name: test.setupScript ? test.setupScript.name : '' }).path,
setupScript: test.setupScript,
},
Expand Down
11 changes: 9 additions & 2 deletions lib/data/process-test-directory/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ ${exampleReferences}
checkForMissingPath(
record,
typeCheck,
{ path, fileName, shortenedFilePath, customMessage } = {}
{ path, fileName = '', shortenedFilePath = '', customMessage = '' } = {}
) {
if (typeCheck === 'directory') {
if (!record.isDirectory()) {
Expand Down Expand Up @@ -732,6 +732,13 @@ ${exampleReferences}
}
}

/**
* @param {string} name
* @param {function(string): string} examplePathTemplate
* @param {{render: function({script: Lines | string, button: Lines | string}): string}} exampleTemplate
* @param {string} source
* @returns {{name: string, path: string, content: string}}
*/
function createExampleScriptedFile(name, examplePathTemplate, exampleTemplate, source) {
return {
name,
Expand All @@ -741,7 +748,7 @@ function createExampleScriptedFile(name, examplePathTemplate, exampleTemplate, s
}

/**
* @param {AriaATFile.ScriptSource[]} scripts
* @param {AriaATParsed.ScriptSource[]} scripts
* @param {string} testPlanBuildDirectory
* @returns {{path: string, content: Uint8Array}[]}
*/
Expand Down
20 changes: 10 additions & 10 deletions lib/data/process-test-directory/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ const processTestDirectory = async config => {
let testData = {
task: task,
mode: mode,
applies_to: appliesTo,
setup_script_description: getSetupScriptDescription(test.setupScriptDescription),
specific_user_instruction: test.instructions,
appliesTo: appliesTo,
setupScriptDescription: getSetupScriptDescription(test.setupScriptDescription),
specificUserInstruction: test.instructions,
setupTestPage: test.setupScript,
testPlanStrings: supportJson.testPlanStrings,
output_assertions: assertions,
outputAssertions: assertions,
};

const testHtml = utils.getTestHtml({
Expand All @@ -415,10 +415,10 @@ const processTestDirectory = async config => {
emitFile(testPlanJsonFileBuildPath, JSON.stringify(testData, null, 2), 'utf8');
emitFile(testPlanHtmlFileBuildPath, testHtml, 'utf8');

const applies_to_at = [];
allAtKeys.forEach(at => applies_to_at.push(testData.applies_to.indexOf(at) >= 0));
const appliesToAt = [];
allAtKeys.forEach(at => appliesToAt.push(testData.appliesTo.indexOf(at) >= 0));

return [testFileName, applies_to_at];
return [testFileName, appliesToAt];
}

/**
Expand All @@ -435,7 +435,7 @@ const processTestDirectory = async config => {
rows += `<tr><td>${task.id}</td>`;
rows += `<td scope="row">${task.title}</td>`;
for (let i = 0; i < allAtKeys.length; i++) {
if (task.applies_to_at[i]) {
if (task.appliesToAt[i]) {
rows += `<td class="test"><a href="${task.href}?at=${allAtKeys[i]}" aria-label="${allAtNames[i]} test for task ${task.id}">${allAtNames[i]}</a></td>`;
} else {
rows += `<td class="test none">not included</td>`;
Expand Down Expand Up @@ -590,7 +590,7 @@ const processTestDirectory = async config => {
log('Creating the following test files: ');
testsCsv.forEach(function (test) {
try {
const [url, applies_to_at] = createTestFile(test, refs, atCommandsMap, {
const [url, appliesToAt] = createTestFile(test, refs, atCommandsMap, {
emitFile,
scriptsRecord,
exampleScriptedFilesQueryable,
Expand All @@ -601,7 +601,7 @@ const processTestDirectory = async config => {
title: test.title,
href: url,
script: test.setupScript,
applies_to_at: applies_to_at,
appliesToAt: appliesToAt,
});

log('[Test ' + test.testId + ']: ' + url);
Expand Down
1 change: 1 addition & 0 deletions lib/data/templates/collected-test.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { reindent } = require('../../util/lines');

/**
* @param {AriaATFile.CollectedTest} test
* @param {string} testFileName
* @returns {string}
*/
function renderHTML(test, testFileName) {
Expand Down
10 changes: 5 additions & 5 deletions scripts/test-reviewer/createReviewPages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ export function createReviewPages(config) {
const atTests = [];

const openExampleInstructions =
unescapeHTML(openExampleInstruction) + ' ' + testData.setup_script_description + '.';
unescapeHTML(openExampleInstruction) + ' ' + testData.setupScriptDescription + '.';

// TODO: applies_to strings are not standardized yet.
// TODO: appliesTo strings are not standardized yet.
let allRelevantATs =
testData.applies_to[0].toLowerCase() === 'desktop screen readers' ||
testData.applies_to[0].toLowerCase() === 'screen readers'
testData.appliesTo[0].toLowerCase() === 'desktop screen readers' ||
testData.appliesTo[0].toLowerCase() === 'screen readers'
? allATKeys
: testData.applies_to;
: testData.appliesTo;
// To remove potential duplicates
allRelevantATs = [...new Set(allRelevantATs)];

Expand Down
Loading
Loading