Skip to content

Commit be60d50

Browse files
VIA-294 AJ/DB Fix expanders opening for snapshots
1 parent eaaaea0 commit be60d50

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

e2e/helpers.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AxeBuilder from "@axe-core/playwright";
2-
import { Page, TestInfo, expect } from "@playwright/test";
2+
import { Locator, Page, TestInfo, expect } from "@playwright/test";
33
import { snapshotPathTemplate } from "@project/playwright.config";
44

55
declare global {
@@ -75,23 +75,29 @@ export const accessibilityCheck = async (page: Page) => {
7575
export const pathForCustomScreenshots = (testFileName: string, screenshotFileName: string, projectName: string) => {
7676
const baseFile: string = screenshotFileName.substring(0, screenshotFileName.lastIndexOf("."));
7777

78-
const path = snapshotPathTemplate
78+
return snapshotPathTemplate
7979
.replace("{testDir}", "./e2e")
8080
.replace("__snapshots__", "snapshot_review")
8181
.replace("{testFileName}", testFileName)
8282
.replace("{arg}", baseFile)
8383
.replace("{projectName}", projectName)
8484
.replace("{platform}", process.platform)
8585
.replace("{ext}", ".png");
86-
87-
return path;
8886
};
8987

90-
export const openExpanders = async (page: Page) => {
91-
const expanderTitles = ["What the vaccine is for", "Who should have the vaccine", "Side effects of the vaccine"];
88+
export const openExpandersIfPresent = async (page: Page) => {
89+
const expanderTitles = [
90+
"What the vaccine is for",
91+
"Who should have the vaccine",
92+
"How to get the vaccine",
93+
"Side effects of the vaccine",
94+
];
9295

9396
for (const title of expanderTitles) {
94-
await page.getByText(title).click();
97+
const expander: Locator = page.getByText(title);
98+
if ((await expander.count()) > 0) {
99+
await expander.click();
100+
}
95101
}
96102

97103
await page.mouse.click(0, 0);

e2e/snapshot/app.snapshot.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Page, TestInfo, expect, test } from "@playwright/test";
22
import { AppPageDetails, type PageDetails } from "@project/e2e/constants";
3-
import { getEnv, openExpanders, pathForCustomScreenshots } from "@project/e2e/helpers";
3+
import { getEnv, openExpandersIfPresent, pathForCustomScreenshots } from "@project/e2e/helpers";
44

55
const currentDatetime = getEnv("CURRENT_DATETIME");
66
const checkoutRef = getEnv("CHECKOUT_REF");
@@ -16,9 +16,7 @@ const testPageSnapshot = async (
1616
await page.goto(pageRoute);
1717
await page.getByRole("link", { name: "Log out" }).waitFor();
1818

19-
if ([AppPageDetails["rsv-older-adults"].url, AppPageDetails["rsv-pregnancy"].url].includes(pageRoute)) {
20-
await openExpanders(page);
21-
}
19+
await openExpandersIfPresent(page);
2220

2321
// This screenshot is NOT used for comparison; used to upload to S3 on failure
2422
await page.screenshot({

e2e/snapshot/eligibility.snapshot.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from "@playwright/test";
22
import { AppPageDetails } from "@project/e2e/constants";
3-
import { getEnv, openExpanders, pathForCustomScreenshots } from "@project/e2e/helpers";
3+
import { getEnv, openExpandersIfPresent, pathForCustomScreenshots } from "@project/e2e/helpers";
44
import users from "@test-data/test-users.json" with { type: "json" };
55

66
const currentDatetime = getEnv("CURRENT_DATETIME");
@@ -27,7 +27,7 @@ test.describe(`Snapshot Testing - Eligibility - ${currentDatetime}-${checkoutRef
2727

2828
await page.goto(AppPageDetails["rsv-older-adults"].url);
2929
await page.getByRole("link", { name: "Log out" }).waitFor();
30-
await openExpanders(page);
30+
await openExpandersIfPresent(page);
3131

3232
// This screenshot is NOT used for comparison; used to upload to S3 on failure
3333
await page.screenshot({

0 commit comments

Comments
 (0)