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

V2-maker Changes #990

Closed
wants to merge 7 commits into from
Closed
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
115 changes: 82 additions & 33 deletions scripts/v2maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ async function makeAssertionsCsvData(allInputCsvData) {
// Separate p1 and p2 assertions.
let p1assertions = assertions.filter(assertion => !assertion.includes('2:'));
let p2assertions = assertions.filter(assertion => assertion.includes('2:'));
// Remove the prefixes from the p2 assertions.
// Remove the prefixes from the assertions.
p1assertions = p1assertions.map(assertion => assertion.replace('1:', ''));
p2assertions = p2assertions.map(assertion => assertion.replace('2:', ''));
// Get rid of duplicates.
p1assertions = [...new Set(p1assertions)];
p2assertions = [...new Set(p2assertions)];
p1assertions = [...new Set(p1assertions.map(a => a.replace(/\s+/g, ' ').trim()))];
p2assertions = [...new Set(p2assertions.map(a => a.replace(/\s+/g, ' ').trim()))];
// Remove p1 assertions that are the same as a p2 assertion.
for (const p2assertion of p2assertions) {
if (p1assertions.includes(p2assertion)) {
Expand Down Expand Up @@ -326,7 +327,11 @@ async function makeTestsCsvData(allInputCsvData, assertionRows) {
if (colName.startsWith('assertion')) {
if (row[colName].trim() !== '') {
// Remove priority prefix if present.
const v1assertion = row[colName].replace('2:', '');
const v1assertion = row[colName]
.replace('1:', '')
.replace('2:', '')
.replace(/\s+/g, ' ')
.trim();
// get the v2 assertion Id and add it to the assertions string. Do lookups and comparisons using lowercase. Keeping the original case for the log in the event the assertion is not found.
if (assertionStatementsToIds.has(v1assertion.toLowerCase())) {
assertions += ` ${assertionStatementsToIds.get(v1assertion.toLowerCase())}`;
Expand Down Expand Up @@ -354,7 +359,7 @@ async function makeTestsCsvData(allInputCsvData, assertionRows) {
return 0;
});

/*
/*
We will be filtering testRows to keep only the rows for the VoiceOver tests. We want to get rid of all the tests that specify reading mode or interaction mode.
However, before removing those obsolete tests, there is some data we need to collect from them:
1. A map of all the v1 testIds to v2 testIds to use during conversion of commands.csv.
Expand All @@ -374,15 +379,21 @@ async function makeTestsCsvData(allInputCsvData, assertionRows) {
const v1tasks = new Set(allInputCsvData.v1tests.map(row => row.task));
// iterate through the tasks and compare the VoiceOver assertions to the the JAWS and NVDA assertions.
for (const task of v1tasks) {
// Find the v1testId for the VoiceOver test for this task in the v1testRows array.
const voiceOverV1TestId = allInputCsvData.v1tests.find(
let voiceOverV1TestId;
let voiceOverAssertions;
const voiceOverV1 = allInputCsvData.v1tests.find(
row => row.task === task && row.appliesTo.toLowerCase().includes('voiceover')
).testId;
// Use the v1testId to extract the VoiceOver assertions column for this task from the v2testRows. It contains a space-delimited set of assertionIds.
// Note that the v1testId was stored in the presentationNumber property in v2testRows.
const voiceOverAssertions = v2testRows.find(
row => row.presentationNumber === voiceOverV1TestId
).assertions;
);
if (voiceOverV1) {
// Find the v1testId for the VoiceOver test for this task in the v1testRows array.
voiceOverV1TestId = voiceOverV1.testId;

// Use the v1testId to extract the VoiceOver assertions column for this task from the v2testRows. It contains a space-delimited set of assertionIds.
// Note that the v1testId was stored in the presentationNumber property in v2testRows.
voiceOverAssertions = v2testRows.find(
row => row.presentationNumber === voiceOverV1TestId
).assertions;
}
// Get array of v1testIds for JAWS and NVDA for this task.
const jawsAndNvdaV1testIds = allInputCsvData.v1tests
.filter(row => row.task === task && row.appliesTo.toLowerCase().search(/jaws|nvda/) >= 0)
Expand All @@ -393,7 +404,7 @@ async function makeTestsCsvData(allInputCsvData, assertionRows) {
.assertions.split(' ');
let loggedWarnings = '';
for (const assertion of jawsAndNvdaAssertions) {
if (!voiceOverAssertions.includes(assertion)) {
if (voiceOverAssertions && !voiceOverAssertions.includes(assertion)) {
if (!loggedWarnings.includes(assertion)) {
const v2testId = v2testRows.find(row => row.presentationNumber === v1testId).testId;
const msg =
Expand All @@ -408,15 +419,41 @@ async function makeTestsCsvData(allInputCsvData, assertionRows) {
}
}

// Now filter v2testRows down to just the VoiceOver rows.
// Now filter v2testRows down to just the VoiceOver rows (because they don't
// specify the reading or interaction mode).
// First, get an array of just the voiceOver rows from v1tests.
const v1voiceOverRows = allInputCsvData.v1tests.filter(row =>
row.appliesTo.toLowerCase().includes('voiceover')
);
// Build a set of the v1 testIds for the VoiceOver tests.
const voiceOverV1testIds = new Set(v1voiceOverRows.map(row => row.testId));
// Filter v2testRows. Note that the presentationNumber property contains the v1testId.
v2testRows = v2testRows.filter(row => voiceOverV1testIds.has(row.presentationNumber));
const v2voiceOverTestRows = v2testRows.filter(row =>
voiceOverV1testIds.has(row.presentationNumber)
);

// Needs to also cover cases where there are tests which have no matching
// voiceover tests (for jaws, nvda). Eg. form test 19 and 20 from v1
const v2uniqueVoiceOverTestIds = v2voiceOverTestRows.map(({ testId }) => testId);
const unhandledV2testRows = v2testRows.filter(
row => !v2uniqueVoiceOverTestIds.includes(row.testId)
);

const v2uniqueNonVoiceOverTestRows = [];
const v2NonVoiceOverFoundTestIds = new Set();

for (const row of unhandledV2testRows) {
if (!v2NonVoiceOverFoundTestIds.has(row.testId)) {
v2uniqueNonVoiceOverTestRows.push({
...row,
// Need to manually update these instances
title: row.title.replace('in reading mode', '').replace('in interaction mode', '').trim(),
instructions: row.instructions.replace('the reading cursor', 'focus'),
});
v2NonVoiceOverFoundTestIds.add(row.testId);
}
}
v2testRows = [...v2voiceOverTestRows, ...v2uniqueNonVoiceOverTestRows];

// Write rows to CSV file
const rowWriter = createCsvWriter({
Expand All @@ -430,7 +467,7 @@ async function makeTestsCsvData(allInputCsvData, assertionRows) {
}

async function makeCommandsCsvData(allInputCsvData, v1ToV2testIds) {
/*
/*
The V1 columns are:
testId,task,mode,at,commandA,commandB,commandC...
The V2 columns are:
Expand Down Expand Up @@ -479,22 +516,34 @@ async function makeCommandsCsvData(allInputCsvData, v1ToV2testIds) {

// Make a new row for each command.
for (const [index, command] of commands.entries()) {
let newRow = {};
newRow.testId = v1ToV2testIds.get(row.testId);
const { commandSequence, commandSettings } = util.translateCommand(
screenReader,
command,
allInputCsvData.commandSubstitutions
);
newRow.command = commandSequence;
if (commandSettings.trim() !== '') newRow.settings = commandSettings;
else if (row.mode.toLowerCase().includes('reading')) newRow.settings = readingModeSetting;
else if (row.mode.toLowerCase().includes('interaction'))
newRow.settings = interactionModeSetting;
else newRow.settings = '';
newRow.assertionExceptions = '';
newRow.presentationNumber = (Number(row.testId) + 0.1 * index).toFixed(1);
v2commandRows.push(newRow);
let splitValue = ' ';
// Create additional rows in the instance of `commandSeq1 / commandSeq2`.
// For eg. F / Shift + F and is defined as F_AND_SHIFT_F in keys.mjs
if (command.includes('_AND_')) splitValue = '_AND_';
// Create additional rows in the instance of `commandSeq1 (or commandSeq2)`.
// For eg. Insert+F7 (or CapsLock+F7) and is defined as INS_F7_OR_CAPS_F7 in keys.mjs
if (command.includes('_OR_')) splitValue = '_OR_';

for (const [_index, _command] of command.split(splitValue).entries()) {
let newRow = {};
newRow.testId = v1ToV2testIds.get(row.testId);
const { commandSequence, commandSettings } = util.translateCommand(
screenReader,
_command,
allInputCsvData.commandSubstitutions
);
newRow.command = commandSequence;
if (commandSettings.trim() !== '') newRow.settings = commandSettings.trim();
else if (row.mode.toLowerCase().includes('reading')) newRow.settings = readingModeSetting;
else if (row.mode.toLowerCase().includes('interaction'))
newRow.settings = interactionModeSetting;
else newRow.settings = '';
newRow.assertionExceptions = '';
const isAdditionalCommand = command.includes(splitValue);
const control = isAdditionalCommand ? index + index : index;
newRow.presentationNumber = (Number(row.testId) + 0.1 * (control + _index)).toFixed(1);
v2commandRows.push(newRow);
}
}
}

Expand Down
17 changes: 16 additions & 1 deletion scripts/v2makerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,22 @@ function translateCommand(screenReader, commandSequence, substitutions) {
commandSequence = newCommandSequence.join(' ');
if (newCommandSettings.length > 0) commandSettings = newCommandSettings.join(' ');
}
commandSequence = commandSequence.replaceAll('_', '+');
commandSequence = commandSequence
.replaceAll('_', '+')
.replaceAll('one', '1')
.replaceAll('two', '2')
.replaceAll('caps', 'capsLock')
.replaceAll('page+up', 'pageUp')
.replaceAll('page+down', 'pageDown')
.replaceAll('numpad+5', 'numpad5')
.replaceAll('numpad+6', 'numpad6')
.replaceAll('UP', 'up')
.replaceAll('DOWN', 'down')
.replaceAll('LEFT', 'left')
.replaceAll('RIGHT', 'right')
.replaceAll('+then+', ' ')
.replaceAll('(with smart navigation on)', '')
.trim();
return { commandSequence, commandSettings };
}

Expand Down
12 changes: 6 additions & 6 deletions tests/support.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"virtualCursor": {
"screenText": "virtual cursor active",
"instructions": [
"Press <kbd>Alt</kbd>+<kbd>Delete </kbd> to determine which cursor is active.",
"Press <kbd>Alt</kbd>+<kbd>Delete</kbd> to determine which cursor is active.",
"If the PC cursor is active, press <kbd>Escape</kbd> to activate the virtual cursor."
]
},
Expand All @@ -39,15 +39,15 @@
"browseMode": {
"screenText": "browse mode on",
"instructions": [
"Press <kbd>insert</kbd>+<kbd>Space</kbd>.",
"If NVDA made the focus mode sound , press <kbd>Insert</kbd>+<kbd>Space</kbd> again to turn browse mode back on."
"Press <kbd>Insert</kbd>+<kbd>Space</kbd>.",
"If NVDA made the focus mode sound, press <kbd>Insert</kbd>+<kbd>Space</kbd> again to turn browse mode back on."
]
},
"focusMode": {
"screenText": "focus mode on",
"instructions": [
"Press <kbd>insert</kbd>+<kbd>Space</kbd>.",
"If NVDA made the browse mode sound , press <kbd>Insert</kbd>+<kbd>Space</kbd> again to turn focus mode back on."
"Press <kbd>Insert</kbd>+<kbd>Space</kbd>.",
"If NVDA made the browse mode sound, press <kbd>Insert</kbd>+<kbd>Space</kbd> again to turn focus mode back on."
]
}
}
Expand Down Expand Up @@ -407,4 +407,4 @@
}
}
}
}
}