Skip to content

Commit 9772867

Browse files
VIA-629 SB/AJ/EO Refactoring in progress. Hides How to get expander, but breaks the "how to get section" that lives on the main page (eg Flu in school aged children)
1 parent bb29546 commit 9772867

23 files changed

+179
-81
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { MoreInformation } from "@src/app/_components/content/MoreInformation";
22
import { VaccineType } from "@src/models/vaccine";
3-
import { mockStyledContent, mockStyledContentWithoutWhatSection } from "@test-data/content-api/data";
3+
import {
4+
mockStyledContent,
5+
mockStyledContentWithoutHowToGet,
6+
mockStyledContentWithoutWhatSection,
7+
} from "@test-data/content-api/data";
48
import { render, screen } from "@testing-library/react";
59
import React from "react";
610

@@ -67,7 +71,7 @@ describe("MoreInformation component ", () => {
6771

6872
it("should not include 'how to get' section for RSV_PREGNANCY ", async () => {
6973
const vaccineType = VaccineType.RSV_PREGNANCY;
70-
render(<MoreInformation styledVaccineContent={mockStyledContent} vaccineType={vaccineType} />);
74+
render(<MoreInformation styledVaccineContent={mockStyledContentWithoutHowToGet} vaccineType={vaccineType} />);
7175

7276
const heading: HTMLElement | null = screen.queryByText("How to get the vaccine");
7377

@@ -76,7 +80,7 @@ describe("MoreInformation component ", () => {
7680

7781
it("should not include 'how to get' section for RSV ", async () => {
7882
const vaccineType = VaccineType.RSV;
79-
render(<MoreInformation styledVaccineContent={mockStyledContent} vaccineType={vaccineType} />);
83+
render(<MoreInformation styledVaccineContent={mockStyledContentWithoutHowToGet} vaccineType={vaccineType} />);
8084

8185
const heading: HTMLElement | null = screen.queryByText("How to get the vaccine");
8286

src/app/_components/content/MoreInformation.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const MoreInformation = (props: {
1111
vaccineType: VaccineType;
1212
}): JSX.Element => {
1313
const vaccineInfo = VaccineInfo[props.vaccineType];
14-
const showHowToGetExpander =
15-
vaccineInfo.removeHowToGetExpanderFromMoreInformationSection === undefined ||
16-
!vaccineInfo.removeHowToGetExpanderFromMoreInformationSection;
17-
1814
return (
1915
<>
2016
<Details.ExpanderGroup data-testid="more-information-expander-group">
@@ -41,7 +37,7 @@ const MoreInformation = (props: {
4137
</Details>
4238

4339
{/* How-to-get-the-vaccine expandable section */}
44-
{showHowToGetExpander && (
40+
{props.styledVaccineContent.howToGetVaccine && (
4541
<Details expander>
4642
<Details.Summary>
4743
{vaccineInfo.moreInformationHeadersFromContentApi

src/app/_components/eligibility/EligibilityVaccinePageContent.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("EligibilityVaccinePageContent", () => {
6363

6464
expect(RSVEligibilityFallback).toHaveBeenCalledWith(
6565
{
66-
howToGetVaccineFallback: mockStyledContent.howToGetVaccine.component,
66+
howToGetVaccineFallback: mockStyledContent.howToGetVaccine?.component,
6767
vaccineType,
6868
},
6969
undefined,

src/app/_components/vaccine/Vaccine.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe("Any vaccine page", () => {
187187
expect(RSVPregnancyInfo).toHaveBeenCalledWith(
188188
{
189189
vaccineType: VaccineType.RSV_PREGNANCY,
190-
howToGetVaccineOrFallback: mockStyledContent.howToGetVaccine.component,
190+
howToGetVaccineOrFallback: mockStyledContent.howToGetVaccine?.component,
191191
},
192192
undefined,
193193
);
@@ -293,7 +293,7 @@ describe("Any vaccine page", () => {
293293
expectRenderEligibilitySectionWith(
294294
VaccineType.RSV,
295295
eligibilitySuccessResponse,
296-
mockStyledContent.howToGetVaccine.component,
296+
mockStyledContent.howToGetVaccine?.component,
297297
);
298298
});
299299

@@ -335,7 +335,7 @@ describe("Any vaccine page", () => {
335335
expectRenderEligibilitySectionWith(
336336
VaccineType.RSV,
337337
eligibilityResponseWithNoContentSection,
338-
mockStyledContent.howToGetVaccine.component,
338+
mockStyledContent.howToGetVaccine?.component,
339339
);
340340
});
341341

@@ -347,7 +347,7 @@ describe("Any vaccine page", () => {
347347
expectRenderEligibilitySectionWith(
348348
VaccineType.RSV,
349349
eligibilityErrorResponse,
350-
mockStyledContent.howToGetVaccine.component,
350+
mockStyledContent.howToGetVaccine?.component,
351351
);
352352
});
353353

@@ -374,7 +374,7 @@ describe("Any vaccine page", () => {
374374
expectRenderEligibilitySectionWith(
375375
VaccineType.RSV,
376376
eligibilityErrorResponse,
377-
mockStyledContent.howToGetVaccine.component,
377+
mockStyledContent.howToGetVaccine?.component,
378378
);
379379
});
380380
});
@@ -401,7 +401,7 @@ describe("Any vaccine page", () => {
401401
const expectRenderEligibilitySectionWith = (
402402
vaccineType: VaccineType,
403403
eligibilityForPerson: EligibilityForPersonType,
404-
howToGetVaccineOrFallback: JSX.Element,
404+
howToGetVaccineOrFallback?: JSX.Element,
405405
) => {
406406
const eligibilitySection: HTMLElement = screen.getByTestId("eligibility-page-content-mock");
407407
expect(eligibilitySection).toBeInTheDocument();

src/app/_components/vaccine/Vaccine.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const VaccineComponent = async ({ vaccineType }: VaccineProps): Promise<JSX.Elem
5858
}
5959

6060
const howToGetVaccineOrFallback = styledVaccineContent ? (
61-
styledVaccineContent.howToGetVaccine.component
61+
styledVaccineContent.howToGetVaccine?.component || <></>
6262
) : (
6363
<HowToGetVaccineFallback vaccineType={vaccineType} />
6464
);

src/services/content-api/parsers/content-filter-service.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,46 +745,58 @@ describe("Content Filter", () => {
745745

746746
await getFilteredContentForVaccine(VaccineType.WHOOPING_COUGH, mockApiContent);
747747

748-
expect(buildFilteredContentForWhoopingCoughVaccine).toHaveBeenCalledWith(mockApiContent);
748+
expect(buildFilteredContentForWhoopingCoughVaccine).toHaveBeenCalledWith(
749+
mockApiContent,
750+
VaccineType.WHOOPING_COUGH,
751+
);
749752
});
750753

751754
it("should call getFilteredContentForFluVaccine for flu vaccine", async () => {
752755
const mockApiContent = "testContent";
753756

754757
await getFilteredContentForVaccine(VaccineType.FLU_FOR_ADULTS, mockApiContent);
755758

756-
expect(buildFilteredContentForFluVaccine).toHaveBeenCalledWith(mockApiContent);
759+
expect(buildFilteredContentForFluVaccine).toHaveBeenCalledWith(mockApiContent, VaccineType.FLU_FOR_ADULTS);
757760
});
758761

759762
it("should call getFilteredContentForFluInPregnancyVaccine for flu in pregnancy vaccine", async () => {
760763
const mockApiContent = "testContent";
761764

762765
await getFilteredContentForVaccine(VaccineType.FLU_IN_PREGNANCY, mockApiContent);
763766

764-
expect(buildFilteredContentForFluInPregnancyVaccine).toHaveBeenCalledWith(mockApiContent);
767+
expect(buildFilteredContentForFluInPregnancyVaccine).toHaveBeenCalledWith(
768+
mockApiContent,
769+
VaccineType.FLU_IN_PREGNANCY,
770+
);
765771
});
766772

767773
it("should call getFilteredContentForFluForChildrenVaccine for flu for children vaccine", async () => {
768774
const mockApiContent = "testContent";
769775

770776
await getFilteredContentForVaccine(VaccineType.FLU_FOR_CHILDREN, mockApiContent);
771777

772-
expect(buildFilteredContentForFluForChildrenVaccine).toHaveBeenCalledWith(mockApiContent);
778+
expect(buildFilteredContentForFluForChildrenVaccine).toHaveBeenCalledWith(
779+
mockApiContent,
780+
VaccineType.FLU_FOR_CHILDREN,
781+
);
773782
});
774783

775784
it("should return standard vaccine content and recommendation for school aged children's flu vaccine", async () => {
776785
const mockApiContent = "testContent";
777786

778787
await getFilteredContentForVaccine(VaccineType.FLU_FOR_SCHOOL_AGED_CHILDREN, mockApiContent);
779-
expect(buildFilteredContentForFluForSchoolAgedChildrenVaccine).toHaveBeenCalledWith(mockApiContent);
788+
expect(buildFilteredContentForFluForSchoolAgedChildrenVaccine).toHaveBeenCalledWith(
789+
mockApiContent,
790+
VaccineType.FLU_FOR_SCHOOL_AGED_CHILDREN,
791+
);
780792
});
781793

782794
it("should call buildFilteredContentForCovid19Vaccine for flu in pregnancy vaccine", async () => {
783795
const mockApiContent = "testContent";
784796

785797
await getFilteredContentForVaccine(VaccineType.COVID_19, mockApiContent);
786798

787-
expect(buildFilteredContentForCovid19Vaccine).toHaveBeenCalledWith(mockApiContent);
799+
expect(buildFilteredContentForCovid19Vaccine).toHaveBeenCalledWith(mockApiContent, VaccineType.COVID_19);
788800
});
789801
});
790802
});

src/services/content-api/parsers/content-filter-service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VaccineType } from "@src/models/vaccine";
1+
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
22
import { buildFilteredContentForCovid19Vaccine } from "@src/services/content-api/parsers/custom/covid-19";
33
import { buildFilteredContentForFluForChildrenVaccine } from "@src/services/content-api/parsers/custom/flu-for-children";
44
import { buildFilteredContentForFluForSchoolAgedChildrenVaccine } from "@src/services/content-api/parsers/custom/flu-for-school-aged-children";
@@ -222,10 +222,13 @@ const getFilteredContentForVaccine = async (
222222
[VaccineType.COVID_19, buildFilteredContentForCovid19Vaccine],
223223
]);
224224
const filteredContentBuilder = filteredContentBuilders.get(vaccineType) || buildFilteredContentForStandardVaccine;
225-
return await filteredContentBuilder(apiContent);
225+
return await filteredContentBuilder(apiContent, vaccineType);
226226
};
227227

228-
const buildFilteredContentForStandardVaccine = async (apiContent: string): Promise<VaccinePageContent> => {
228+
const buildFilteredContentForStandardVaccine = async (
229+
apiContent: string,
230+
vaccineType: VaccineType,
231+
): Promise<VaccinePageContent> => {
229232
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
230233

231234
const overview: Overview = { content: _extractDescriptionForVaccine(content, "lead paragraph"), containsHtml: false };
@@ -245,10 +248,13 @@ const buildFilteredContentForStandardVaccine = async (apiContent: string): Promi
245248
.concat(_extractPartsForAspect(content, "ContraindicationsHealthAspect")),
246249
};
247250

248-
const howToGetVaccine: VaccinePageSection = {
249-
headline: _extractHeadlineForAspect(content, "GettingAccessHealthAspect"),
250-
subsections: _extractPartsForAspect(content, "GettingAccessHealthAspect"),
251-
};
251+
const howToGetVaccine: VaccinePageSection | undefined = VaccineInfo[vaccineType]
252+
.removeHowToGetExpanderFromMoreInformationSection
253+
? undefined
254+
: {
255+
headline: _extractHeadlineForAspect(content, "GettingAccessHealthAspect"),
256+
subsections: _extractPartsForAspect(content, "GettingAccessHealthAspect"),
257+
};
252258

253259
const vaccineSideEffects: VaccinePageSection = {
254260
headline: _extractHeadlineForAspect(content, "SideEffectsHealthAspect"),

src/services/content-api/parsers/content-styling-service.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe("ContentStylingService", () => {
323323
expect(styledVaccineContent.overview).toEqual(mockContent.overview);
324324
expect(styledVaccineContent.whatVaccineIsFor?.heading).toEqual(mockWhatSection.headline);
325325
expect(styledVaccineContent.whoVaccineIsFor.heading).toEqual(mockWhoSection.headline);
326-
expect(styledVaccineContent.howToGetVaccine.heading).toEqual(mockHowSection.headline);
326+
expect(styledVaccineContent.howToGetVaccine?.heading).toEqual(mockHowSection.headline);
327327
expect(styledVaccineContent.vaccineSideEffects.heading).toEqual(mockSideEffectsSection.headline);
328328
expect(styledVaccineContent.callout?.heading).toEqual(mockCallout.heading);
329329
expect(styledVaccineContent.recommendation?.heading).toEqual(mockRecommendation.heading);
@@ -332,7 +332,7 @@ describe("ContentStylingService", () => {
332332
const expectedRsvPregnancyHowToGetSection = `<div><div><p>para3</p><p>para4</p></div></div>`;
333333
const expectedGenericVaccineHowToGetSection =
334334
"<div class=\"zeroMarginBottom\"><h3>How To Get Headline</h3><p>para</p><h3>If you're aged 75 to 79</h3><p>para1</p><p>para2</p><h3>If you're pregnant</h3><p>para3</p><p>para4</p></div>";
335-
const { container } = render(styledVaccineContent.howToGetVaccine.component);
335+
const { container } = render(styledVaccineContent.howToGetVaccine?.component);
336336
if (vaccine === VaccineType.RSV) {
337337
expect(container).toContainHTML(expectedRsvHowToGetSection);
338338
} else if (vaccine === VaccineType.RSV_PREGNANCY) {
@@ -343,7 +343,7 @@ describe("ContentStylingService", () => {
343343

344344
expect(isValidElement(styledVaccineContent.whatVaccineIsFor?.component)).toBe(true);
345345
expect(isValidElement(styledVaccineContent.whoVaccineIsFor.component)).toBe(true);
346-
expect(isValidElement(styledVaccineContent.howToGetVaccine.component)).toBe(true);
346+
expect(isValidElement(styledVaccineContent.howToGetVaccine?.component)).toBe(true);
347347
expect(isValidElement(styledVaccineContent.vaccineSideEffects.component)).toBe(true);
348348
expect(styledVaccineContent.webpageLink).toEqual(new URL("https://test.example.com/"));
349349
});
@@ -380,7 +380,7 @@ describe("ContentStylingService", () => {
380380
expect(styledVaccineContent.overview).toEqual({ content: "This is an overview", containsHtml: false });
381381
expect(styledVaccineContent.whatVaccineIsFor).toBeUndefined();
382382
expect(isValidElement(styledVaccineContent.whoVaccineIsFor.component)).toBe(true);
383-
expect(isValidElement(styledVaccineContent.howToGetVaccine.component)).toBe(true);
383+
expect(isValidElement(styledVaccineContent.howToGetVaccine?.component)).toBe(true);
384384
expect(isValidElement(styledVaccineContent.vaccineSideEffects.component)).toBe(true);
385385
expect(styledVaccineContent.webpageLink).toEqual(new URL("https://test.example.com/"));
386386
});

src/services/content-api/parsers/content-styling-service.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ const getStyledContentForVaccine = async (
227227
whatVaccineIsFor = styleSection(filteredContent.whatVaccineIsFor);
228228
}
229229
const whoVaccineIsFor: StyledPageSection = styleSection(filteredContent.whoVaccineIsFor);
230-
const howToGetVaccine: StyledPageSection = styleHowToGetSection(vaccine, filteredContent.howToGetVaccine, fragile);
230+
const howToGetVaccine: StyledPageSection | undefined = filteredContent.howToGetVaccine
231+
? styleHowToGetSection(vaccine, filteredContent.howToGetVaccine, fragile)
232+
: undefined;
231233
const vaccineSideEffects: StyledPageSection = styleSection(filteredContent.vaccineSideEffects);
232234
const webpageLink: URL = filteredContent.webpageLink;
233235

src/services/content-api/parsers/custom/covid-19.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VaccineType } from "@src/models/vaccine";
12
import { buildFilteredContentForCovid19Vaccine } from "@src/services/content-api/parsers/custom/covid-19";
23
import { ActionDisplayType, ButtonUrl, Content, Label } from "@src/services/eligibility-api/types";
34
import { buildNbsUrl } from "@src/services/nbs/nbs-service";
@@ -44,6 +45,7 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
4445

4546
const pageCopyForCovid19Vaccine = await buildFilteredContentForCovid19Vaccine(
4647
JSON.stringify(genericVaccineContentAPIResponse),
48+
VaccineType.COVID_19,
4749
);
4850

4951
expect(pageCopyForCovid19Vaccine.overview).toBeDefined();
@@ -74,7 +76,10 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
7476
};
7577

7678
// When
77-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
79+
const pageCopy = await buildFilteredContentForCovid19Vaccine(
80+
JSON.stringify(genericVaccineContentAPIResponse),
81+
VaccineType.COVID_19,
82+
);
7883

7984
// Then
8085
expect(pageCopy).toEqual(expect.objectContaining(expected));
@@ -113,7 +118,10 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
113118
};
114119

115120
// When
116-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
121+
const pageCopy = await buildFilteredContentForCovid19Vaccine(
122+
JSON.stringify(genericVaccineContentAPIResponse),
123+
VaccineType.COVID_19,
124+
);
117125

118126
// Then
119127
expect(pageCopy).toEqual(expect.objectContaining(expected));
@@ -130,7 +138,10 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
130138
};
131139
(headers as jest.Mock).mockResolvedValue(mockHeaders);
132140

133-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
141+
const pageCopy = await buildFilteredContentForCovid19Vaccine(
142+
JSON.stringify(genericVaccineContentAPIResponse),
143+
VaccineType.COVID_19,
144+
);
134145

135146
expect(pageCopy.callout).not.toBeUndefined();
136147
expect(pageCopy.actions).toHaveLength(0);
@@ -145,7 +156,10 @@ describe("buildFilteredContentForCovid19Vaccine", () => {
145156
};
146157
(headers as jest.Mock).mockResolvedValue(mockHeaders);
147158

148-
const pageCopy = await buildFilteredContentForCovid19Vaccine(JSON.stringify(genericVaccineContentAPIResponse));
159+
const pageCopy = await buildFilteredContentForCovid19Vaccine(
160+
JSON.stringify(genericVaccineContentAPIResponse),
161+
VaccineType.COVID_19,
162+
);
149163

150164
expect(pageCopy.callout).toBeUndefined();
151165
expect(pageCopy.actions).not.toHaveLength(0);

0 commit comments

Comments
 (0)