Skip to content

Commit

Permalink
build: added accessibility tests (CMC-1487) (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd-dudkiewicz authored May 20, 2021
1 parent 1d49742 commit 0a21fa0
Show file tree
Hide file tree
Showing 58 changed files with 11,541 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.min.js
node_modules/*

35 changes: 18 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
module.exports = {
"plugins": [
"codeceptjs"
'plugins': [
'codeceptjs'
],
"env": {
"browser": true,
"commonjs": true,
"es2020": true,
"codeceptjs/codeceptjs": true
'env': {
'browser': true,
'commonjs': true,
'es2020': true,
'codeceptjs/codeceptjs': true,
'node': true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 11
'extends': 'eslint:recommended',
'parserOptions': {
'ecmaVersion': 11
},
"rules": {
"quotes": [
"error",
"single"
'rules': {
'quotes': [
'error',
'single'
],
"semi": [
"error",
"always"
'semi': [
'error',
'always'
]
}
};
5 changes: 3 additions & 2 deletions codecept.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global process */

exports.config = {
tests: './e2e/tests/*_test.js',
output: './output',
Expand All @@ -17,6 +15,9 @@ exports.config = {
PuppeteerHelpers: {
require: './e2e/helpers/puppeteer_helper.js',
},
GenerateReportHelper: {
require: './e2e/helpers/generate_report_helper.js'
},
},
include: {
I: './e2e/steps_file.js',
Expand Down
6 changes: 3 additions & 3 deletions e2e/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*global process*/

const defaultPassword = 'Password12!';

module.exports = {
Expand Down Expand Up @@ -37,5 +35,7 @@ module.exports = {
definition: {
jurisdiction: 'CIVIL',
caseType: 'CIVIL',
}
},
TestOutputDir: process.env.E2E_OUTPUT_DIR || './output',
TestForAccessibility: process.env.TESTS_FOR_ACCESSIBILITY === 'true',
};
1 change: 1 addition & 0 deletions e2e/fragments/confirmDetails.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {

async confirmReference() {
I.waitForElement(this.fields.solicitorReferences.id);
await I.runAccessibilityTest();
I.fillField(this.fields.solicitorReferences.id, 'Defendant Reference ++');
await I.clickContinue();
}
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {

async enterDate(fieldId = '', plusDays = 28) {
I.waitForElement(this.fields(fieldId).day);
await I.runAccessibilityTest();
const date = new Date();
date.setDate(date.getDate() + plusDays);
I.fillField(this.fields(fieldId).day, date.getDate());
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/disclosureOfElectrionicDocuments.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {

async enterDisclosureOfElectronicDocuments(party) {
I.waitForElement(this.fields(party).reachedAgreement.id);
await I.runAccessibilityTest();
await within(this.fields(party).reachedAgreement.id, () => {
I.click(this.fields(party).reachedAgreement.options.no);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {

async enterDirectionsProposedForDisclosure(party) {
I.waitForElement(this.fields(party).directionsForDisclosureProposed.id);
await I.runAccessibilityTest();
await within(this.fields(party).directionsForDisclosureProposed.id, () => {
I.click(this.fields(party).directionsForDisclosureProposed.options.yes);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/disclosureReport.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {

async enterDisclosureReport(party) {
I.waitForElement(this.fields(party).disclosureFormFiledAndServed.id);
await I.runAccessibilityTest();
await within (this.fields(party).disclosureFormFiledAndServed.id, () => {
I.click(this.fields(party).disclosureFormFiledAndServed.options.yes);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/draftDirections.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {

async upload(party, file) {
I.waitForElement(this.fields(party).draftDirections);
await I.runAccessibilityTest();
await I.attachFile(this.fields(party).draftDirections, file);
await I.waitForInvisible(locate('.error-message').withText('Uploading...'));

Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/experts.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {

async enterExpertInformation(party) {
I.waitForElement(this.fields(party).expertRequired.id);
await I.runAccessibilityTest();
await within(this.fields(party).expertRequired.id, () => {
I.click(this.fields(party).expertRequired.options.yes);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/fileDirectionsQuestionnaire.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {

async fileDirectionsQuestionnaire(party) {
I.waitForElement(this.fields(party).explainedToClient.id);
await I.runAccessibilityTest();
I.checkOption(this.fields(party).explainedToClient.options.confirm);

await within(this.fields(party).oneMonthStay.id, () => {
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/furtherInformation.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {

async enterFurtherInformation(party) {
I.waitForElement(this.fields(party).futureApplications.id);
await I.runAccessibilityTest();
await within(this.fields(party).futureApplications.id, () => {
I.click(this.fields(party).futureApplications.options.yes);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/hearing.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = {

async enterHearingInformation(party) {
I.waitForElement(this.fields(party).hearingLength.id);
await I.runAccessibilityTest();
await within(this.fields(party).hearingLength.id, () => {
I.click(this.fields(party).hearingLength.options.lessThanOneDay);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/hearingSupportRequirements.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {

async selectRequirements(party) {
I.waitForElement(this.fields(party).requirements.options.disabledAccess);
await I.runAccessibilityTest();
I.checkOption(this.fields(party).requirements.options.signLanguage);
I.checkOption(this.fields(party).requirements.options.languageInterpreter);
I.checkOption(this.fields(party).requirements.options.other);
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/language.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {

async enterWelshLanguageRequirements(party) {
I.waitForElement(this.fields(party).evidence.id);
await I.runAccessibilityTest();

I.click(this.fields(party).evidence.options.welsh);
I.click(this.fields(party).court.options.welsh);
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/requestedCourt.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {

async selectSpecificCourtForHearing(party) {
I.waitForElement(this.fields(party).requestHearingAtSpecificCourt.id);
await I.runAccessibilityTest();
await within(this.fields(party).requestHearingAtSpecificCourt.id, () => {
I.click(this.fields(party).requestHearingAtSpecificCourt.options.yes);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/dq/witnesses.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {

async enterWitnessInformation(party) {
I.waitForElement(this.fields(party).witnessesToAppear.id);
await I.runAccessibilityTest();
await within(this.fields(party).witnessesToAppear.id, () => {
I.click(this.fields(party).witnessesToAppear.options.yes);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {

async submit(buttonText, expectedMessage) {
I.waitForText(buttonText);
await I.runAccessibilityTest();
await I.retryUntilExists(() => I.click(buttonText), CONFIRMATION_HEADER);
await within(CONFIRMATION_HEADER, () => {
I.see(expectedMessage);
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/party.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {

async enterParty(partyType, address) {
I.waitForElement(this.fields(partyType).type.id);
await I.runAccessibilityTest();
await within(this.fields(partyType).type.id, () => {
I.click(this.fields(partyType).type.options.company);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/respondentDetails.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {

async verifyDetails() {
I.waitForElement(this.fields.respondentDetails.id);
await I.runAccessibilityTest();
await I.see('Example company');

await I.clickContinue();
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/servedDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {I} = inject();
module.exports = {

async upload(file, documents) {
await I.runAccessibilityTest();
for (const fileType of documents) {
await within(fileType, async () => {
I.click('Add new');
Expand Down
1 change: 1 addition & 0 deletions e2e/fragments/statementOfTruth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {

async enterNameAndRole(type = '', name = 'John Smith', role = 'Solicitor') {
I.waitForElement(this.fields[type].name);
await I.runAccessibilityTest();
I.fillField(this.fields[type].name, name);
I.fillField(this.fields[type].role, role);
await I.clickContinue();
Expand Down
87 changes: 87 additions & 0 deletions e2e/helpers/accessibility/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const HTMLCS = require('html_codesniffer');
const fs = require('fs');
const testConfig = require('../../config.js');

const result = {
PASSED: 'passed',
FAILED: 'failed',
};

const resultObj = {
appName: 'Civil',
passCount: 0,
failCount: 0,
tests: [],
};

async function runAccessibility(url, page) {
//Add HMTL code sniffer script
await page.addScriptTag({
path: 'node_modules/html_codesniffer/build/HTMLCS.js',
});

const screenshotPath = testConfig.TestOutputDir + '/assets';
const screenshotName = Date.now() + '.png';
const screenshotReportRef = 'assets/' + screenshotName;

const accessibilityErrorsOnThePage = await page.evaluate(() => {
const processIssue = function(issue) {
return {
code: issue.code,
message: issue.msg,
type: 'error',
element: issue.element,
runner: 'htmlcs',
};
};

const STANDARD = 'WCAG2AA';
let messages;

HTMLCS.process(STANDARD, window.document, function () {
messages = HTMLCS
.getMessages()
.filter(function (m) {
return m.type === HTMLCS.ERROR;
})
.map(processIssue);
});
return messages;
});

try {
await page.screenshot({path: screenshotPath + '/' + screenshotName, fullPage: true});
} catch (err) {
fs.mkdirSync(screenshotPath, {recursive: true});
await page.screenshot({path: screenshotPath + '/' + screenshotName, fullPage: true});
}

updateResultObject(url, await page.title(), screenshotReportRef, accessibilityErrorsOnThePage);
}

function updateResultObject(url, pageTitle, screenshotReportRef, accessibilityErrorsOnThePage) {
const isPageAccessible = accessibilityErrorsOnThePage.length === 0 ? result.PASSED : result.FAILED;

const urlArr = url.split('/');

if (isPageAccessible === result.PASSED) {
resultObj.passCount += 1;
} else {
resultObj.failCount += 1;
}

resultObj.tests.push({
name: urlArr[urlArr.length -2] + '/' + urlArr[urlArr.length -1],
pageUrl: url,
documentTitle: pageTitle,
status: isPageAccessible,
screenshot: screenshotReportRef,
a11yIssues: accessibilityErrorsOnThePage,
});
}

function getAccessibilityTestResult() {
return resultObj;
}

module.exports = {runAccessibility, getAccessibilityTestResult};
15 changes: 15 additions & 0 deletions e2e/helpers/generate_report_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {getAccessibilityTestResult} = require('./accessibility/runner');
const {generateAccessibilityReport} = require('../reporters/accessibility-reporter/customReporter');
const testConfig = require('../config.js');

class Generate_report_helper extends Helper {

_finishTest() {
if (!testConfig.TestForAccessibility) {
return;
}
generateAccessibilityReport(getAccessibilityTestResult());
}

}
module.exports = Generate_report_helper;
13 changes: 13 additions & 0 deletions e2e/helpers/puppeteer_helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const testConfig = require('../config.js');
const {runAccessibility} = require('./accessibility/runner');

module.exports = class PuppeteerHelpers extends Helper {

/**
Expand Down Expand Up @@ -33,4 +36,14 @@ module.exports = class PuppeteerHelpers extends Helper {
return undefined;
}
}

async runAccessibilityTest() {
if (!testConfig.TestForAccessibility) {
return;
}
const url = await this.helpers['Puppeteer'].grabCurrentUrl();
const {page} = await this.helpers['Puppeteer'];

runAccessibility(url, page);
}
};
1 change: 1 addition & 0 deletions e2e/pages/acknowledgeClaim/responseIntention.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
throw new Error(`Response intention: ${responseIntention} does not exist`);
}
I.waitForElement(this.fields.responseIntention.id);
await I.runAccessibilityTest();
await within(this.fields.responseIntention.id, () => {
I.click(this.fields.responseIntention.options[responseIntention]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const litigationFriend = require('../../fragments/litigationFriend');
module.exports = {

async enterLitigantFriendWithDifferentAddressToDefendant(address, file) {
await I.runAccessibilityTest();
await litigationFriend.enterLitigantFriendWithDifferentAddressToLitigant('respondent1', address, file);
await I.clickContinue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
},

async enterTransferDate() {
await I.runAccessibilityTest();
await date.enterDate(this.fields.transferredDate.id, -1);
await within(this.fields.claimProceedsInCasemanReason.id, () => {
I.click(this.fields.claimProceedsInCasemanReason.options.other);
Expand Down
1 change: 1 addition & 0 deletions e2e/pages/caseProceedsInCaseman/takeCaseOffline.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {

async takeCaseOffline() {
I.waitForText('Take offline');
await I.runAccessibilityTest();
I.click('Take offline');
}

Expand Down
1 change: 1 addition & 0 deletions e2e/pages/createClaim/chooseCourt.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {

async enterCourt() {
I.waitForElement(this.fields.courtLocation);
await I.runAccessibilityTest();
I.fillField(this.fields.courtLocation, '344');
await I.clickContinue();
}
Expand Down
Loading

0 comments on commit 0a21fa0

Please sign in to comment.