Skip to content

Commit 89626aa

Browse files
VIA-629 AJ/EO Add tests for MoreInformation for COVID vaccine with campaign states
1 parent 73aab8c commit 89626aa

File tree

2 files changed

+34
-137
lines changed

2 files changed

+34
-137
lines changed

src/app/_components/content/MoreInformation.test.tsx

Lines changed: 32 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,54 @@
11
import { MoreInformation } from "@src/app/_components/content/MoreInformation";
22
import { VaccineType } from "@src/models/vaccine";
3-
import { ActionDisplayType, ButtonUrl, Content, Label } from "@src/services/eligibility-api/types";
43
import { Campaigns } from "@src/utils/campaigns/types";
54
import config from "@src/utils/config";
65
import { ConfigMock, configBuilder } from "@test-data/config/builders";
7-
import {
8-
genericVaccineContentAPIResponse,
9-
mockStyledContent,
10-
mockStyledContentWithoutWhatSection,
11-
} from "@test-data/content-api/data";
6+
import { mockStyledContent, mockStyledContentWithoutWhatSection } from "@test-data/content-api/data";
127
import { render, screen } from "@testing-library/react";
13-
import { headers } from "next/headers";
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
1420

1521
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
1622
jest.mock("@src/utils/config");
17-
jest.mock("next/headers");
1823

19-
describe("MoreInformation for COVID", () => {
24+
describe("MoreInformation component for COVID", () => {
2025
const mockedConfig = config as ConfigMock;
2126
const covid19VaccineType: VaccineType = VaccineType.COVID_19;
27+
const campaigns = new Campaigns({});
2228

2329
beforeEach(() => {
24-
const defaultConfig = configBuilder()
25-
.withCampaigns(
26-
Campaigns.fromJson(
27-
JSON.stringify({
28-
COVID_19: [
29-
{ start: "2025-11-01T09:00:00Z", end: "2026-01-31T09:00:00Z" },
30-
{ start: "2026-11-01T09:00:00Z", end: "2027-01-31T09:00:00Z" },
31-
],
32-
}),
33-
)!,
34-
)
35-
.build();
30+
const defaultConfig = configBuilder().withCampaigns(campaigns).build();
3631
Object.assign(mockedConfig, defaultConfig);
37-
38-
const mockHeaders = {
39-
get: jest.fn(),
40-
};
41-
(headers as jest.Mock).mockResolvedValue(mockHeaders);
4232
});
4333

44-
jest.useFakeTimers();
45-
46-
it("should return standard vaccine content and additional content for COVID-19 vaccine", async () => {
47-
jest.setSystemTime(new Date("2025-10-01"));
34+
it("should not show how-to-get expander section for COVID-19 vaccine when campaign is active", async () => {
35+
const activeCampaignSpy = jest.spyOn(campaigns, "isActive").mockReturnValue(true);
4836

4937
render(await MoreInformation({ styledVaccineContent: mockStyledContent, vaccineType: covid19VaccineType }));
5038

51-
// COVID-19 vaccine content (closed campaign)
52-
expectExpanderBlockToBePresent("How to get the vaccine", "How Section styled component");
53-
expectExpanderBlockToBePresent("Callout Heading", "");
54-
// expect(pageCopyForCovid19Vaccine.recommendation?.heading).toEqual("The COVID-19 vaccine is recommended if you:");
55-
});
56-
57-
it("should return a callout but no actions when no campaign is active", async () => {
58-
// Given
59-
jest.setSystemTime(new Date("2025-10-01"));
60-
61-
const expected = {
62-
callout: {
63-
heading: "Booking service closed",
64-
content:
65-
"You can no longer book a COVID-19 vaccination using this online service\n\n" +
66-
"Bookings can also no longer be made through the 119 service.\n\n" +
67-
"COVID-19 vaccinations will be available again in spring.",
68-
contentType: "markdown",
69-
},
70-
};
71-
72-
// When
73-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
74-
75-
// Then
76-
expect(pageCopy).toEqual(expect.objectContaining(expected));
77-
expect(pageCopy.actions).toHaveLength(0);
78-
});
79-
80-
it("should return actions but no callout when no campaign is active", async () => {
81-
// Given
82-
jest.setSystemTime(new Date("2025-12-01"));
83-
84-
const expected = {
85-
actions: [
86-
{
87-
type: ActionDisplayType.buttonWithInfo,
88-
content: "## If this applies to you\n\n### Book an appointment online at a pharmacy" as Content,
89-
button: {
90-
label: "Continue to booking" as Label,
91-
url: new URL("https://test-nbs-url.example.com/sausages") as ButtonUrl,
92-
},
93-
delineator: true,
94-
},
95-
{
96-
type: ActionDisplayType.actionLinkWithInfo,
97-
content: ("## Get vaccinated without an appointment\n\n" +
98-
"You can find a walk-in COVID-19 vaccination site to get a vaccination without an appointment. " +
99-
"You do not need to be registered with a GP.") as Content,
100-
button: {
101-
label: "Find a walk-in COVID-19 vaccination site" as Label,
102-
url: new URL(
103-
"https://www.nhs.uk/nhs-services/vaccination-and-booking-services/find-a-walk-in-covid-19-vaccination-site/",
104-
) as ButtonUrl,
105-
},
106-
delineator: false,
107-
},
108-
],
109-
};
110-
111-
// When
112-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
113-
114-
// Then
115-
expect(pageCopy).toEqual(expect.objectContaining(expected));
116-
expect(pageCopy.callout).toBeUndefined();
39+
// COVID-19 vaccine content (active campaign)
40+
expectExpanderBlockToNotBePresent("How to get the vaccine", "How Section styled component");
41+
expect(activeCampaignSpy).toHaveBeenCalledWith(covid19VaccineType, expect.any(Date));
11742
});
11843

119-
describe("with x-e2e-datetime header set", () => {
120-
it("should return a callout but no actions when no campaign is active", async () => {
121-
const mockHeaders = {
122-
get: jest.fn((key: string) => {
123-
if (key === "x-e2e-datetime") return "2025-10-01T12:00:00Z";
124-
return null;
125-
}),
126-
};
127-
(headers as jest.Mock).mockResolvedValue(mockHeaders);
44+
it("should show how-to-get expander section for COVID-19 vaccine when campaign is inactive", async () => {
45+
const inactiveCampaignSpy = jest.spyOn(campaigns, "isActive").mockReturnValue(false);
12846

129-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
130-
131-
expect(pageCopy.callout).not.toBeUndefined();
132-
expect(pageCopy.actions).toHaveLength(0);
133-
});
134-
135-
it("should return actions but no callout when no campaign is active", async () => {
136-
const mockHeaders = {
137-
get: jest.fn((key: string) => {
138-
if (key === "x-e2e-datetime") return "2025-12-01T12:00:00Z";
139-
return null;
140-
}),
141-
};
142-
(headers as jest.Mock).mockResolvedValue(mockHeaders);
143-
144-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
47+
render(await MoreInformation({ styledVaccineContent: mockStyledContent, vaccineType: covid19VaccineType }));
14548

146-
expect(pageCopy.callout).toBeUndefined();
147-
expect(pageCopy.actions).not.toHaveLength(0);
148-
});
49+
// COVID-19 vaccine content (closed campaign)
50+
expectExpanderBlockToBePresent("How to get the vaccine", "How Section styled component");
51+
expect(inactiveCampaignSpy).toHaveBeenCalledWith(covid19VaccineType, expect.any(Date));
14952
});
15053
});
15154

@@ -291,3 +194,8 @@ const expectExpanderBlockToBePresent = (expanderHeading: string, expanderContent
291194
expect(heading).toBeInTheDocument();
292195
expect(content).toBeInTheDocument();
293196
};
197+
198+
const expectExpanderBlockToNotBePresent = (expanderHeading: string, expanderContent: string) => {
199+
expect(screen.queryByText(expanderHeading)).toBeNull();
200+
expect(screen.queryByText(expanderContent)).toBeNull();
201+
};

src/app/_components/content/MoreInformation.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { HEADINGS } from "@src/app/constants";
55
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
66
import { StyledVaccineContent } from "@src/services/content-api/types";
77
import config from "@src/utils/config";
8-
import { UtcDateTimeFromStringSchema } from "@src/utils/date";
9-
import { headers } from "next/headers";
8+
import { getNow } from "@src/utils/date";
109
import { Details } from "nhsuk-react-components";
1110
import React, { JSX } from "react";
1211

@@ -16,17 +15,7 @@ const MoreInformation = async (props: {
1615
vaccineType: VaccineType;
1716
}): Promise<JSX.Element> => {
1817
const campaigns = await config.CAMPAIGNS;
19-
const now = await _getNow();
20-
const isCampaignActive: boolean = campaigns.isActive(props.vaccineType, now);
21-
22-
async function _getNow() {
23-
try {
24-
const headersList = await headers();
25-
return UtcDateTimeFromStringSchema.safeParse(headersList.get("x-e2e-datetime")).data ?? new Date();
26-
} catch {
27-
return new Date();
28-
}
29-
}
18+
const isCampaignActive: boolean = campaigns.isActive(props.vaccineType, await getNow());
3019

3120
const vaccineInfo = VaccineInfo[props.vaccineType];
3221
const showHowToGetExpander = vaccineInfo.removeHowToGetExpanderFromMoreInformationSection ? false : !isCampaignActive;

0 commit comments

Comments
 (0)