@@ -7,41 +7,19 @@ import { VaccineType } from "@src/models/vaccine";
77import { getContentForVaccine } from "@src/services/content-api/content-service" ;
88import { ContentErrorTypes } from "@src/services/content-api/types" ;
99import { getEligibilityForPerson } from "@src/services/eligibility-api/domain/eligibility-filter-service" ;
10- import { EligibilityErrorTypes , EligibilityForPersonType , EligibilityStatus } from "@src/services/eligibility-api/types" ;
10+ import {
11+ EligibilityErrorTypes ,
12+ EligibilityForPersonType ,
13+ EligibilityStatus ,
14+ } from "@src/services/eligibility-api/types" ;
1115import { Campaigns } from "@src/utils/campaigns/types" ;
1216import config from "@src/utils/config" ;
1317import { ConfigMock , configBuilder } from "@test-data/config/builders" ;
1418import { mockStyledContent } from "@test-data/content-api/data" ;
1519import { eligibilityContentBuilder } from "@test-data/eligibility-api/builders" ;
1620import { render , screen } from "@testing-library/react" ;
17- import { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers" ;
18- import { headers } from "next/headers" ;
1921import React , { JSX } from "react" ;
2022
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
4523jest . mock ( "@src/services/content-api/content-service" , ( ) => ( {
4624 getContentForVaccine : jest . fn ( ) ,
4725} ) ) ;
@@ -88,11 +66,9 @@ jest.mock("cheerio", () => ({
8866 attr : jest . fn ( ) ,
8967 } ) ) ;
9068
91- const $ = Object . assign ( selectorImpl , {
69+ return Object . assign ( selectorImpl , {
9270 html : jest . fn ( ( ) => "<p>HTML fragment</p>" ) ,
9371 } ) ;
94-
95- return $ ;
9672 } ) ,
9773} ) ) ;
9874
@@ -121,28 +97,21 @@ const contentErrorResponse = {
12197} ;
12298
12399describe ( "Any vaccine page" , ( ) => {
124-
125100 const mockedConfig = config as ConfigMock ;
126101
127102 beforeEach ( ( ) => {
128103 const defaultConfig = configBuilder ( )
129104 . withCampaigns (
130105 Campaigns . fromJson (
131106 JSON . stringify ( {
132- COVID_19 : [
133- { start : "2025-11-01T09:00:00Z" , end : "2026-01-31T09:00:00Z" }
134- ] ,
107+ COVID_19 : [ { start : "2025-11-01T09:00:00Z" , end : "2026-01-31T09:00:00Z" } ] ,
135108 } ) ,
136109 ) ! ,
137110 )
138111 . build ( ) ;
139112 Object . assign ( mockedConfig , defaultConfig ) ;
140113 } ) ;
141114
142- const renderNamedVaccinePage = async ( vaccineType : VaccineType ) => {
143- render ( await Vaccine ( { vaccineType : vaccineType } ) ) ;
144- } ;
145-
146115 const renderRsvVaccinePage = async ( ) => {
147116 await renderNamedVaccinePage ( VaccineType . RSV ) ;
148117 } ;
@@ -161,12 +130,6 @@ describe("Any vaccine page", () => {
161130 nhs_number : nhsNumber ,
162131 } ,
163132 } ) ;
164- const fakeHeaders : ReadonlyHeaders = {
165- get ( name : string ) : string | null {
166- return `fake-${ name } -header` ;
167- } ,
168- } as ReadonlyHeaders ;
169- ( headers as jest . Mock ) . mockResolvedValue ( fakeHeaders ) ;
170133 } ) ;
171134
172135 describe ( "shows content section, when content available" , ( ) => {
@@ -257,6 +220,61 @@ describe("Any vaccine page", () => {
257220 } ) ;
258221 } ) ;
259222
223+ describe ( "shows callouts and actions for Vaccines that handle campaigns (COVID_19)" , ( ) => {
224+ const mockedConfig = config as ConfigMock ;
225+ const campaigns = new Campaigns ( { } ) ;
226+ const covid19VaccineType = VaccineType . COVID_19 ;
227+
228+ beforeEach ( ( ) => {
229+ ( getContentForVaccine as jest . Mock ) . mockResolvedValue ( contentSuccessResponse ) ;
230+ ( getEligibilityForPerson as jest . Mock ) . mockResolvedValue ( eligibilitySuccessResponse ) ;
231+ const defaultConfig = configBuilder ( ) . withCampaigns ( campaigns ) . build ( ) ;
232+ Object . assign ( mockedConfig , defaultConfig ) ;
233+ } ) ;
234+
235+ it ( "should include callout text when campaign is inactive" , async ( ) => {
236+ const inactiveCampaignSpy = jest . spyOn ( campaigns , "isActive" ) . mockReturnValue ( false ) ;
237+ await renderNamedVaccinePage ( covid19VaccineType ) ;
238+
239+ const calloutText : HTMLElement = screen . getByTestId ( "callout" ) ;
240+
241+ expect ( inactiveCampaignSpy ) . toHaveBeenCalledWith ( covid19VaccineType , expect . any ( Date ) ) ;
242+ expect ( calloutText ) . toBeInTheDocument ( ) ;
243+ inactiveCampaignSpy . mockRestore ( ) ;
244+ } ) ;
245+
246+ it ( "should not include callout text when campaign is active" , async ( ) => {
247+ const activeCampaignSpy = jest . spyOn ( campaigns , "isActive" ) . mockReturnValue ( true ) ;
248+ await renderNamedVaccinePage ( covid19VaccineType ) ;
249+
250+ const calloutText : HTMLElement | null = screen . queryByTestId ( "callout" ) ;
251+
252+ expect ( activeCampaignSpy ) . toHaveBeenCalledWith ( covid19VaccineType , expect . any ( Date ) ) ;
253+ expect ( calloutText ) . toBeNull ( ) ;
254+ activeCampaignSpy . mockRestore ( ) ;
255+ } ) ;
256+
257+ it ( "should include actions when campaign is active" , async ( ) => {
258+ const activeCampaignSpy = jest . spyOn ( campaigns , "isActive" ) . mockReturnValue ( true ) ;
259+ await renderNamedVaccinePage ( covid19VaccineType ) ;
260+
261+ const actions : HTMLElement = screen . getByTestId ( "eligibility-actions-mock" ) ;
262+ expect ( activeCampaignSpy ) . toHaveBeenCalledWith ( covid19VaccineType , expect . any ( Date ) ) ;
263+ expect ( actions ) . toBeInTheDocument ( ) ;
264+ activeCampaignSpy . mockRestore ( ) ;
265+ } ) ;
266+
267+ it ( "should not include actions when campaign is inactive" , async ( ) => {
268+ const inactiveCampaignSpy = jest . spyOn ( campaigns , "isActive" ) . mockReturnValue ( false ) ;
269+ await renderNamedVaccinePage ( covid19VaccineType ) ;
270+
271+ const actions : HTMLElement | null = screen . queryByTestId ( "eligibility-actions-mock" ) ;
272+ expect ( inactiveCampaignSpy ) . toHaveBeenCalledWith ( covid19VaccineType , expect . any ( Date ) ) ;
273+ expect ( actions ) . toBeNull ( ) ;
274+ inactiveCampaignSpy . mockRestore ( ) ;
275+ } ) ;
276+ } ) ;
277+
260278 describe ( "shows content section, when content load fails" , ( ) => {
261279 beforeEach ( ( ) => {
262280 ( getContentForVaccine as jest . Mock ) . mockResolvedValue ( contentErrorResponse ) ;
@@ -440,6 +458,10 @@ describe("Any vaccine page", () => {
440458 } ) ;
441459 } ) ;
442460
461+ const renderNamedVaccinePage = async ( vaccineType : VaccineType ) => {
462+ render ( await Vaccine ( { vaccineType : vaccineType } ) ) ;
463+ } ;
464+
443465 const expectRenderEligibilitySectionWith = (
444466 vaccineType : VaccineType ,
445467 eligibilityForPerson : EligibilityForPersonType ,
0 commit comments