UNCLASSIFIED - NO CUI

Skip to content
Snippets Groups Projects
Commit 0000243e authored by graham.smith's avatar graham.smith
Browse files

Merge branch 'BULL-1802' into 'master'

Removed cypress commands only used in one file

See merge request !197
parents 73be9e3e 65b590c3
No related branches found
No related tags found
1 merge request!197Removed cypress commands only used in one file
function verifyDownloads(numLinks, url) {
if (url) {
cy.visit(url);
}
cy.get('[data-cy="download"]')
.should("have.length", numLinks)
.each((element) => {
cy.wrap(element)
.invoke("attr", "href")
.then((link) => {
cy.request({
url: link,
}).then((response) => {
cy.wrap(response.status).should("eq", 200);
});
});
});
}
describe("Testing File Downloads", () => {
it("Home Downloads", () => {
cy.verifyDownloads(1, "/");
verifyDownloads(1, "/");
});
it("Iron Bank Downloads", () => {
cy.verifyDownloads(6, "/products/iron-bank");
verifyDownloads(6, "/products/iron-bank");
});
it("Party Bus Downloads", () => {
cy.verifyDownloads(1, "/products/party-bus");
verifyDownloads(1, "/products/party-bus");
});
it("Party Bus Service Catalog Downloads", () => {
cy.verifyDownloads(4, "/products/party-bus/service-catalog");
verifyDownloads(4, "/products/party-bus/service-catalog");
});
it("Cybersecurity Downloads", () => {
cy.verifyDownloads(1, "/products/cybersecurity");
verifyDownloads(1, "/products/cybersecurity");
});
it("DSOP Timeline Downloads", () => {
cy.verifyDownloads(1, "/products/cybersecurity/dsopTimeline");
verifyDownloads(1, "/products/cybersecurity/dsopTimeline");
});
it("Residency Downloads", () => {
cy.verifyDownloads(1, "/residency");
verifyDownloads(1, "/residency");
});
it("Resources Downloads", () => {
cy.verifyDownloads(6, "/resources");
verifyDownloads(6, "/resources");
});
});
import { routesByName } from "../../../src/router/routes";
function checkImages() {
cy.get("body").then(($body) => {
if ($body.find("img, .v-image, [data-cy=v-img]").length > 0) {
cy.get("img, .v-image, [data-cy=v-img]")
.not("img.vue-lb-modal-image")
.each(($el) => {
cy.get($el[0])
.scrollIntoView()
.invoke("width")
.should("be.greaterThan", 0);
});
}
});
}
describe("Ensures all images have valid sources and load correctly in browser.", function () {
Object.entries(routesByName).forEach(([page, data]) => {
if (data.path && data.meta) {
it(`Checks that all images are visible on ${page} page.`, () => {
cy.visit(data.path);
cy.checkImages();
checkImages();
});
}
});
......@@ -17,11 +32,11 @@ describe("Ensures all images have valid sources and load correctly in browser.",
cy.get("[data-cy=phone-input]").type("2101110000");
cy.get("[data-cy=submit]").click();
cy.wait(4000);
cy.checkImages();
checkImages();
});
it("Checks that all images are visible on Error page", function () {
cy.visit("*");
cy.checkImages();
checkImages();
});
});
......@@ -18,12 +18,50 @@ const productLinks = [
];
const selectors = ["ib", "pb", "bb", "cnap", "cyber"];
function checkExternalLinks() {
cy.get("a[target]").within((links) => {
cy.wrap(links).each((link) => {
cy.wrap(link)
.invoke("attr", "target")
.then((target) => {
if (target.match("_blank")) {
cy.log('Expecting rel="noopener noreferrer"');
cy.wrap(link)
.should("have.attr", "rel")
.should("eq", "noopener noreferrer");
} else {
cy.log('Not expecting rel="noopener noreferrer"');
}
});
});
});
}
function checkLinks(forceClick, linksData) {
linksData.forEach((data) => {
const pageNavText = data.meta?.breadcrumb || data.meta?.header?.title;
cy.contains(pageNavText).click({
force: forceClick,
});
const pageHeaderText = data.meta?.header?.title || data.meta?.breadcrumb;
verifyUrlAndHeader(data.path, pageHeaderText);
});
}
function verifyUrlAndHeader(pathname, header) {
cy.url().should(
"eq",
`${Cypress.config("baseUrl")}/${pathname.substring(1)}`
);
cy.get("h1").should("contain", `${header}`);
}
describe("Verifying Pageheader links", () => {
Object.entries(routesByName).forEach(([page, data]) => {
if (data.path && data.meta) {
it(`Checks that all external links on ${page} page contains "rel=noopener noreferrer".`, () => {
cy.visit(data.path);
cy.checkExternalLinks();
checkExternalLinks();
});
}
});
......@@ -31,23 +69,23 @@ describe("Verifying Pageheader links", () => {
it("Visits the main links in Desktop View", () => {
cy.viewport(1024, 768);
cy.visit("/");
cy.checkLinks(true, mainLinks);
cy.checkLinks(true, productLinks);
checkLinks(true, mainLinks);
checkLinks(true, productLinks);
});
it("Visits the main links in Mobile View", () => {
cy.viewport(375, 667);
cy.visit("/");
cy.get(".burger").click();
cy.checkLinks(true, mainLinks);
cy.checkLinks(true, productLinks);
checkLinks(true, mainLinks);
checkLinks(true, productLinks);
});
it("Visits internal links from Home page", () => {
cy.viewport(1024, 768);
cy.visit("/");
cy.contains("Learn More").click();
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.Services.path,
routesByName.Services.meta.header.title
);
......@@ -57,7 +95,7 @@ describe("Verifying Pageheader links", () => {
const pageHeaderText =
productLinks[idx].meta?.header?.title ||
productLinks[idx].meta?.breadcrumb;
cy.verifyUrlAndHeader(productLinks[idx].path, pageHeaderText);
verifyUrlAndHeader(productLinks[idx].path, pageHeaderText);
cy.go("back");
});
});
......@@ -68,18 +106,18 @@ describe("Verifying Pageheader links", () => {
cy.get("[data-cy=bb]").within(() => {
cy.contains(routesByName.BigBang.meta.breadcrumb).click();
});
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.BigBang.path,
routesByName.BigBang.meta.breadcrumb
);
cy.go("back");
cy.get("[data-cy=pb]").click();
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.PartyBusOnboarding.path,
routesByName.PartyBusOnboarding.meta.header.title
);
cy.contains("Contact Us").click();
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.ContactUs.path,
routesByName.ContactUs.meta.breadcrumb
);
......@@ -89,7 +127,7 @@ describe("Verifying Pageheader links", () => {
cy.viewport(1624, 768);
cy.visit(routesByName.Resources.path);
cy.contains(".v-btn", routesByName.ContactUs.meta.breadcrumb).click();
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.ContactUs.path,
routesByName.ContactUs.meta.breadcrumb
);
......@@ -99,7 +137,7 @@ describe("Verifying Pageheader links", () => {
cy.viewport(1024, 768);
cy.visit(routesByName.ContactUs.path);
cy.contains(".v-btn", "Residency Program").click();
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.Residency.path,
routesByName.Residency.meta.breadcrumb
);
......@@ -109,7 +147,7 @@ describe("Verifying Pageheader links", () => {
cy.viewport(1024, 768);
cy.visit(routesByName.IronBank.path);
cy.contains("a", "Iron Bank Onboarding Request").click();
cy.verifyUrlAndHeader(
verifyUrlAndHeader(
routesByName.IronBankGettingStarted.path,
routesByName.IronBankGettingStarted.meta.header.title
);
......
// https://docs.cypress.io/api/introduction/api.html
import { routesByName } from "../../../src/router/routes";
function checkLockIcons() {
cy.get('a[href*=".dso.mil"]').within((links) => {
cy.wrap(links).each((link) => {
cy.wrap(link)
.invoke("attr", "href")
.then((href) => {
cy.log("Link text: " + link.text());
cy.log(href);
if (
href.match(/(?<!(repo1|p1|login|onboarding|sso-info).*).dso.mil/)
) {
cy.log("Expecting lock icon...");
cy.wrap(link).within(() => {
cy.get(".mdi-lock").should("exist");
});
} else {
cy.log("Not expecting lock icon...");
cy.wrap(link).within(() => {
cy.get(".mdi-lock").should("not.exist");
});
}
});
});
});
}
describe("SSO Locks", () => {
Object.entries(routesByName).forEach(([page, data]) => {
if (data.path && data.meta) {
it(`${page}`, () => {
cy.visit(data.path);
cy.checkLockIcons();
checkLockIcons();
});
}
});
......
......@@ -23,100 +23,3 @@
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add("verifyDownloads", (numLinks, url) => {
if (url) {
cy.visit(url);
}
cy.get('[data-cy="download"]')
.should("have.length", numLinks)
.each((element) => {
cy.wrap(element)
.invoke("attr", "href")
.then((link) => {
cy.request({
url: link,
}).then((response) => {
cy.wrap(response.status).should("eq", 200);
});
});
});
});
Cypress.Commands.add("checkLockIcons", () => {
cy.get('a[href*=".dso.mil"]').within((links) => {
cy.wrap(links).each((link) => {
cy.wrap(link)
.invoke("attr", "href")
.then((href) => {
cy.log("Link text: " + link.text());
cy.log(href);
if (
href.match(/(?<!(repo1|p1|login|onboarding|sso-info).*).dso.mil/)
) {
cy.log("Expecting lock icon...");
cy.wrap(link).within(() => {
cy.get(".mdi-lock").should("exist");
});
} else {
cy.log("Not expecting lock icon...");
cy.wrap(link).within(() => {
cy.get(".mdi-lock").should("not.exist");
});
}
});
});
});
});
Cypress.Commands.add("verifyUrlAndHeader", (pathname, header) => {
cy.url().should(
"eq",
`${Cypress.config("baseUrl")}/${pathname.substring(1)}`
);
cy.get("h1").should("contain", `${header}`);
});
Cypress.Commands.add("checkLinks", (forceClick, linksData) => {
linksData.forEach((data) => {
const pageNavText = data.meta?.breadcrumb || data.meta?.header?.title;
cy.contains(pageNavText).click({
force: forceClick,
});
const pageHeaderText = data.meta?.header?.title || data.meta?.breadcrumb;
cy.verifyUrlAndHeader(data.path, pageHeaderText);
});
});
Cypress.Commands.add("checkImages", () => {
cy.get("body").then(($body) => {
if ($body.find("img, .v-image, [data-cy=v-img]").length > 0) {
cy.get("img, .v-image, [data-cy=v-img]")
.not("img.vue-lb-modal-image")
.each(($el) => {
cy.get($el[0])
.scrollIntoView()
.invoke("width")
.should("be.greaterThan", 0);
});
}
});
});
Cypress.Commands.add("checkExternalLinks", () => {
cy.get("a[target]").within((links) => {
cy.wrap(links).each((link) => {
cy.wrap(link)
.invoke("attr", "target")
.then((target) => {
if (target.match("_blank")) {
cy.log('Expecting rel="noopener noreferrer"');
cy.wrap(link)
.should("have.attr", "rel")
.should("eq", "noopener noreferrer");
} else {
cy.log('Not expecting rel="noopener noreferrer"');
}
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment