Skip to content

Commit

Permalink
Feat/add link checking to gca cypress suite (#1646)
Browse files Browse the repository at this point in the history
* fix(cypress/gca): beef up tests following incident:

1. Add missing routes
2. Add checks for dead links across all pages
3. Refactor the a11y tests a bit to keep code DRY

* chore(cypress): gitignore screenshots generated by cypress

* feat(cypress): run the GCA tests in addition to the app page ones in CI

---------

Co-authored-by: William B <[email protected]>
  • Loading branch information
andrewleith and whabanks authored Aug 16, 2023
1 parent 96f25ad commit 0a628ed
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 58 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-admin-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,6 @@ jobs:
record: false
build: npx cypress info
working-directory: tests_cypress
spec: cypress/e2e/admin/a11y/app_pages.cy.js
spec: |
cypress/e2e/admin/a11y/app_pages.cy.js
cypress/e2e/admin/a11y/gca_pages.cy.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ dump.rdb
cypress.env.json
node_modules/
tests_cypress/cypress/videos/
tests_cypress/cypress/screenshots/
121 changes: 64 additions & 57 deletions tests_cypress/cypress/e2e/admin/a11y/gca_pages.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,78 @@

import config from "../../../../config";

const pages = [
{ en: "/accessibility", fr: "/accessibilite" },
{ en: "/keep-accurate-contact-information", fr: "/maintenez-a-jour-les-coordonnees"},
{ en: "/understanding-delivery-and-failure", fr: "/comprendre-statut-de-livraison"},
{ en: "/features", fr: "/fonctionnalites" },
{ en: "/formatting-guide", fr: "/guide-mise-en-forme" },
{ en: "/guidance", fr: "/guides-reference" },
{ en: "/home", fr: "/accueil" },
{ en: "/message-delivery-status", fr: "/etat-livraison-messages" },
{ en: "/other-services", fr: "/autres-services" },
{ en: "/personalisation-guide", fr: "/guide-personnalisation" },
{ en: "/privacy", fr: "/confidentialite" },
{ en: "/privacy-old", fr: "/confidentialite-old" },
{ en: "/security", fr: "/securite" },
{ en: "/security-old", fr: "/securite-old" },
{ en: "/spreadsheets", fr: "/feuille-de-calcul" },
{ en: "/terms", fr: "/conditions-dutilisation" },
{ en: "/why-gc-notify", fr: "/pourquoi-gc-notification" },
const langs = ['en', 'fr'];

const fullPageList = [
{ en: '/accessibility', fr: '/accessibilite' },
{ en: '/features', fr: '/fonctionnalites' },
{ en: '/formatting-emails', fr: '/guide-mise-en-forme' },
{ en: '/service-level-agreement', fr: '/accord-niveaux-de-service' },
{ en: '/terms', fr: '/conditions-dutilisation' },
{ en: '/guidance', fr: '/guides-reference' },
{ en: '/home', fr: '/accueil' },
{ en: '/message-delivery-status', fr: '/etat-livraison-messages' },
{ en: '/other-services', fr: '/autres-services' },
{ en: '/privacy', fr: '/confidentialite' },
{ en: '/security', fr: '/securite' },
{ en: '/sending-custom-content', fr: '/envoyer-contenu-personnalise' },
{ en: '/service-level-objectives', fr: '/objectifs-niveau-de-service' },
{ en: '/system-status', fr: '/etat-du-systeme' },
{ en: '/understanding-delivery-and-failure', fr: '/comprendre-statut-de-livraison' },
{ en: '/updating-contact-information', fr: '/maintenir-a-jour-les-coordonnees' },
{ en: '/using-a-spreadsheet', fr: '/utiliser-une-feuille-de-calcul' },
{ en: '/why-gc-notify', fr: '/pourquoi-notification-gc' },
];

describe('GCA static pages', () => {
afterEach(() => {
// cy.get('main').htmlvalidate({
// rules: {
// "no-redundant-role": "off",
// },
// });
});
console.log(config.viewports)
for (const viewport of config.viewports) {
context(`Viewport: ${viewport}px x 660px`, () => {
context('English', () => {
for (const page of pages) {
it(`${page.en} passes a11y checks`, () => {
cy.viewport(viewport, 660);
cy.visit(page.en);
cy.get('main').should('be.visible');

// check for a11y compliance
cy.injectAxe();
cy.checkA11y();
context("Check for dead links", () => {
for (const lang of langs) {
const currentLang = (lang === 'en' ? 'English' : 'Francais');
context(currentLang, () => {
for (const page of fullPageList) {
it(`${page[lang]} contains no dead links`, () => {
if (lang === 'fr') {
cy.visit('/set-lang');
}
cy.visit(page[lang]);

cy.get('body').within(() => {
cy.get('a').each((link) => {
if (link.prop('href').startsWith('mailto') || link.prop('href').startsWith('/set-lang') || link.prop('href').startsWith('#')) return;
cy.request(link.prop('href'));
});
});
});
}
});

context('Francais', () => {
// switch to french before getting french pages
before(() => {
cy.visit('/set-lang');
});

for (const page of pages) {
it(`can load ${page.fr} page`, () => {
cy.viewport(viewport, 660);

cy.visit(page.fr);
cy.get('main').should('be.visible');
// check for a11y compliance
cy.injectAxe();
cy.checkA11y();

}

});

for (const viewport of config.viewports) {
context('A11y and HTML validation test', () => {
context(`Viewport: ${viewport}px x 660px`, () => {
for (const lang of langs) {
const currentLang = (lang === 'en' ? 'English' : 'Francais');
context(currentLang, () => {
for (const page of fullPageList) {
it(`${page[lang]} passes a11y checks`, () => {
// cy.viewport(viewport, 660);
if (lang === 'fr') {
cy.visit('/set-lang');
}
cy.visit(page[lang]);

cy.get('main').should('be.visible');

// check for a11y compliance
cy.injectAxe();
cy.checkA11y();
});
}
});
}
});
})
});
}

});

0 comments on commit 0a628ed

Please sign in to comment.