Skip to content

Commit

Permalink
15839 - E2e tests (mock data) for all of Org/Receiver/Sender Settings…
Browse files Browse the repository at this point in the history
… Pages (#15921)

* 15839 - E2e tests (mock data) for all of Org/Receiver/Sender Settings Pages
Fixed last Mile Failures e2e broken test

* 15839 - added data-test-id for e2e testing

* 15839 - fixed indentation

* 15839 - added optional heading param to BasePage.ts
  • Loading branch information
penny-lischer authored Sep 20, 2024
1 parent b6bd185 commit f97a602
Show file tree
Hide file tree
Showing 16 changed files with 1,456 additions and 429 deletions.
1,359 changes: 979 additions & 380 deletions frontend-react/e2e/mocks/organizations.ts

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions frontend-react/e2e/pages/BasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export abstract class BasePage {
typeof err === "function" || typeof err === "object"
? err
: {
status: typeof err === "number" ? err : 500,
};
status: typeof err === "number" ? err : 500,
};
}

/**
Expand Down Expand Up @@ -134,9 +134,11 @@ export abstract class BasePage {
);
}

async testHeader() {
async testHeader(hasHeading = true) {
await expect(this.page).toHaveTitle(this.title);
await expect(this.heading).toBeVisible();
if (hasHeading) {
await expect(this.heading).toBeVisible();
}
}

async testCard(card: { name: string }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, Locator } from "@playwright/test";
import { startOfDay, subDays } from "date-fns";
import { tableRows } from "../../helpers/utils";
import { MOCK_GET_RESEND, MOCK_GET_SEND_FAILURES } from "../../mocks/lastMilefailures";
import { BasePage, BasePageTestArgs, RouteHandlerFulfillEntry } from "../BasePage";
import { tableRows } from "../../../helpers/utils";
import { MOCK_GET_RESEND, MOCK_GET_SEND_FAILURES } from "../../../mocks/lastMilefailures";
import { BasePage, BasePageTestArgs, RouteHandlerFulfillEntry } from "../../BasePage";

export class LastMileFailuresPage extends BasePage {
static readonly URL_LAST_MILE = "/admin/lastmile";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MessageIDSearchPage } from "./message-id-search";
import { MOCK_GET_MESSAGE } from "../../mocks/messages";
import { MOCK_GET_MESSAGE } from "../../../mocks/messages";

import { BasePage, BasePageTestArgs, RouteHandlerFulfillEntry } from "../BasePage";
import { BasePage, BasePageTestArgs, RouteHandlerFulfillEntry } from "../../BasePage";

export class MessageDetailsPage extends BasePage {
static readonly URL_MESSAGE_DETAILS = `/message-details/${MessageIDSearchPage.MESSAGE_ID}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MOCK_GET_MESSAGE, MOCK_GET_MESSAGES } from "../../mocks/messages";
import { BasePage, BasePageTestArgs, RouteHandlerFulfillEntry } from "../BasePage";
import { MOCK_GET_MESSAGE, MOCK_GET_MESSAGES } from "../../../mocks/messages";
import { BasePage, BasePageTestArgs, RouteHandlerFulfillEntry } from "../../BasePage";

export class MessageIDSearchPage extends BasePage {
static readonly URL_MESSAGE_ID_SEARCH = "/admin/message-tracker";
Expand Down
182 changes: 182 additions & 0 deletions frontend-react/e2e/pages/authenticated/admin/organization-edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { expect, Locator, Page } from "@playwright/test";
import { RSReceiver, RSSender } from "../../../../src/config/endpoints/settings";
import { formatDate } from "../../../../src/utils/misc";
import {
MOCK_GET_ORGANIZATION_IGNORE,
MOCK_GET_RECEIVERS_IGNORE,
MOCK_GET_SENDERS_IGNORE
} from "../../../mocks/organizations";
import { BasePage, BasePageTestArgs, type RouteHandlerFulfillEntry } from "../../BasePage";

export class OrganizationEditPage extends BasePage {
static readonly URL_ORGANIZATION_EDIT = `/admin/orgsettings/org/ignore`;
static readonly API_ORGANIZATION_IGNORE = "/api/settings/organizations/ignore";
static readonly API_SENDERS = "/api/settings/organizations/ignore/senders";
static readonly API_RECEIVERS = "/api/settings/organizations/ignore/receivers";
protected _organizationSenders: RSSender[];
protected _organizationReceivers: RSReceiver[];

readonly orgSenderNew: {
cancel: Locator;
save: Locator;
}
readonly orgSenderEdit: {
modal: Locator;
cancelButton: Locator;
editJsonButton: Locator;
editJsonModal: {
save: Locator;
checkSyntax: Locator;
back: Locator;
};
}
readonly orgReceiverNew: {
cancel: Locator;
save: Locator;
}
readonly orgReceiverEdit: {
modal: Locator;
cancelButton: Locator;
editJsonButton: Locator;
editJsonModal: {
save: Locator;
checkSyntax: Locator;
back: Locator;
};
}

constructor(testArgs: BasePageTestArgs) {
super(
{
url: OrganizationEditPage.URL_ORGANIZATION_EDIT,
title: "Organization edit - Admin",
},
testArgs,
);

this._organizationSenders = [];
this._organizationReceivers = [];

this.addMockRouteHandlers(
[this.createMockOrganizationIgnoreAPIHandler(),
this.createMockOrganizationSenderAPIHandler(),
this.createMockOrganizationReceiverAPIHandler()]
);
this.orgSenderNew = {
cancel: this.page.getByRole("button", {
name: "Cancel",
}),
save: this.page.getByRole("button", {
name: "Save",
}),
}
this.orgSenderEdit = {
modal: this.page.getByTestId("modalWindow"),
cancelButton: this.page.getByRole("button", {
name: "Cancel",
}),
editJsonButton: this.page.getByRole("button", {
name: "Edit json and save...",
}),
editJsonModal: {
save: this.page.getByTestId("editCompareSaveButton"),
checkSyntax: this.page.getByTestId("editCheckSyntaxButton"),
back: this.page.getByRole("button", {
name: "Back",
}),
}
}
this.orgReceiverNew = {
cancel: this.page.getByRole("button", {
name: "Cancel",
}),
save: this.page.getByRole("button", {
name: "Save",
}),
}

this.orgReceiverEdit = {
modal: this.page.getByTestId("modalWindow"),
cancelButton: this.page.getByRole("button", {
name: "Cancel",
}),
editJsonButton: this.page.getByRole("button", {
name: "Edit json and save...",
}),
editJsonModal: {
save: this.page.getByTestId("editCompareSaveButton"),
checkSyntax: this.page.getByTestId("editCheckSyntaxButton"),
back: this.page.getByRole("button", {
name: "Back",
}),
}
}
}

get isPageLoadExpected() {
return super.isPageLoadExpected && this.testArgs.storageState === this.testArgs.adminLogin.path;
}

createMockOrganizationIgnoreAPIHandler(): RouteHandlerFulfillEntry {
return [
OrganizationEditPage.API_ORGANIZATION_IGNORE,
() => {
return {
json: MOCK_GET_ORGANIZATION_IGNORE,
};
},
];
}

createMockOrganizationSenderAPIHandler(): RouteHandlerFulfillEntry {
return [
OrganizationEditPage.API_SENDERS,
() => {
return {
json: MOCK_GET_SENDERS_IGNORE,
};
},
];
}

createMockOrganizationReceiverAPIHandler(): RouteHandlerFulfillEntry {
return [
OrganizationEditPage.API_RECEIVERS,
() => {
return {
json: MOCK_GET_RECEIVERS_IGNORE,
};
},
];
}

async testTableHeaders() {
await expect(this.page.locator(".usa-table th").nth(0)).toHaveText(/Name/);
await expect(this.page.locator(".usa-table th").nth(1)).toHaveText(/Org Name/);
await expect(this.page.locator(".usa-table th").nth(2)).toHaveText(/Topic/);
await expect(this.page.locator(".usa-table th").nth(3)).toHaveText(/Status/);
await expect(this.page.locator(".usa-table th").nth(4)).toHaveText(/Meta/);
await expect(this.page.locator(".usa-table th").nth(4)).toHaveText(/Action/);

return true;
}

getOrgMeta(metaData: any){
const { version, createdAt, createdBy } = metaData;

// handle cases where individual metadata are not available
const versionDisplay = version || version === 0 ? `v${version} ` : "";
const createdAtDisplay = createdAt
? `[${formatDate(metaData.createdAt)}] `
: "";
const createdByDisplay = createdBy ?? "";

return `${versionDisplay}${createdAtDisplay}${createdByDisplay}`;
}

getApplyButton(page: Page) {
return page.getByRole("button", {
name: "Apply",
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { RSOrganizationSettings } from "../../../src/config/endpoints/settings";
import { MOCK_GET_ORGANIZATION_SETTINGS_LIST } from "../../mocks/organizations";
import { BasePage, BasePageTestArgs, type RouteHandlerFulfillEntry } from "../BasePage";
import { RSOrganizationSettings } from "../../../../src/config/endpoints/settings";
import { MOCK_GET_ORGANIZATION_SETTINGS_LIST } from "../../../mocks/organizations";
import { BasePage, BasePageTestArgs, type RouteHandlerFulfillEntry } from "../../BasePage";

export class OrganizationPage extends BasePage {
static readonly API_ORGANIZATIONS = "/api/settings/organizations";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tableRows } from "../../../../helpers/utils";
import { LastMileFailuresPage } from "../../../../pages/authenticated/last-mile-failures";
import { LastMileFailuresPage } from "../../../../pages/authenticated/admin/last-mile-failures";
import { test as baseTest, expect } from "../../../../test";

export interface LastMileFailuresPageFixtures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from "node:fs";
import { parseFileLocation } from "../../../../../src/utils/misc";
import { tableRows } from "../../../../helpers/utils";
import { MOCK_GET_MESSAGE } from "../../../../mocks/messages";
import { MessageDetailsPage } from "../../../../pages/authenticated/message-details";
import { MessageIDSearchPage } from "../../../../pages/authenticated/message-id-search";
import { MessageDetailsPage } from "../../../../pages/authenticated/admin/message-details";
import { MessageIDSearchPage } from "../../../../pages/authenticated/admin/message-id-search";
import { mockGetHistoryReportResponse } from "../../../../pages/authenticated/report-details";

import { test as baseTest, expect } from "../../../../test";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noData, tableRows } from "../../../../helpers/utils";
import { MOCK_GET_MESSAGES } from "../../../../mocks/messages";
import { MessageIDSearchPage } from "../../../../pages/authenticated/message-id-search";
import { MessageIDSearchPage } from "../../../../pages/authenticated/admin/message-id-search";
import { openReportIdDetailPage } from "../../../../pages/authenticated/submission-history";

import { test as baseTest, expect } from "../../../../test";
Expand Down
Loading

0 comments on commit f97a602

Please sign in to comment.