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

Support assertionExceptions without priority prefix #1053

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions lib/data/parse-command-csv-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

'use strict';

const { setDefaultAssertionPriority } = require('../util/assertion-exception');

/**
* @param {AriaATCSV.Command} commandRow
* @returns {AriaATParsed.Command}
Expand Down Expand Up @@ -186,7 +188,7 @@ function findValuesByKeys(commandsMapping, keysToFind = []) {
return result;
}

function parseCommandCSVRowV2({ commands }, commandsJson) {
function parseCommandCSVRowV2({ commands }, commandsJson, assertions) {
const commandsParsed = [];
const flattenedCommandsJson = flattenObject(commandsJson);

Expand All @@ -195,7 +197,10 @@ function parseCommandCSVRowV2({ commands }, commandsJson) {
const commandKVs = findValuesByKeys(flattenedCommandsJson, [command.command]);

const assertionExceptions = command.assertionExceptions.length
? sanitizeWhitespace(command.assertionExceptions).split(' ')
? setDefaultAssertionPriority(
sanitizeWhitespace(command.assertionExceptions),
assertions
).split(' ')
: [];

const commands = commandKVs.map(e => ({
Expand Down
8 changes: 7 additions & 1 deletion lib/data/parse-test-csv-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

'use strict';

const { setDefaultAssertionPriority } = require('../util/assertion-exception');

/**
* @param {AriaATCSV.Test} testRow
* @returns {AriaATParsed.Test}
Expand Down Expand Up @@ -216,12 +218,16 @@ function parseTestCSVRowV2({ tests, assertions, scripts, commands }) {
at => at.key === key && at.settings === (command.settings || 'defaultMode')
)
) {
const assertionExceptions = setDefaultAssertionPriority(
command.assertionExceptions,
assertions
);
const commandInfo = {
testId: command.testId,
command: command.command,
settings: command.settings || 'defaultMode',
presentationNumber: Number(command.presentationNumber),
assertionExceptions: command.assertionExceptions,
assertionExceptions: assertionExceptions,
};

// Test level commandInfo, useful for getting assertionExceptions and
Expand Down
5 changes: 3 additions & 2 deletions lib/data/process-test-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const processTestDirectory = async ({ directory, args = {} }) => {
const validCommandKeys = /^(?:testId|command|settings|assertionExceptions|presentationNumber)$/;
const numericKeyFormat = /^_(\d+)$/;
const idFormat = /^[A-Za-z0-9-]+$/;
const assertionsExceptionsFormat = /^([0123]:[a-zA-Z-\d]+\s*)+$/;
const assertionsExceptionsFormat = /^(([0123]:)?[a-zA-Z-\d]+\s*)+$/;
const settingsFormat = /^[A-Za-z0-9-\s]+$/;
function validateCommandsKeys(row) {
// example header:
Expand Down Expand Up @@ -847,7 +847,8 @@ ${rows}
{
commands: parsedAtCommandsCsvs,
},
commandsJson
commandsJson,
assertionsCsv
);
const {
references: { aria, htmlAam },
Expand Down
38 changes: 38 additions & 0 deletions lib/util/assertion-exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Generates the assertionException string with a default priority prefix
* @param {String} assertionException
* @param {Number} defaultPriority
* @returns {String}
*/
function setDefaultAssertionException(assertionException, defaultPriority) {
if (assertionException && !assertionException.includes(':')) {
return `${defaultPriority}:${assertionException}`;
}
return assertionException;
}

/**
* Finds the default assertion value for an assertionException without
* a priority prefix in a string of assertionExceptions and recreates
* the string with the new default assertion priorities
* @param {String} assertionExceptions
* @param {Array} assertions
* @returns {String}
*/
function setDefaultAssertionPriority(assertionExceptions, assertions) {
return assertionExceptions
.split(' ')
.map(assertionException => {
const assertion = assertions.find(assertion =>
assertionException.includes(assertion.assertionId)
);
if (assertion) {
const defaultPriority = assertion.priority;
return setDefaultAssertionException(assertionException, defaultPriority);
}
return assertionException;
})
.join(' ');
}

exports.setDefaultAssertionPriority = setDefaultAssertionPriority;
Loading