Skip to content

Commit 33a1de3

Browse files
VIA-629 SB Add in-campaign and no-campaign variants for Covid page to e2e and snapshot tests.
1 parent 9e2048a commit 33a1de3

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

e2e/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type VaccinePageName =
1717
| "flu-in-pregnancy"
1818
| "flu-vaccine"
1919
| "covid-19-vaccine"
20+
| "covid-19-vaccine-active-campaign"
2021
| "flu-for-children"
2122
| "flu-for-school-aged-children";
2223
type FailurePageName = "sso-failure" | "service-failure" | "service-failure-static" | "not-found";
@@ -29,6 +30,7 @@ export type PageDetails = {
2930
heading: string;
3031
title: string;
3132
snapshotFilename: string;
33+
datetimeOverride?: Date;
3234
};
3335

3436
const SERVICE_HEADING = "Check and book vaccinations";
@@ -157,6 +159,14 @@ export const AppPageDetails: Record<PageName, PageDetails> = {
157159
heading: "COVID-19 vaccine",
158160
title: `COVID-19 vaccine - ${SERVICE_HEADING} - ${NHS_TITLE_SUFFIX}`,
159161
snapshotFilename: "default-covid-19-vaccine.png",
162+
datetimeOverride: new Date("2026-06-01"),
163+
},
164+
"covid-19-vaccine-active-campaign": {
165+
url: "/vaccines/covid-19-vaccine",
166+
heading: "COVID-19 vaccine",
167+
title: `COVID-19 vaccine - ${SERVICE_HEADING} - ${NHS_TITLE_SUFFIX}`,
168+
snapshotFilename: "default-covid-19-vaccine-active-campaign.png",
169+
datetimeOverride: new Date("2025-12-01"),
160170
},
161171
"flu-for-children": {
162172
url: "/vaccines/flu-vaccine-for-children",

e2e/general/app.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ test.describe("Application", () => {
1212
test(`Check title, heading, accessibility, LCP performance for ${pageName} page`, async ({
1313
page,
1414
}, testInfo: TestInfo) => {
15+
if (pageDetails.datetimeOverride)
16+
await page.setExtraHTTPHeaders({ "x-e2e-datetime": pageDetails.datetimeOverride.toISOString() });
1517
await page.goto(pageDetails.url);
1618
await expect(page).toHaveTitle(pageDetails.title);
1719
await expect(page.getByRole("heading", { level: 1, name: pageDetails.heading })).toBeVisible();

e2e/snapshot/app.snapshot.spec.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,26 @@ import { getEnv, openExpandersIfPresent, pathForCustomScreenshots } from "@proje
55
const currentDatetime = getEnv("CURRENT_DATETIME");
66
const checkoutRef = getEnv("CHECKOUT_REF");
77

8-
const testPageSnapshot = async (
9-
page: Page,
10-
snapshotFileName: string,
11-
pageRoute: string,
12-
testFileName: string,
13-
projectName: string,
14-
) => {
15-
const screenshotPath: string = pathForCustomScreenshots(testFileName, snapshotFileName, projectName);
16-
await page.goto(pageRoute);
8+
const testPageSnapshot = async (page: Page, pageDetails: PageDetails, testFileName: string, projectName: string) => {
9+
const screenshotPath: string = pathForCustomScreenshots(testFileName, pageDetails.snapshotFilename, projectName);
10+
11+
if (pageDetails.datetimeOverride)
12+
await page.setExtraHTTPHeaders({ "x-e2e-datetime": pageDetails.datetimeOverride.toISOString() });
13+
14+
await page.goto(pageDetails.url);
1715

1816
// wait for specific elements on the page, as they may take longer to load
19-
if (pageRoute !== AppPageDetails["service-failure-static"].url) {
17+
if (pageDetails.url !== AppPageDetails["service-failure-static"].url) {
2018
await page.getByRole("link", { name: "Log out" }).waitFor();
2119
}
2220

2321
await openExpandersIfPresent(page);
2422

2523
// This screenshot is NOT used for comparison; used to upload to S3 on failure
26-
await page.screenshot({
27-
path: screenshotPath,
28-
fullPage: true,
29-
scale: "device",
30-
});
24+
await page.screenshot({ path: screenshotPath, fullPage: true, scale: "device" });
3125

3226
// This screenshot IS used for comparison with the snapshot from S3
33-
await expect.soft(page).toHaveScreenshot(snapshotFileName, {
34-
fullPage: true,
35-
scale: "device",
36-
});
27+
await expect.soft(page).toHaveScreenshot(pageDetails.snapshotFilename, { fullPage: true, scale: "device" });
3728
};
3829

3930
test.describe(`Snapshot Testing - ${currentDatetime}-${checkoutRef}`, () => {
@@ -44,7 +35,7 @@ test.describe(`Snapshot Testing - ${currentDatetime}-${checkoutRef}`, () => {
4435
const projectName = testInfo.project.name;
4536
const testFileName = testInfo.file.split("/").pop()!;
4637

47-
await testPageSnapshot(page, pageDetails.snapshotFilename, pageDetails.url, testFileName, projectName);
38+
await testPageSnapshot(page, pageDetails, testFileName, projectName);
4839
});
4940
});
5041
});

src/services/content-api/parsers/custom/covid-19.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ export const buildFilteredContentForCovid19Vaccine = async (apiContent: string):
2727
let callout: HeadingWithTypedContent | undefined;
2828
const actions: Action[] = [];
2929
if (campaigns.isActive(VaccineType.COVID_19, now)) {
30-
log.debug({ context: { campaigns, vaccineType: VaccineType.COVID_19 } }, "Campaign active");
30+
log.debug({ context: { campaigns, vaccineType: VaccineType.COVID_19, now: now.toISOString() } }, "Campaign active");
3131
callout = undefined;
3232
actions.push(...(await _buildActions()));
3333
} else {
34-
log.debug({ context: { campaigns, vaccineType: VaccineType.COVID_19 } }, "No campaign active");
34+
log.debug(
35+
{ context: { campaigns, vaccineType: VaccineType.COVID_19, now: now.toISOString() } },
36+
"No campaign active",
37+
);
3538
callout = {
3639
heading: "Booking service closed",
3740
content: [
@@ -56,9 +59,7 @@ export const buildFilteredContentForCovid19Vaccine = async (apiContent: string):
5659

5760
async function _getNow() {
5861
const headersList = await headers();
59-
const now = UtcDateTimeFromStringSchema.safeParse(headersList.get("x-e2e-datetime")).data ?? new Date();
60-
log.debug({ context: { headersList, now: now.toDateString() } }, "headers");
61-
return now;
62+
return UtcDateTimeFromStringSchema.safeParse(headersList.get("x-e2e-datetime")).data ?? new Date();
6263
}
6364

6465
async function _buildActions(): Promise<Action[]> {

0 commit comments

Comments
 (0)