Skip to content

Commit

Permalink
Vote-3155: Updating link validation tests (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
clmedders authored Nov 22, 2024
1 parent e1cd44b commit 8d786e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// <reference types="Cypress" />

const allPages = require("../../fixtures/site-pages.json");
// ! IMPORTANT: When testing locally, comment out the LIVE_URL and use the LOCAL_URL listed below for testing purposes. This is necessary because our pipeline testing targets the live site. Remember to revert this change before committing, ensuring the LIVE_URL is set as the base.
// const baseUrl = "http://vote-gov.lndo.site/";

const baseUrl = "https://vote.gov";
const excludedLinks = [
Expand Down
22 changes: 16 additions & 6 deletions testing/cypress/e2e/internalLinks/internal-links-validator.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/// <reference types="Cypress" />

const allPages = require("../../fixtures/site-pages.json");
// ! IMPORTANT: When testing locally, comment out the LIVE_URL and use the LOCAL_URL listed below for testing purposes. This is necessary because our pipeline testing targets the live site. Remember to revert this change before committing, ensuring the LIVE_URL is set as the base.
// const baseUrl = "http://vote-gov.lndo.site/";

const baseUrl = "https://vote.gov";
const excludedLinks = [
'http://vote-gov.lndo.site/',
'https://vote.gov'
];

describe("Internal Link Validator Test", () => {
const singlePage =
Expand All @@ -14,7 +22,7 @@ describe("Internal Link Validator Test", () => {
: null;
const pages = singlePage !== null ? singlePage : allPages;
pages.forEach((page) => {
it(
it(
`${page.name === "" ? "home" : page.name}`,
() =>
Cypress.env("retries") === true
Expand All @@ -25,18 +33,20 @@ describe("Internal Link Validator Test", () => {
}
: {},
() => {
cy.visit({
url: page.route,
});
cy.visit(`${baseUrl}${page.route}`);
cy.get("a[href^='/']").each(link => {
const href = link.prop("href");
if (excludedLinks.indexOf(href) === -1) {
expect(href).not.match(/\/$/);
cy.request({
url: link.prop('href'),
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(200)
})
}
})
}
);
});
});
});
});

0 comments on commit 8d786e4

Please sign in to comment.