From f5348518d3ca080912fff28007c4e0403e0aa681 Mon Sep 17 00:00:00 2001 From: Jessica Eldredge Date: Tue, 12 Nov 2024 12:24:31 -0500 Subject: [PATCH] More Playwright tinkerings (#792) --- tests/e2e/utils/archive.ts | 44 ------------------- tests/e2e/utils/index.ts | 1 - tests/e2e/utils/pageObjects/adminHome.page.ts | 8 +++- .../utils/pageObjects/wp/wpDashboard.page.ts | 25 +++++++++++ .../pageObjects/wp/wpInitiativeDefine.page.ts | 9 +++- .../wp/wpInitiativeOverlay.page.ts | 6 ++- tests/e2e/wp/create.spec.ts | 30 ++++++++++--- 7 files changed, 67 insertions(+), 56 deletions(-) delete mode 100644 tests/e2e/utils/archive.ts diff --git a/tests/e2e/utils/archive.ts b/tests/e2e/utils/archive.ts deleted file mode 100644 index 25d3871f8..000000000 --- a/tests/e2e/utils/archive.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Page } from "@playwright/test"; -import { logInAdminUser, logOutUser } from "./login"; -import { stateAbbreviation } from "./consts"; - -export async function archiveReports(page: Page) { - const archiveButtons = await page - .getByRole("button", { name: "Archive", exact: true }) - .all(); - if (archiveButtons.length > 0) { - await archiveButtons[0].click(); - const modal = page.getByRole("dialog"); - await modal.isVisible(); - await modal.getByRole("textbox").fill("ARCHIVE"); - await modal.getByRole("button", { name: "Archive" }).click(); - await page.waitForResponse( - (response) => - response.url().includes(`reports/archive/WP/${stateAbbreviation}/`) && - response.status() == 200 - ); - await modal.isHidden(); - await page.getByRole("table").isVisible(); - await archiveReports(page); - } -} - -export async function archiveExistingWPs(page: Page) { - await logInAdminUser(page); - await page - .getByRole("combobox", { - name: "List of states, including District of Columbia and Puerto Rico", - }) - .selectOption(stateAbbreviation); - await page.getByLabel("MFP Work Plan").click(); - - await page.getByRole("button", { name: "Go to Report Dashboard" }).click(); - await page.waitForResponse( - (response) => - response.url().includes(`/reports/WP/${stateAbbreviation}`) && - response.status() == 200 - ); - await page.getByRole("table").isVisible(); - await archiveReports(page); - await logOutUser(page); -} diff --git a/tests/e2e/utils/index.ts b/tests/e2e/utils/index.ts index e3941e044..1b4506130 100644 --- a/tests/e2e/utils/index.ts +++ b/tests/e2e/utils/index.ts @@ -1,4 +1,3 @@ export * from "./consts"; export * from "./login"; -export * from "./archive"; export * from "./a11y"; diff --git a/tests/e2e/utils/pageObjects/adminHome.page.ts b/tests/e2e/utils/pageObjects/adminHome.page.ts index bc661873c..943bce86c 100644 --- a/tests/e2e/utils/pageObjects/adminHome.page.ts +++ b/tests/e2e/utils/pageObjects/adminHome.page.ts @@ -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() { diff --git a/tests/e2e/utils/pageObjects/wp/wpDashboard.page.ts b/tests/e2e/utils/pageObjects/wp/wpDashboard.page.ts index da808c665..adeacb858 100644 --- a/tests/e2e/utils/pageObjects/wp/wpDashboard.page.ts +++ b/tests/e2e/utils/pageObjects/wp/wpDashboard.page.ts @@ -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(); + } + } } diff --git a/tests/e2e/utils/pageObjects/wp/wpInitiativeDefine.page.ts b/tests/e2e/utils/pageObjects/wp/wpInitiativeDefine.page.ts index 8172ccc35..e787276e8 100644 --- a/tests/e2e/utils/pageObjects/wp/wpInitiativeDefine.page.ts +++ b/tests/e2e/utils/pageObjects/wp/wpInitiativeDefine.page.ts @@ -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); } } diff --git a/tests/e2e/utils/pageObjects/wp/wpInitiativeOverlay.page.ts b/tests/e2e/utils/pageObjects/wp/wpInitiativeOverlay.page.ts index d2caca840..25b85a6eb 100644 --- a/tests/e2e/utils/pageObjects/wp/wpInitiativeOverlay.page.ts +++ b/tests/e2e/utils/pageObjects/wp/wpInitiativeOverlay.page.ts @@ -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"; @@ -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) { @@ -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) { @@ -72,5 +73,6 @@ export class WPInitiativeOverlayPage extends BasePage { await fundingPage.fillFields(); } await fundingPage.backButton.click(); + await this.fundingSources.isVisible(); } } diff --git a/tests/e2e/wp/create.spec.ts b/tests/e2e/wp/create.spec.ts index cbb056a70..154d394ba 100644 --- a/tests/e2e/wp/create.spec.ts +++ b/tests/e2e/wp/create.spec.ts @@ -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"; @@ -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; @@ -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); @@ -40,6 +48,8 @@ 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 () => { @@ -47,10 +57,11 @@ test.afterAll(async () => { }); 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(); @@ -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(); @@ -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(); }