Skip to content

Commit 7261dec

Browse files
VIA-245 MD/AJ Refactored the snapshot test to remove duplication
1 parent ccb0b2b commit 7261dec

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

e2e/snapshot/app.snapshot.spec.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,38 @@ import { HUB_PAGE_URL, RSV_PAGE_URL, RSV_PREGNANCY_PAGE_URL } from "../constants
99
test.describe("E2E", () => {
1010
let page: Page;
1111
let projectName: string;
12-
let fileName: string;
12+
let testFileName: string;
1313

1414
test.beforeAll(async ({ browser }, testInfo: TestInfo) => {
1515
testInfo.setTimeout(60000);
1616
page = await login(browser, users.Default.email);
1717
projectName = testInfo.project.name;
18-
fileName = testInfo.file.split("/").pop()!;
18+
testFileName = testInfo.file.split("/").pop()!;
1919

2020
await page.mouse.move(0, 0);
2121
});
2222

23-
test("Page Snapshots", async () => {
24-
let screenshotFileName: string;
25-
let customScreenshotPath: string;
26-
27-
screenshotFileName = "default-hub.png";
28-
customScreenshotPath = pathForCustomScreenshots(fileName, screenshotFileName, projectName);
29-
await page.goto(HUB_PAGE_URL);
23+
const testPageSnapshot = async (snapshotFileName: string, pageRoute: string) => {
24+
const screenshotPath: string = pathForCustomScreenshots(testFileName, snapshotFileName, projectName);
25+
await page.goto(pageRoute);
3026
await page.screenshot({
31-
path: customScreenshotPath,
27+
path: screenshotPath,
3228
fullPage: true,
3329
});
34-
await expect.soft(page).toHaveScreenshot(screenshotFileName, {
30+
await expect.soft(page).toHaveScreenshot(snapshotFileName, {
3531
fullPage: true,
3632
});
33+
};
3734

38-
screenshotFileName = "default-rsv.png";
39-
customScreenshotPath = pathForCustomScreenshots(fileName, screenshotFileName, projectName);
40-
await page.goto(RSV_PAGE_URL);
41-
await page.screenshot({
42-
path: customScreenshotPath,
43-
fullPage: true,
44-
});
45-
await expect.soft(page).toHaveScreenshot(screenshotFileName, {
46-
fullPage: true,
47-
});
35+
const PathsToSnapshots = [
36+
{ snapshotFilename: "default-hub.png", pageRoute: HUB_PAGE_URL },
37+
{ snapshotFilename: "default-rsv.png", pageRoute: RSV_PAGE_URL },
38+
{ snapshotFilename: "default-rsv-pregnancy.png", pageRoute: RSV_PREGNANCY_PAGE_URL },
39+
];
4840

49-
screenshotFileName = "default-rsv-pregnancy.png";
50-
customScreenshotPath = pathForCustomScreenshots(fileName, screenshotFileName, projectName);
51-
await page.goto(RSV_PREGNANCY_PAGE_URL);
52-
await page.screenshot({
53-
path: customScreenshotPath,
54-
fullPage: true,
55-
});
56-
await expect.soft(page).toHaveScreenshot(screenshotFileName, {
57-
fullPage: true,
41+
PathsToSnapshots.forEach(({ snapshotFilename, pageRoute }) => {
42+
test(`Testing snapshot for ${pageRoute}`, async () => {
43+
await testPageSnapshot(snapshotFilename, pageRoute);
5844
});
5945
});
6046
});

0 commit comments

Comments
 (0)