Skip to content

Commit

Permalink
Add MCPAR dashboard Playwright tests (#11959)
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbay-bluetiger authored Dec 6, 2024
1 parent 0f49e18 commit 07a05ff
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ TEST_ADMIN_USER_EMAIL=op://mdct_devs/mcr_secrets/CYPRESS_ADMIN_USER_EMAIL
TEST_ADMIN_USER_PASSWORD=op://mdct_devs/mcr_secrets/CYPRESS_ADMIN_USER_PASSWORD # pragma: allowlist secret
TEST_STATE_USER_EMAIL=op://mdct_devs/mcr_secrets/CYPRESS_STATE_USER_EMAIL
TEST_STATE_USER_PASSWORD=op://mdct_devs/mcr_secrets/CYPRESS_STATE_USER_PASSWORD # pragma: allowlist secret
TEST_STATE=MN
TEST_STATE=Minnesota
TEST_STATE=DC
TEST_STATE_NAME="District of Columbia"
6 changes: 3 additions & 3 deletions tests/playwright/pages/banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "../utils/fixtures/base";
import BannerPage from "../utils/pageObjects/banner.page";
import { expect, test } from "../utils/fixtures/base";
import { BannerPage, stateUserAuth } from "../utils";

test.describe("admin user banner page", () => {
test("Should see the correct banner page as an admin user", async ({
Expand Down Expand Up @@ -34,7 +34,7 @@ test.describe("admin user banner page", () => {
profilePage,
}) => {
const userContext = await browser.newContext({
storageState: ".auth/user.json",
storageState: stateUserAuth,
});
await profilePage.goto();
const newBannerPage = new BannerPage(await userContext.newPage());
Expand Down
9 changes: 5 additions & 4 deletions tests/playwright/pages/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { test, expect } from "../utils/fixtures/base";
import BasePage from "../utils/pageObjects/base.page";
import { expect, test } from "../utils/fixtures/base";
import { BasePage } from "../utils";

test.describe("state user home page", () => {
test("Should see the correct home page as a state user", async ({
stateHomePage,
}) => {
await stateHomePage.goto();
await stateHomePage.isReady();
await expect(stateHomePage.wpButton).toBeVisible();
await expect(stateHomePage.sarButton).toBeVisible();
await expect(stateHomePage.mcparButton).toBeVisible();
await expect(stateHomePage.mlrButton).toBeVisible();
await expect(stateHomePage.naaarButton).toBeVisible();
});

test("Is accessible on all device types for state user", async ({
Expand Down
72 changes: 72 additions & 0 deletions tests/playwright/pages/mcpar/dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { expect, test } from "../../utils/fixtures/base";
import { stateName } from "../../utils";

let currentDate = "";
let programName = "";
let updatedProgramName = "";

test.beforeAll(async () => {
currentDate = new Date().toISOString();
programName = `automated test - ${currentDate}`;
updatedProgramName = `Updated: ${programName}`;
});

test.describe(
"MCPAR Dashboard Page - Program Creation/Editing/Archiving",
() => {
test("State users can create and edit reports", async ({
mcparDashboardPage,
mcparGetStartedPage,
stateHomePage,
}) => {
await stateHomePage.goto();
await stateHomePage.isReady();

await stateHomePage.mcparButton.isVisible();
await stateHomePage.mcparButton.click();
await stateHomePage.redirectPage("/mcpar/get-started");

await mcparGetStartedPage.mcparButton.isVisible();
await mcparGetStartedPage.mcparButton.click();
await mcparGetStartedPage.redirectPage("/mcpar");

const originalRow = mcparDashboardPage.table.getByRole("row", {
name: programName,
});
const updatedRow = mcparDashboardPage.table.getByRole("row", {
name: updatedProgramName,
});

// Create MCPAR
await mcparDashboardPage.create(programName);
await expect(originalRow).toBeVisible();
await expect(updatedRow).toBeHidden();

// Update MCPAR
await mcparDashboardPage.update(programName, updatedProgramName);
await expect(originalRow).toBeHidden();
await expect(updatedRow).toBeVisible();
});

test("Admin users can archive/unarchive reports", async ({
adminHomePage,
}) => {
await adminHomePage.archiveMCPAR(stateName, updatedProgramName);
await adminHomePage.unarchiveMCPAR(stateName, updatedProgramName);
});

test("State users can't see archived programs", async ({
adminHomePage,
mcparDashboardPage,
}) => {
await adminHomePage.archiveMCPAR(stateName, updatedProgramName);

await mcparDashboardPage.goto();
await mcparDashboardPage.isReady();
await mcparDashboardPage.table.isVisible();
await expect(
mcparDashboardPage.table.getByRole("row", { name: updatedProgramName })
).toBeHidden();
});
}
);
8 changes: 4 additions & 4 deletions tests/playwright/pages/profile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "../utils/fixtures/base";
import { expect, test } from "../utils/fixtures/base";
import { BrowserContext, Page } from "@playwright/test";
import ProfilePage from "../utils/pageObjects/profile.page";
import { adminUserAuth, ProfilePage, stateUserAuth } from "../utils";

let adminPage: Page;
let userPage: Page;
Expand All @@ -9,12 +9,12 @@ let userContext: BrowserContext;

test.beforeAll(async ({ browser }) => {
adminContext = await browser.newContext({
storageState: ".auth/admin.json",
storageState: adminUserAuth,
});
adminPage = await adminContext.newPage();

userContext = await browser.newContext({
storageState: ".auth/user.json",
storageState: stateUserAuth,
});
userPage = await userContext.newPage();
});
Expand Down
17 changes: 10 additions & 7 deletions tests/playwright/utils/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { test as setup } from "@playwright/test";

import { adminPassword, adminUser, statePassword, stateUser } from "./consts";

const adminFile = ".auth/admin.json";
import {
adminPassword,
adminUser,
adminUserAuth,
statePassword,
stateUser,
stateUserAuth,
} from "./consts";

setup("authenticate as admin", async ({ page }) => {
await page.goto("/");
Expand All @@ -19,11 +24,9 @@ setup("authenticate as admin", async ({ page }) => {
})
.isVisible();
await page.waitForTimeout(1000);
await page.context().storageState({ path: adminFile });
await page.context().storageState({ path: adminUserAuth });
});

const userFile = ".auth/user.json";

setup("authenticate as user", async ({ page }) => {
await page.goto("/");
const emailInput = page.getByRole("textbox", { name: "email" });
Expand All @@ -39,5 +42,5 @@ setup("authenticate as user", async ({ page }) => {
})
.isVisible();
await page.waitForTimeout(1000);
await page.context().storageState({ path: userFile });
await page.context().storageState({ path: stateUserAuth });
});
7 changes: 5 additions & 2 deletions tests/playwright/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ export const adminPassword = process.env.TEST_ADMIN_USER_PASSWORD!; // pragma: a
export const stateUser = process.env.TEST_STATE_USER_EMAIL!;
export const statePassword = process.env.TEST_STATE_USER_PASSWORD!; // pragma: allowlist secret

export const stateAbbreviation = process.env.TEST_STATE || "MN";
export const stateName = process.env.TEST_STATE_NAME || "Minnesota";
export const stateAbbreviation = process.env.TEST_STATE || "DC";
export const stateName = process.env.TEST_STATE_NAME || "District of Columbia";

export const currentYear: number = new Date().getFullYear();

export const stateUserAuth: string = ".auth/user.json";
export const adminUserAuth: string = ".auth/admin.json";
80 changes: 48 additions & 32 deletions tests/playwright/utils/fixtures/base.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
import { mergeTests, test as base } from "@playwright/test";
import StateHomePage from "../pageObjects/stateHome.page";
import AdminHomePage from "../pageObjects/adminHome.page";
import BannerPage from "../pageObjects/banner.page";
import ProfilePage from "../pageObjects/profile.page";
import { Browser, mergeTests, test as base } from "@playwright/test";
import {
AdminHomePage,
adminUserAuth,
BannerPage,
MCPARDashboardPage,
MCPARGetStartedPage,
ProfilePage,
StateHomePage,
stateUserAuth,
} from "../../utils";

type CustomFixtures = {
stateHomePage: StateHomePage;
adminHomePage: AdminHomePage;
bannerPage: BannerPage;
profilePage: ProfilePage;
mcparGetStartedPage: MCPARGetStartedPage;
mcparDashboardPage: MCPARDashboardPage;
stateHomePage: StateHomePage;
};

async function addPageObject(
PageObject: any,
browser: Browser,
use: any,
storageState: string
) {
const context = await browser.newContext({ storageState });
const page = new PageObject(await context.newPage());
// Init page
await page.goto();
await use(page);
await context.close();
}

async function adminPage(PageObject: any, browser: Browser, use: any) {
await addPageObject(PageObject, browser, use, adminUserAuth);
}

async function statePage(PageObject: any, browser: Browser, use: any) {
await addPageObject(PageObject, browser, use, stateUserAuth);
}

export const baseTest = base.extend<CustomFixtures>({
stateHomePage: async ({ browser }, use) => {
const context = await browser.newContext({
storageState: ".auth/user.json",
});
const stateHomePage = new StateHomePage(await context.newPage());
await use(stateHomePage);
await context.close();
},
adminHomePage: async ({ browser }, use) => {
const context = await browser.newContext({
storageState: ".auth/admin.json",
});
const adminHomePage = new AdminHomePage(await context.newPage());
await use(adminHomePage);
await context.close();
await adminPage(AdminHomePage, browser, use);
},
bannerPage: async ({ browser }, use) => {
const context = await browser.newContext({
storageState: ".auth/admin.json",
});
const bannerPage = new BannerPage(await context.newPage());
await use(bannerPage);
await context.close();
await adminPage(BannerPage, browser, use);
},
mcparDashboardPage: async ({ browser }, use) => {
await statePage(MCPARDashboardPage, browser, use);
},
mcparGetStartedPage: async ({ browser }, use) => {
await statePage(MCPARGetStartedPage, browser, use);
},
profilePage: async ({ browser }, use) => {
const context = await browser.newContext({
storageState: ".auth/user.json",
});
const profilePage = new ProfilePage(await context.newPage());
await use(profilePage);
await context.close();
await statePage(ProfilePage, browser, use);
},
stateHomePage: async ({ browser }, use) => {
await statePage(StateHomePage, browser, use);
},
});

Expand Down
3 changes: 2 additions & 1 deletion tests/playwright/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./a11y";
export * from "./consts";
export * from "./login";
export * from "./a11y";
export * from "./pageObjects";
32 changes: 32 additions & 0 deletions tests/playwright/utils/pageObjects/adminHome.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class AdminHomePage extends BasePage {
readonly page: Page;
readonly title: Locator;
readonly dropdown: Locator;
readonly table: Locator;

constructor(page: Page) {
super(page);
Expand All @@ -17,6 +18,7 @@ export default class AdminHomePage extends BasePage {
this.dropdown = page.getByRole("combobox", {
name: "List of states, including District of Columbia and Puerto Rico",
});
this.table = page.getByRole("table");
}

public async selectMCPAR(state: string) {
Expand Down Expand Up @@ -55,5 +57,35 @@ export default class AdminHomePage extends BasePage {
name: "Go to Report Dashboard",
})
.click();
await this.page.waitForResponse((response) => response.status() == 200);
}

public async getRowMCPAR(stateName: string, programName: string) {
await this.goto();
await this.isReady();
await this.selectMCPAR(stateName);
await this.table.isVisible();

return this.table.getByRole("row", { name: programName });
}

public async archiveMCPAR(stateName: string, programName: string) {
const row = await this.getRowMCPAR(stateName, programName);
const archiveButton = row.getByRole("button", { name: "Archive" });

await archiveButton.click();
await this.page.waitForResponse((response) => response.status() == 200);
await archiveButton.isHidden();
await row.getByRole("button", { name: "Unarchive" }).isVisible();
}

public async unarchiveMCPAR(stateName: string, programName: string) {
const row = await this.getRowMCPAR(stateName, programName);
const unarchiveButton = row.getByRole("button", { name: "Unarchive" });

await unarchiveButton.click();
await this.page.waitForResponse((response) => response.status() == 200);
await row.getByRole("button", { name: "Archive" }).isVisible();
await unarchiveButton.isHidden();
}
}
13 changes: 13 additions & 0 deletions tests/playwright/utils/pageObjects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { default as BasePage } from "./base.page";
export { default as BannerPage } from "./banner.page";
export { default as ProfilePage } from "./profile.page";

// Admin User
export { default as AdminHomePage } from "./adminHome.page";

// State User
export { default as StateHomePage } from "./stateHome.page";

// MCPAR
export { default as MCPARDashboardPage } from "./mcpar/dashboard.page";
export { default as MCPARGetStartedPage } from "./mcpar/getStarted.page";
Loading

0 comments on commit 07a05ff

Please sign in to comment.