Skip to content

Commit c568413

Browse files
VIA-304 SB Whooping Cough overview contains HTML, so renders as a div with dangerouslySetInnerHTML. Other vaccines render as a single paragraph as hitherto.
1 parent 3c03f5e commit c568413

File tree

13 files changed

+70
-20
lines changed

13 files changed

+70
-20
lines changed

src/_lambda/content-cache-hydrator/content-change-detector.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { vitaContentChangedSinceLastApproved } from "@src/_lambda/content-cache-
22
import { VaccinePageContent } from "@src/services/content-api/types";
33

44
const mockPreviousApprovedVaccineContent: VaccinePageContent = {
5-
overview: "This is an overview",
5+
overview: { content: "This is an overview", containsHtml: false },
66
whatVaccineIsFor: {
77
headline: "What Vaccine Is For",
88
subsections: [
@@ -58,7 +58,10 @@ describe("vitaContentChangedSinceLastApproved", () => {
5858
});
5959

6060
it("should return true if content changed since last approved", async () => {
61-
const mockChangedContent = { ...mockPreviousApprovedVaccineContent, overview: "changed-overview" };
61+
const mockChangedContent = {
62+
...mockPreviousApprovedVaccineContent,
63+
overview: { content: "changed-overview", containsHtml: false },
64+
};
6265

6366
expect(vitaContentChangedSinceLastApproved(mockChangedContent, mockPreviousApprovedVaccineContent)).toBeTruthy();
6467
});

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import { Overview } from "@src/app/_components/content/Overview";
22
import { VaccineType } from "@src/models/vaccine";
3-
import { mockStyledContent } from "@test-data/content-api/data";
3+
import { mockStyledContent, mockStyledContentWithHtmlOverview } from "@test-data/content-api/data";
44
import { render, screen } from "@testing-library/react";
55
import React from "react";
66

77
describe("Overview component", () => {
8-
it("renders correctly", () => {
8+
it("renders overview without HTML correctly", () => {
99
const vaccineType = VaccineType.SHINGLES;
1010

1111
render(<Overview styledVaccineContent={mockStyledContent} vaccineType={vaccineType} />);
1212

1313
const overviewText: HTMLElement = screen.getByTestId("overview-text");
1414

1515
expect(overviewText).toBeInTheDocument();
16+
});
17+
18+
it("renders overview with HTML correctly", () => {
19+
const vaccineType = VaccineType.SHINGLES;
20+
21+
render(<Overview styledVaccineContent={mockStyledContentWithHtmlOverview} vaccineType={vaccineType} />);
22+
23+
const overviewText: HTMLElement = screen.getByTestId("overview-text");
24+
25+
expect(overviewText).toBeInTheDocument();
1626

1727
const boldElement = screen.getByText("text");
1828

src/app/_components/content/Overview.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import { StyledVaccineContent } from "@src/services/content-api/types";
33
import { JSX } from "react";
44

55
const Overview = (props: { styledVaccineContent: StyledVaccineContent; vaccineType: VaccineType }): JSX.Element => {
6-
return (
7-
<p data-testid="overview-text" dangerouslySetInnerHTML={{ __html: props.styledVaccineContent?.overview || "" }} />
6+
const element = props.styledVaccineContent?.overview.containsHtml ? (
7+
<div
8+
data-testid="overview-text"
9+
dangerouslySetInnerHTML={{ __html: props.styledVaccineContent?.overview.content || "" }}
10+
/>
11+
) : (
12+
<p data-testid="overview-text">{props.styledVaccineContent?.overview.content}</p>
813
);
14+
return element;
915
};
1016
export { Overview };

src/services/content-api/content-api.integration.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ describe("Content API Read Integration Test ", () => {
3030

3131
expect(styledVaccineContent).not.toBeNull();
3232
expect(contentError).toBeUndefined();
33-
expect(styledVaccineContent?.overview).toEqual(mockRsvVaccineJson.mainEntityOfPage[0].text);
33+
expect(styledVaccineContent?.overview).toEqual({
34+
content: mockRsvVaccineJson.mainEntityOfPage[0].text,
35+
containsHtml: false,
36+
});
3437
expect(styledVaccineContent?.webpageLink.href).toEqual(mockRsvVaccineJson.webpage);
3538
});
3639

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ describe("getContentForVaccine()", () => {
2626
const { styledVaccineContent, contentError }: GetContentForVaccineResponse = await getContentForVaccine(vaccine);
2727

2828
expect(styledVaccineContent).toBeDefined();
29-
expect(styledVaccineContent?.overview).toEqual(mockRsvVaccineJson.mainEntityOfPage[0].text);
29+
expect(styledVaccineContent?.overview).toEqual({
30+
content: mockRsvVaccineJson.mainEntityOfPage[0].text,
31+
containsHtml: false,
32+
});
3033
expect(styledVaccineContent?.whatVaccineIsFor?.heading).toEqual(mockRsvVaccineJson.mainEntityOfPage[1].headline);
3134
expect(styledVaccineContent?.webpageLink.href).toEqual(mockRsvVaccineJson.webpage);
3235
expect(contentError).toBeUndefined();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ describe("Content Filter", () => {
527527
describe("getFilteredContentForVaccine", () => {
528528
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
529529
const expectedOverview = {
530-
overview: "Generic Vaccine Lead Paragraph (overview)",
530+
overview: { content: "Generic Vaccine Lead Paragraph (overview)", containsHtml: false },
531531
};
532532

533533
const pageCopyForRsv = getFilteredContentForVaccine(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ContentApiVaccineResponse,
55
HasPartSubsection,
66
MainEntityOfPage,
7+
Overview,
78
VaccinePageContent,
89
VaccinePageSection,
910
VaccinePageSubsection,
@@ -180,7 +181,7 @@ const getFilteredContentForVaccine = (vaccineType: VaccineType, apiContent: stri
180181
const getFilteredContentForStandardVaccine = (apiContent: string): VaccinePageContent => {
181182
const content: ContentApiVaccineResponse = JSON.parse(apiContent);
182183

183-
const overview: string = _extractDescriptionForVaccine(content, "lead paragraph");
184+
const overview: Overview = { content: _extractDescriptionForVaccine(content, "lead paragraph"), containsHtml: false };
184185

185186
let whatVaccineIsFor;
186187
if (_hasHealthAspect(content, "BenefitsHealthAspect")) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe("ContentStylingService", () => {
214214
subsections: [mockMarkdownSubsection, mockUrgentSubsection],
215215
};
216216
const mockContent: VaccinePageContent = {
217-
overview: "This is an overview",
217+
overview: { content: "This is an overview", containsHtml: false },
218218
whatVaccineIsFor: mockWhatSection,
219219
whoVaccineIsFor: mockWhoSection,
220220
howToGetVaccine: mockHowSection,
@@ -265,7 +265,7 @@ describe("ContentStylingService", () => {
265265
subsections: [mockMarkdownSubsection, mockNonUrgentSubsection],
266266
};
267267
const mockContent: VaccinePageContent = {
268-
overview: "This is an overview",
268+
overview: { content: "This is an overview", containsHtml: false },
269269
whoVaccineIsFor: mockWhoSection,
270270
howToGetVaccine: mockHowSection,
271271
vaccineSideEffects: mockSideEffectsSection,
@@ -279,7 +279,7 @@ describe("ContentStylingService", () => {
279279
);
280280

281281
expect(styledVaccineContent).not.toBeNull();
282-
expect(styledVaccineContent.overview).toEqual("This is an overview");
282+
expect(styledVaccineContent.overview).toEqual({ content: "This is an overview", containsHtml: false });
283283
expect(styledVaccineContent.whatVaccineIsFor).toBeUndefined();
284284
expect(isValidElement(styledVaccineContent.whoVaccineIsFor.component)).toBe(true);
285285
expect(isValidElement(styledVaccineContent.howToGetVaccine.component)).toBe(true);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { styleHowToGetSectionForRsv } from "@src/services/content-api/parsers/cu
55
import { styleHowToGetSectionForRsvPregnancy } from "@src/services/content-api/parsers/custom/rsv-pregnancy";
66
import type {
77
HeadingWithContent,
8+
Overview,
89
StyledPageSection,
910
StyledVaccineContent,
1011
VaccinePageContent,
@@ -142,7 +143,7 @@ const getStyledContentForVaccine = async (
142143
filteredContent: VaccinePageContent,
143144
fragile: boolean,
144145
): Promise<StyledVaccineContent> => {
145-
const overview: string = filteredContent.overview;
146+
const overview: Overview = filteredContent.overview;
146147
let whatVaccineIsFor;
147148
if (filteredContent.whatVaccineIsFor) {
148149
whatVaccineIsFor = styleSection(filteredContent.whatVaccineIsFor);

src/services/content-api/parsers/custom/whooping-cough.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const apiResponse = JSON.stringify({
2424

2525
describe("getFilteredContentForVaccine", () => {
2626
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
27-
const expected = { overview: "Whooping Cough Vaccine Lead Paragraph (overview)" };
27+
const expected = { overview: { content: "Whooping Cough Vaccine Lead Paragraph (overview)", containsHtml: true } };
2828

2929
const pageCopy = getFilteredContentForWhoopingCoughVaccine(apiResponse);
3030

0 commit comments

Comments
 (0)