Skip to content

Commit 985f645

Browse files
VIA-618 SB Final(?) changes to hard-coded content for Flu in pregnancy page.
This involved making overview optional, since this page doesn't have one.
1 parent ea61309 commit 985f645

File tree

7 files changed

+57
-26
lines changed

7 files changed

+57
-26
lines changed

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

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

@@ -30,4 +34,14 @@ describe("Overview component", () => {
3034
expect(boldElement).toBeInTheDocument();
3135
expect(boldElement.tagName).toBe("B");
3236
});
37+
38+
it("does not render missing overview", () => {
39+
const vaccineType = VaccineType.FLU_IN_PREGNANCY;
40+
41+
render(<Overview styledVaccineContent={mockStyledContentWithMissingOverview} vaccineType={vaccineType} />);
42+
43+
const overviewText: HTMLElement | null = screen.queryByTestId("overview-text");
44+
45+
expect(overviewText).not.toBeInTheDocument();
46+
});
3347
});

src/app/_components/content/Overview.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ 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-
const element = props.styledVaccineContent?.overview.containsHtml ? (
7-
<div
8-
data-testid="overview-text"
9-
dangerouslySetInnerHTML={{ __html: props.styledVaccineContent?.overview.content || "" }}
10-
/>
6+
const element = props.styledVaccineContent.overview ? (
7+
props.styledVaccineContent.overview.containsHtml ? (
8+
<div
9+
data-testid="overview-text"
10+
dangerouslySetInnerHTML={{ __html: props.styledVaccineContent.overview.content || "" }}
11+
/>
12+
) : (
13+
<p data-testid="overview-text">{props.styledVaccineContent.overview.content}</p>
14+
)
1115
) : (
12-
<p data-testid="overview-text">{props.styledVaccineContent?.overview.content}</p>
16+
<></>
1317
);
1418
return element;
1519
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const getStyledContentForVaccine = async (
175175
filteredContent: VaccinePageContent,
176176
fragile: boolean,
177177
): Promise<StyledVaccineContent> => {
178-
const overview: Overview = filteredContent.overview;
178+
const overview: Overview | undefined = filteredContent.overview;
179179
let whatVaccineIsFor;
180180
if (filteredContent.whatVaccineIsFor) {
181181
whatVaccineIsFor = styleSection(filteredContent.whatVaccineIsFor);

src/services/content-api/parsers/custom/flu-in-pregnancy.test.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ const apiResponse = JSON.stringify({
1313
});
1414

1515
describe("getFilteredContentForFluInPregnancyVaccine", () => {
16-
it("should return overview text from lead paragraph mainEntityOfPage object", async () => {
17-
const expected = {
18-
overview: { content: "Flu in Pregnancy Vaccine Lead Paragraph (overview)", containsHtml: true },
19-
};
20-
21-
const pageCopy = getFilteredContentForFluInPregnancyVaccine(apiResponse);
22-
23-
expect(pageCopy).toEqual(expect.objectContaining(expected));
24-
});
25-
2616
it("should return all parts for whatVaccineIsFor section", () => {
2717
const expected = {
2818
whatVaccineIsFor: {
@@ -126,8 +116,8 @@ describe("getFilteredContentForFluInPregnancyVaccine", () => {
126116
it("should return recommendation", () => {
127117
const expected = {
128118
recommendation: {
129-
heading: "The flu vaccine is recommended if you:",
130-
content: "* are pregnant\n* have not had the vaccine during this pregnancy",
119+
heading: "The flu vaccine is recommended:",
120+
content: "* if you are pregnant\n* whatever stage of pregnancy you're at\n\nIt's free on the NHS.",
131121
},
132122
};
133123

src/services/content-api/parsers/custom/flu-in-pregnancy.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const getFilteredContentForFluInPregnancyVaccine = (apiContent: string):
1414
.map((part) => part?.text)
1515
.filter((text): text is string => !!text);
1616

17-
const overview = { content: paragraphs[0], containsHtml: true };
1817
const whyOffered: VaccinePageSection = {
1918
headline: "Why pregnant women are offered the vaccine",
2019
subsections: [{ type: "simpleElement", headline: "", text: paragraphs[1], name: "markdown" }],
@@ -37,12 +36,14 @@ export const getFilteredContentForFluInPregnancyVaccine = (apiContent: string):
3736
content: "Flu vaccine bookings will reopen in autumn 2026",
3837
};
3938
const recommendation: HeadingWithContent = {
40-
heading: "The flu vaccine is recommended if you:",
41-
content: ["* are pregnant", "* have not had the vaccine during this pregnancy"].join("\n"),
39+
heading: "The flu vaccine is recommended:",
40+
content: ["* if you are pregnant", "* whatever stage of pregnancy you're at", "", "It's free on the NHS."].join(
41+
"\n",
42+
),
4243
};
4344

4445
return {
45-
overview,
46+
overview: undefined,
4647
whatVaccineIsFor: whyOffered,
4748
whoVaccineIsFor: isItSafe,
4849
howToGetVaccine,

src/services/content-api/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export type VaccinePageSection = {
103103
export type Overview = { content: string; containsHtml: boolean };
104104

105105
export type VaccinePageContent = {
106-
overview: Overview;
106+
overview?: Overview;
107107
whatVaccineIsFor?: VaccinePageSection;
108108
whoVaccineIsFor: VaccinePageSection;
109109
howToGetVaccine: VaccinePageSection;
@@ -127,7 +127,7 @@ export type HeadingWithContent = {
127127
};
128128

129129
export type StyledVaccineContent = {
130-
overview: Overview;
130+
overview?: Overview;
131131
whatVaccineIsFor?: StyledPageSection;
132132
whoVaccineIsFor: StyledPageSection;
133133
howToGetVaccine: StyledPageSection;

test-data/content-api/data.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,28 @@ export const mockStyledContent: StyledVaccineContent = {
595595
recommendation: { heading: "Recommendation Heading", component: <div>Recommendation component</div> },
596596
};
597597

598+
export const mockStyledContentWithMissingOverview: StyledVaccineContent = {
599+
whatVaccineIsFor: {
600+
heading: "what-heading",
601+
component: <p>What Section styled component</p>,
602+
},
603+
whoVaccineIsFor: {
604+
heading: "who-heading",
605+
component: <h2>Who Section styled component</h2>,
606+
},
607+
howToGetVaccine: {
608+
heading: "how-heading",
609+
component: <div>How Section styled component</div>,
610+
},
611+
vaccineSideEffects: {
612+
heading: "side-effects-heading",
613+
component: <div>Side effects section styled component</div>,
614+
},
615+
webpageLink: new URL("https://test.example.com/"),
616+
callout: { heading: "Callout Heading", content: "Callout content" },
617+
recommendation: { heading: "Recommendation Heading", component: <div>Recommendation component</div> },
618+
};
619+
598620
export const mockStyledContentWithHtmlOverview: StyledVaccineContent = {
599621
overview: { content: "Overview <b>text</b>", containsHtml: true },
600622
whatVaccineIsFor: {

0 commit comments

Comments
 (0)