|
1 | 1 | import { MoreInformation } from "@src/app/_components/content/MoreInformation"; |
2 | 2 | import { VaccineType } from "@src/models/vaccine"; |
3 | | -import { ActionDisplayType, ButtonUrl, Content, Label } from "@src/services/eligibility-api/types"; |
4 | 3 | import { Campaigns } from "@src/utils/campaigns/types"; |
5 | 4 | import config from "@src/utils/config"; |
6 | 5 | 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"; |
12 | 7 | 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 | + |
14 | 20 |
|
15 | 21 | jest.mock("sanitize-data", () => ({ sanitize: jest.fn() })); |
16 | 22 | jest.mock("@src/utils/config"); |
17 | | -jest.mock("next/headers"); |
18 | 23 |
|
19 | | -describe("MoreInformation for COVID", () => { |
| 24 | +describe("MoreInformation component for COVID", () => { |
20 | 25 | const mockedConfig = config as ConfigMock; |
21 | 26 | const covid19VaccineType: VaccineType = VaccineType.COVID_19; |
| 27 | + const campaigns = new Campaigns({}); |
22 | 28 |
|
23 | 29 | 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(); |
36 | 31 | Object.assign(mockedConfig, defaultConfig); |
37 | | - |
38 | | - const mockHeaders = { |
39 | | - get: jest.fn(), |
40 | | - }; |
41 | | - (headers as jest.Mock).mockResolvedValue(mockHeaders); |
42 | 32 | }); |
43 | 33 |
|
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); |
48 | 36 |
|
49 | 37 | render(await MoreInformation({ styledVaccineContent: mockStyledContent, vaccineType: covid19VaccineType })); |
50 | 38 |
|
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)); |
117 | 42 | }); |
118 | 43 |
|
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); |
128 | 46 |
|
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 })); |
145 | 48 |
|
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)); |
149 | 52 | }); |
150 | 53 | }); |
151 | 54 |
|
@@ -291,3 +194,8 @@ const expectExpanderBlockToBePresent = (expanderHeading: string, expanderContent |
291 | 194 | expect(heading).toBeInTheDocument(); |
292 | 195 | expect(content).toBeInTheDocument(); |
293 | 196 | }; |
| 197 | + |
| 198 | +const expectExpanderBlockToNotBePresent = (expanderHeading: string, expanderContent: string) => { |
| 199 | + expect(screen.queryByText(expanderHeading)).toBeNull(); |
| 200 | + expect(screen.queryByText(expanderContent)).toBeNull(); |
| 201 | +}; |
0 commit comments