Skip to content

Commit

Permalink
More Playwright tinkerings (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessabean authored Nov 12, 2024
1 parent d883c65 commit f534851
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 56 deletions.
44 changes: 0 additions & 44 deletions tests/e2e/utils/archive.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./consts";
export * from "./login";
export * from "./archive";
export * from "./a11y";
8 changes: 7 additions & 1 deletion tests/e2e/utils/pageObjects/adminHome.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ export default class AdminHomePage extends BasePage {
});
}

public async selectWP() {
public async selectWP(state: string) {
await this.page
.getByRole("combobox", {
name: "List of states, including District of Columbia and Puerto Rico",
})
.selectOption(state);
await this.page.getByRole("radio", { name: "MFP Work Plan" }).click();
await this.goToDashboard();
}

public async selectSAR() {
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/utils/pageObjects/wp/wpDashboard.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,29 @@ export class WPDashboardPage extends BasePage {
.click();
await this.modal.getByRole("button", { name: "Start new" }).click();
}

public async archiveAllReports() {
const archiveButtons = await this.page
.getByRole("button", {
name: "Archive",
exact: true,
})
.all();

if (archiveButtons.length > 0) {
await archiveButtons[0].click();
const modal = this.page.getByRole("dialog");
await modal.isVisible();
await modal.getByRole("textbox").fill("ARCHIVE");
await modal.getByRole("button", { name: "Archive" }).click();
await this.page.waitForResponse(
(response) =>
response.url().includes(`reports/archive/WP/${stateAbbreviation}/`) &&
response.status() == 200
);
await modal.isHidden();
await this.getReports();
await this.archiveAllReports();
}
}
}
9 changes: 8 additions & 1 deletion tests/e2e/utils/pageObjects/wp/wpInitiativeDefine.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ export class WPDefineInitiativePage extends BasePage {
public async fillFields() {
await this.description.fill("test");
await this.olderAdultsCheckbox.check();
await this.olderAdultsCheckbox.blur();
// ChoiceListField component has a hard timeout in the onblur handler to call the updateReport function and a hard timeout this is how we are working with that. :(
await this.page.waitForTimeout(200);
await this.individualsPhysicalCheckbox.check();
await this.individualsPhysicalCheckbox.blur();
await this.page.waitForTimeout(200);
await this.startDate.fill("01/01/2024");
await this.endDate.getByLabel("No").click();
await this.endDate.getByLabel("No").check();
await this.endDate.getByLabel("No").blur();
await this.page.waitForTimeout(200);
}
}
6 changes: 4 additions & 2 deletions tests/e2e/utils/pageObjects/wp/wpInitiativeOverlay.page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Locator, Page } from "@playwright/test";
import { Locator, Page } from "@playwright/test";
import BasePage from "../base.page";
import { WPDefineInitiativePage } from "./wpInitiativeDefine.page";
import { WPEvaluationPlanPage } from "./wpInitiativeEvaluation.page";
Expand Down Expand Up @@ -44,7 +44,7 @@ export class WPInitiativeOverlayPage extends BasePage {
await definePage.isReady();
await definePage.fillFields();
await definePage.saveButton.click();
await expect(definePage.page.getByRole("alert")).not.toBeVisible();
await this.defineInitiative.isVisible();
}

public async completeEvaluationPlan(page: Page) {
Expand All @@ -59,6 +59,7 @@ export class WPInitiativeOverlayPage extends BasePage {
await evaluationPage.fillFields();
}
await evaluationPage.backButton.click();
await this.evaluationPlan.isVisible();
}

public async completeFundingSources(page: Page) {
Expand All @@ -72,5 +73,6 @@ export class WPInitiativeOverlayPage extends BasePage {
await fundingPage.fillFields();
}
await fundingPage.backButton.click();
await this.fundingSources.isVisible();
}
}
30 changes: 23 additions & 7 deletions tests/e2e/wp/create.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BrowserContext, Page } from "@playwright/test";
import { archiveExistingWPs, logInStateUser } from "../utils";
import { test, expect } from "../utils/fixtures/base";
import { WPInitiativeOverlayPage } from "../utils/pageObjects/wp/wpInitiativeOverlay.page";
import StateHomePage from "../utils/pageObjects/stateHome.page";
Expand All @@ -10,9 +9,12 @@ import { WPTransitionBenchmarkStrategyPage } from "../utils/pageObjects/wp/wpTra
import { WPInitiativesInstructionsPage } from "../utils/pageObjects/wp/wpInitiativesInstructions.page";
import { WPInitiativesDashboardPage } from "../utils/pageObjects/wp/wpInitiativesDashboard.page";
import { WPReviewAndSubmitPage } from "../utils/pageObjects/wp/wpReviewAndSubmit.page";
import AdminHomePage from "../utils/pageObjects/adminHome.page";

let userPage: Page;
let userContext: BrowserContext;
let adminPage: Page;
let adminContext: BrowserContext;
let homePage: StateHomePage;
let wpDashboard: WPDashboardPage;
let wpGeneralInformation: WPGeneralInformationPage;
Expand All @@ -21,12 +23,18 @@ let wpTransitionBenchmarkStrategy: WPTransitionBenchmarkStrategyPage;
let wpInitiativesInstructions: WPInitiativesInstructionsPage;
let wpInitiativesDashboard: WPInitiativesDashboardPage;
let wpReviewAndSubmit: WPReviewAndSubmitPage;
let adminHomePage: AdminHomePage;
let adminWpDashboard: WPDashboardPage;

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

homePage = new StateHomePage(userPage);
wpDashboard = new WPDashboardPage(userPage);
Expand All @@ -40,17 +48,20 @@ test.beforeAll(async ({ browser }) => {
wpInitiativesInstructions = new WPInitiativesInstructionsPage(userPage);
wpInitiativesDashboard = new WPInitiativesDashboardPage(userPage);
wpReviewAndSubmit = new WPReviewAndSubmitPage(userPage);
adminHomePage = new AdminHomePage(adminPage);
adminWpDashboard = new WPDashboardPage(adminPage);
});

test.afterAll(async () => {
await userContext.close();
});

test.describe("Creating a new Work Plan", () => {
test("State user can create a Work Plan", async ({ page }) => {
// TODO: migrate these functions to use the save auth model
await archiveExistingWPs(page);
await logInStateUser(page);
test("State user can create a Work Plan", async () => {
await adminHomePage.goto();
await adminHomePage.selectWP("PR");
await adminWpDashboard.reportsReady();
await adminWpDashboard.archiveAllReports();

// View WPs
await homePage.goto();
Expand Down Expand Up @@ -95,8 +106,7 @@ test.describe("Creating a new Work Plan", () => {
}
});

test("State user can fill and submit a Work Plan", async ({ page }) => {
await logInStateUser(page);
test("State user can fill and submit a Work Plan", async () => {
await homePage.goto();
await homePage.wpButton.click();

Expand Down Expand Up @@ -154,6 +164,12 @@ test.describe("Creating a new Work Plan", () => {
await overlayPage.completeDefineInitiative(userPage);
await overlayPage.completeEvaluationPlan(userPage);
await overlayPage.completeFundingSources(userPage);
await overlayPage.isReady();
const errorIcons = await wpReviewAndSubmit.page
.getByAltText("warning icon")
.all();
await expect(errorIcons.length).toBe(0);

await overlayPage.backButton.click();
}

Expand Down

0 comments on commit f534851

Please sign in to comment.