Skip to content

Commit

Permalink
Merge pull request #15919 from CDCgov/experience/15823/fix-link-checker
Browse files Browse the repository at this point in the history
Experience/15823/fix link checker
  • Loading branch information
etanb authored Sep 30, 2024
2 parents 351db90 + 23a7fcf commit b9f2d0d
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 368 deletions.
12 changes: 8 additions & 4 deletions frontend-react/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>%VITE_TITLE%</title>
<meta name="description" content="%VITE_DESCRIPTION%" />
<meta property="og:image" content="%VITE_OPENGRAPH_DEFAULT_IMAGE_SRC%" />
<meta property="og:image:alt" content="%VITE_OPENGRAPH_DEFAULT_IMAGE_ALTTEXT%" />
<title>Page not found</title>
<meta
name="description"
content="This page could not be found on our website. Please check the URL or return to the homepage."
/>
<meta property="og:title" content="404 - Page Not Found" />
<meta property="og:description" content="The page you are looking for is not available." />

<!-- 404 -->
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
Expand Down
11 changes: 11 additions & 0 deletions frontend-react/e2e/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,14 @@ export function removeDateTime(filename: string) {

return filename;
}

export function isAbsoluteURL(url: string): boolean {
return /^(https?|ftp|file|mailto):/.test(url);
}

export function isAssetURL(url: string): boolean {
// Regular expression to match common asset file extensions at the end of a URL
const assetExtensions = /\.(pdf|png|jpg|jpeg|gif|bmp|svg|webp|mp4|mp3|wav|ogg|avi|mov|mkv|zip|rar|tar|gz|iso)$/i;

return assetExtensions.test(url);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pageNotFound } from "../../../../../src/content/error/ErrorMessages";
import { tableRows } from "../../../../helpers/utils";
import { LastMileFailuresPage } from "../../../../pages/authenticated/admin/last-mile-failures";
import { test as baseTest, expect } from "../../../../test";
Expand Down Expand Up @@ -95,15 +96,15 @@ test.describe("Last Mile Failure page", () => {
test.use({ storageState: "e2e/.auth/receiver.json" });

test("returns Page Not Found", async ({ lastMileFailuresPage }) => {
await expect(lastMileFailuresPage.page).toHaveTitle(/Page Not Found/);
await expect(lastMileFailuresPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

test.describe("sender user", () => {
test.use({ storageState: "e2e/.auth/sender.json" });

test("returns Page Not Found", async ({ lastMileFailuresPage }) => {
await expect(lastMileFailuresPage.page).toHaveTitle(/Page Not Found/);
await expect(lastMileFailuresPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pageNotFound } from "../../../../../src/content/error/ErrorMessages";
import { noData, tableRows } from "../../../../helpers/utils";
import { MOCK_GET_MESSAGES } from "../../../../mocks/messages";
import { MessageIDSearchPage } from "../../../../pages/authenticated/admin/message-id-search";
Expand Down Expand Up @@ -160,7 +161,7 @@ test.describe("Message ID Search Page", () => {
messageIDSearchPage.mockError = true;
await messageIDSearchPage.reload();

await expect(messageIDSearchPage.page).toHaveTitle(/Page Not Found/);
await expect(messageIDSearchPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

Expand All @@ -171,7 +172,7 @@ test.describe("Message ID Search Page", () => {
messageIDSearchPage.mockError = true;
await messageIDSearchPage.reload();

await expect(messageIDSearchPage.page).toHaveTitle(/Page Not Found/);
await expect(messageIDSearchPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "@playwright/test";
import { pageNotFound } from "../../../../../src/content/error/ErrorMessages";
import { tableDataCellValue } from "../../../../helpers/utils";
import { MOCK_GET_ORGANIZATION_IGNORE } from "../../../../mocks/organizations";
import { OrganizationEditPage } from "../../../../pages/authenticated/admin/organization-edit";
Expand Down Expand Up @@ -47,14 +48,14 @@ test.describe("Organization Edit Page", () => {
test.describe("receiver user", () => {
test.use({ storageState: "e2e/.auth/receiver.json" });
test("returns Page Not Found", async ({ organizationEditPage }) => {
await expect(organizationEditPage.page).toHaveTitle(/Page Not Found/);
await expect(organizationEditPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

test.describe("sender user", () => {
test.use({ storageState: "e2e/.auth/sender.json" });
test("returns Page Not Found", async ({ organizationEditPage }) => {
await expect(organizationEditPage.page).toHaveTitle(/Page Not Found/);
await expect(organizationEditPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

Expand Down Expand Up @@ -84,18 +85,24 @@ test.describe("Organization Edit Page", () => {
test("has expected 'Meta'", async ({ organizationEditPage }) => {
const meta = organizationEditPage.page.getByTestId("gridContainer").getByTestId("grid").nth(2);
await expect(meta).toHaveText(organizationEditPage.getOrgMeta(MOCK_GET_ORGANIZATION_IGNORE));
});
});

test("has expected 'Description'", async ({ organizationEditPage }) => {
await expect(organizationEditPage.page.getByTestId("description")).toHaveValue(MOCK_GET_ORGANIZATION_IGNORE.description);
await expect(organizationEditPage.page.getByTestId("description")).toHaveValue(
MOCK_GET_ORGANIZATION_IGNORE.description,
);
});

test("has expected 'Jurisdiction'", async ({ organizationEditPage }) => {
await expect(organizationEditPage.page.getByTestId("jurisdiction")).toHaveValue(MOCK_GET_ORGANIZATION_IGNORE.jurisdiction);
await expect(organizationEditPage.page.getByTestId("jurisdiction")).toHaveValue(
MOCK_GET_ORGANIZATION_IGNORE.jurisdiction,
);
});

test("has expected 'Filters'", async ({ organizationEditPage }) => {
await expect(organizationEditPage.page.getByTestId("filters")).toHaveValue(JSON.stringify(MOCK_GET_ORGANIZATION_IGNORE.filters, null, 2));
await expect(organizationEditPage.page.getByTestId("filters")).toHaveValue(
JSON.stringify(MOCK_GET_ORGANIZATION_IGNORE.filters, null, 2),
);
});
});

Expand Down Expand Up @@ -129,9 +136,12 @@ test.describe("Organization Edit Page", () => {
test.describe("'Organization Sender Settings' section", () => {
test("can create a new organization sender", async ({ organizationEditPage }) => {
await organizationEditPage.page
.locator('#orgsendersettings').getByRole('link', { name: 'New' })
.locator("#orgsendersettings")
.getByRole("link", { name: "New" })
.click();
await expect(organizationEditPage.page).toHaveURL(`/admin/orgnewsetting/org/ignore/settingtype/sender`);
await expect(organizationEditPage.page).toHaveURL(
`/admin/orgnewsetting/org/ignore/settingtype/sender`,
);
await expect(organizationEditPage.page.getByText(/Org name: ignore/)).toBeVisible();
await expect(organizationEditPage.page.getByText(/Setting Type: sender/)).toBeVisible();

Expand All @@ -141,9 +151,20 @@ test.describe("Organization Edit Page", () => {
});

test("can edit an organization sender", async ({ organizationEditPage }) => {
const firstOrgSender = await organizationEditPage.page.locator("#orgsendersettings").nth(0).locator("td").nth(0).innerText();
await organizationEditPage.page.locator('#orgsendersettings').getByRole('link', { name: 'Edit' }).nth(0).click();
await expect(organizationEditPage.page).toHaveURL(`/admin/orgsendersettings/org/ignore/sender/${firstOrgSender}/action/edit`);
const firstOrgSender = await organizationEditPage.page
.locator("#orgsendersettings")
.nth(0)
.locator("td")
.nth(0)
.innerText();
await organizationEditPage.page
.locator("#orgsendersettings")
.getByRole("link", { name: "Edit" })
.nth(0)
.click();
await expect(organizationEditPage.page).toHaveURL(
`/admin/orgsendersettings/org/ignore/sender/${firstOrgSender}/action/edit`,
);
await expect(organizationEditPage.page.getByText(`Org name: ignore`)).toBeVisible();
await expect(organizationEditPage.page.getByText(`Sender name: ${firstOrgSender}`)).toBeVisible();

Expand All @@ -162,15 +183,24 @@ test.describe("Organization Edit Page", () => {

const orgSenderLocator = firstOrgSender.replace("-", "_");

await expect(organizationEditPage.page.locator(`#id_Item__${orgSenderLocator}__has_been_saved`).getByTestId("alerttoast")).toHaveText(`Item '${firstOrgSender}' has been saved`);
await expect(
organizationEditPage.page
.locator(`#id_Item__${orgSenderLocator}__has_been_saved`)
.getByTestId("alerttoast"),
).toHaveText(`Item '${firstOrgSender}' has been saved`);
await expect(organizationEditPage.page).toHaveURL(organizationEditPage.url);
});

test("can cancel when editing an organization sender", async ({ organizationEditPage }) => {
const firstOrgSender = await tableDataCellValue(organizationEditPage.page, 0, 0);
await organizationEditPage.page.
locator('#orgsendersettings').getByRole('link', { name: 'Edit' }).nth(0).click();
await expect(organizationEditPage.page).toHaveURL(`/admin/orgsendersettings/org/ignore/sender/${firstOrgSender}/action/edit`);
await organizationEditPage.page
.locator("#orgsendersettings")
.getByRole("link", { name: "Edit" })
.nth(0)
.click();
await expect(organizationEditPage.page).toHaveURL(
`/admin/orgsendersettings/org/ignore/sender/${firstOrgSender}/action/edit`,
);
await expect(organizationEditPage.page.getByText(`Org name: ignore`)).toBeVisible();
await expect(organizationEditPage.page.getByText(`Sender name: ${firstOrgSender}`)).toBeVisible();

Expand All @@ -182,9 +212,12 @@ test.describe("Organization Edit Page", () => {
test.describe("'Organization Receiver Settings' section", () => {
test("can create a new organization receiver", async ({ organizationEditPage }) => {
await organizationEditPage.page
.locator('#orgreceiversettings').getByRole('link', { name: 'New' })
.locator("#orgreceiversettings")
.getByRole("link", { name: "New" })
.click();
await expect(organizationEditPage.page).toHaveURL(`/admin/orgnewsetting/org/ignore/settingtype/receiver`);
await expect(organizationEditPage.page).toHaveURL(
`/admin/orgnewsetting/org/ignore/settingtype/receiver`,
);
await expect(organizationEditPage.page.getByText(/Org name: ignore/)).toBeVisible();
await expect(organizationEditPage.page.getByText(/Setting Type: receiver/)).toBeVisible();

Expand All @@ -194,11 +227,24 @@ test.describe("Organization Edit Page", () => {
});

test("can edit an organization receiver", async ({ organizationEditPage }) => {
const firstOrgReceiver = await organizationEditPage.page.locator("#orgreceiversettings").nth(0).locator("td").nth(0).innerText();
await organizationEditPage.page.locator('#orgreceiversettings').getByRole('link', { name: 'Edit' }).nth(0).click();
await expect(organizationEditPage.page).toHaveURL(`/admin/orgreceiversettings/org/ignore/receiver/${firstOrgReceiver}/action/edit`);
const firstOrgReceiver = await organizationEditPage.page
.locator("#orgreceiversettings")
.nth(0)
.locator("td")
.nth(0)
.innerText();
await organizationEditPage.page
.locator("#orgreceiversettings")
.getByRole("link", { name: "Edit" })
.nth(0)
.click();
await expect(organizationEditPage.page).toHaveURL(
`/admin/orgreceiversettings/org/ignore/receiver/${firstOrgReceiver}/action/edit`,
);
await expect(organizationEditPage.page.getByText(`Org name: ignore`)).toBeVisible();
await expect(organizationEditPage.page.getByText(`Receiver name: ${firstOrgReceiver}`)).toBeVisible();
await expect(
organizationEditPage.page.getByText(`Receiver name: ${firstOrgReceiver}`),
).toBeVisible();

await organizationEditPage.orgReceiverEdit.editJsonButton.click();
const modal = organizationEditPage.page.getByTestId("modalWindow").nth(0);
Expand All @@ -208,23 +254,42 @@ test.describe("Organization Edit Page", () => {
await expect(organizationEditPage.orgReceiverEdit.editJsonModal.save).toHaveAttribute("disabled");

await organizationEditPage.orgReceiverEdit.editJsonModal.checkSyntax.click();
await expect(organizationEditPage.orgReceiverEdit.editJsonModal.save).not.toHaveAttribute("disabled");
await expect(organizationEditPage.orgReceiverEdit.editJsonModal.save).not.toHaveAttribute(
"disabled",
);

await organizationEditPage.orgReceiverEdit.editJsonModal.save.click();
await expect(modal).toBeHidden();

const orgReceiverLocator = firstOrgReceiver.replace("-", "_");

await expect(organizationEditPage.page.locator(`#id_Item__${orgReceiverLocator}__has_been_updated`).getByTestId("alerttoast")).toHaveText(`Item '${firstOrgReceiver}' has been updated`);
await expect(
organizationEditPage.page
.locator(`#id_Item__${orgReceiverLocator}__has_been_updated`)
.getByTestId("alerttoast"),
).toHaveText(`Item '${firstOrgReceiver}' has been updated`);
await expect(organizationEditPage.page).toHaveURL(organizationEditPage.url);
});

test("can cancel when editing an organization receiver", async ({ organizationEditPage }) => {
const firstOrgReceiver = await organizationEditPage.page.locator("#orgreceiversettings").nth(0).locator("td").nth(0).innerText();
await organizationEditPage.page.locator('#orgreceiversettings').getByRole('link', { name: 'Edit' }).nth(0).click();
await expect(organizationEditPage.page).toHaveURL(`/admin/orgreceiversettings/org/ignore/receiver/${firstOrgReceiver}/action/edit`);
const firstOrgReceiver = await organizationEditPage.page
.locator("#orgreceiversettings")
.nth(0)
.locator("td")
.nth(0)
.innerText();
await organizationEditPage.page
.locator("#orgreceiversettings")
.getByRole("link", { name: "Edit" })
.nth(0)
.click();
await expect(organizationEditPage.page).toHaveURL(
`/admin/orgreceiversettings/org/ignore/receiver/${firstOrgReceiver}/action/edit`,
);
await expect(organizationEditPage.page.getByText(`Org name: ignore`)).toBeVisible();
await expect(organizationEditPage.page.getByText(`Receiver name: ${firstOrgReceiver}`)).toBeVisible();
await expect(
organizationEditPage.page.getByText(`Receiver name: ${firstOrgReceiver}`),
).toBeVisible();

await organizationEditPage.orgReceiverEdit.cancelButton.click();
await expect(organizationEditPage.page).toHaveURL(organizationEditPage.url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from "@playwright/test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { pageNotFound } from "../../../../../src/content/error/ErrorMessages";
import { MOCK_GET_ORGANIZATION_SETTINGS_LIST } from "../../../../mocks/organizations";
import { OrganizationPage } from "../../../../pages/authenticated/admin/organization";
import { test as baseTest } from "../../../../test";
Expand Down Expand Up @@ -51,14 +52,14 @@ test.describe("Admin Organization Settings Page", () => {
test.describe("receiver user", () => {
test.use({ storageState: "e2e/.auth/receiver.json" });
test("returns Page Not Found", async ({ organizationPage }) => {
await expect(organizationPage.page).toHaveTitle(/Page Not Found/);
await expect(organizationPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

test.describe("sender user", () => {
test.use({ storageState: "e2e/.auth/sender.json" });
test("returns Page Not Found", async ({ organizationPage }) => {
await expect(organizationPage.page).toHaveTitle(/Page Not Found/);
await expect(organizationPage.page).toHaveTitle(new RegExp(pageNotFound));
});
});

Expand All @@ -79,8 +80,8 @@ test.describe("Admin Organization Settings Page", () => {

test.describe("when there is no error", () => {
test("nav contains the 'Admin tools' dropdown with 'Organization Settings' option", async ({
organizationPage,
}) => {
organizationPage,
}) => {
const navItems = organizationPage.page.locator(".usa-nav li");
await expect(navItems).toContainText(["Admin tools"]);

Expand Down Expand Up @@ -126,8 +127,8 @@ test.describe("Admin Organization Settings Page", () => {
i === 0
? MOCK_GET_ORGANIZATION_SETTINGS_LIST[0]
: (MOCK_GET_ORGANIZATION_SETTINGS_LIST.find((i) => i.name === cols[0]) ?? {
name: "INVALID",
});
name: "INVALID",
});
// if first row, we expect column headers. else, the data row matching id (name)
// SetEdit is text of buttons in button column
const expectedColContents =
Expand Down
Loading

0 comments on commit b9f2d0d

Please sign in to comment.