Skip to content

Commit 2ed2470

Browse files
AJ/KB Add support for care headers in RSV vaccine
1 parent 757fbdf commit 2ed2470

File tree

8 files changed

+42
-65
lines changed

8 files changed

+42
-65
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ terraform 1.14.1
44
pre-commit 4.5.0
55
vale 3.13.0
66
nodejs 22.13.1
7+
gitleaks 8.30.1
78

89
# ==============================================================================
910
# The section below is reserved for Docker image versions.
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { RSVEligibilityFallback } from "@src/app/_components/eligibility/RSVEligibilityFallback";
2-
import { PharmacyBookingInfo } from "@src/app/_components/nbs/PharmacyBookingInfo";
32
import { VaccineType } from "@src/models/vaccine";
43
import { render, screen, within } from "@testing-library/react";
54

6-
jest.mock("@src/app/_components/nbs/PharmacyBookingInfo", () => ({
7-
PharmacyBookingInfo: jest
8-
.fn()
9-
.mockImplementation(() => <p data-testid={"pharmacy-booking-info"}>Pharmacy booking test</p>),
10-
}));
11-
125
describe("RSVEligibilityFallback", () => {
136
const vaccineType = VaccineType.RSV;
147
const howToGetVaccineFallback = <div>How Section styled component</div>;
@@ -25,32 +18,13 @@ describe("RSVEligibilityFallback", () => {
2518
expect(fallbackBulletPoint2).toBeVisible();
2619
});
2720

28-
it("should include Pharmacy booking info for specified vaccine", () => {
29-
render(<RSVEligibilityFallback howToGetVaccineFallback={howToGetVaccineFallback} vaccineType={vaccineType} />);
30-
31-
const pharmacyBookingInfo: HTMLElement = screen.getByTestId("pharmacy-booking-info");
32-
expect(pharmacyBookingInfo).toBeVisible();
33-
34-
expect(PharmacyBookingInfo).toHaveBeenCalledWith(
35-
{
36-
vaccineType: vaccineType,
37-
},
38-
undefined,
39-
);
40-
});
41-
42-
it("should display 'If this applies' paragraph with provided how-to-get content", async () => {
21+
it("should display provided how-to-get content", async () => {
4322
render(<RSVEligibilityFallback howToGetVaccineFallback={howToGetVaccineFallback} vaccineType={vaccineType} />);
4423

4524
const fallback = screen.getByTestId("elid-fallback");
4625

47-
const fallbackHeading: HTMLElement = within(fallback).getByRole("heading", {
48-
name: "If this applies to you",
49-
level: 3,
50-
});
5126
const howToGetContent: HTMLElement = within(fallback).getByText("How Section styled component");
5227

53-
expect(fallbackHeading).toBeVisible();
5428
expect(howToGetContent).toBeVisible();
5529
});
5630
});

src/app/_components/eligibility/RSVEligibilityFallback.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { PharmacyBookingInfo } from "@src/app/_components/nbs/PharmacyBookingInfo";
21
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
3-
import { HEADINGS } from "@src/app/constants";
42
import { VaccineType } from "@src/models/vaccine";
53
import React, { JSX } from "react";
64

@@ -21,9 +19,7 @@ const RSVEligibilityFallback = (props: {
2119
</>
2220
}
2321
/>
24-
<h3>{HEADINGS.IF_THIS_APPLIES}</h3>
2522
{props.howToGetVaccineFallback}
26-
<PharmacyBookingInfo vaccineType={props.vaccineType} />
2723
</div>
2824
);
2925
};

src/app/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ export const HEADINGS = {
1111
HOW_TO_GET_VACCINE: "How to get the vaccine",
1212
EXTRA_DOSES_SCHEDULE: "Extra doses of the vaccine",
1313
VACCINE_SIDE_EFFECTS: "Side effects of the vaccine",
14-
IF_THIS_APPLIES: "If this applies to you",
1514
};

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jest.mock("@project/src/app/_components/markdown/MarkdownWithStyling", () => ({
2727
MarkdownWithStyling: jest.fn(),
2828
}));
2929

30+
jest.mock("@src/app/_components/nbs/PharmacyBookingInfo", () => ({
31+
PharmacyBookingInfo: () => <div>Pharmacy Booking Info</div>,
32+
}));
33+
3034
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
3135
jest.mock("cheerio", () => ({
3236
load: jest.fn(() => {
@@ -69,7 +73,7 @@ describe("ContentStylingService", () => {
6973

7074
const mockHowToGetMarkdownSubsection: VaccinePageSubsection = {
7175
type: "simpleElement",
72-
text: "<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>",
76+
text: "<p>para</p><h3>If you're aged 75 or over</h3><p>para1</p><p>para2</p><h3>If you live in a care home for older adults</h3><p>para3</p><p>para4</p><h3>If you're pregnant</h3><p>para5</p><p>para6</p>",
7377
name: "markdown",
7478
headline: "How To Get Headline",
7579
};
@@ -347,10 +351,11 @@ describe("ContentStylingService", () => {
347351
expect(styledVaccineContent.recommendation?.heading).toEqual(mockRecommendation.heading);
348352
expect(styledVaccineContent.additionalInformation?.heading).toEqual(mockAdditionalInformationSection.headline);
349353

350-
const expectedRsvHowToGetSection = "<div><p>para1</p><p>para2</p></div>";
351-
const expectedRsvPregnancyHowToGetSection = `<div><div><p>para3</p><p>para4</p></div></div>`;
354+
const expectedRsvHowToGetSection =
355+
"<div><div><h3>If you're aged 75 or over</h3><p>para1</p><p>para2</p></div><div>Pharmacy Booking Info</div><div><h3>If you live in a care home for older adults</h3><p>para3</p><p>para4</p></div></div>";
356+
const expectedRsvPregnancyHowToGetSection = `<div><div><p>para5</p><p>para6</p></div></div>`;
352357
const expectedGenericVaccineHowToGetSection =
353-
"<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>";
358+
"<div class=\"zeroMarginBottom\"><h3>How To Get Headline</h3><p>para</p><h3>If you're aged 75 or over</h3><p>para1</p><p>para2</p><h3>If you live in a care home for older adults</h3><p>para3</p><p>para4</p><h3>If you're pregnant</h3><p>para5</p><p>para6</p></div>";
354359
const { container } = render(styledVaccineContent.howToGetVaccine.component);
355360
if (vaccine === VaccineType.RSV) {
356361
expect(container).toContainHTML(expectedRsvHowToGetSection);

src/services/content-api/parsers/custom/both.test.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { render } from "@testing-library/react";
66
import React from "react";
77

88
const mockNBSBookingActionHTML = "NBS Booking Link Test";
9+
jest.mock("@src/app/_components/nbs/PharmacyBookingInfo", () => ({
10+
PharmacyBookingInfo: () => <p data-testid="pharmacy-booking-info">test</p>,
11+
}));
912
jest.mock("@src/app/_components/nbs/NBSBookingAction", () => ({
1013
NBSBookingAction: () => mockNBSBookingActionHTML,
1114
}));
@@ -26,14 +29,7 @@ const mockRsvInPregnancySubsection: VaccinePageSubsection = {
2629

2730
const mockRsvForOlderAdultsSubsection: VaccinePageSubsection = {
2831
type: "simpleElement",
29-
text: "<h3>If you're aged 75 to 79</h3><p>Paragraph 1</p><p>Paragraph 2</p>",
30-
headline: "",
31-
name: "",
32-
};
33-
34-
const mockRsvForOlderAdultsNewerSubsection: VaccinePageSubsection = {
35-
type: "simpleElement",
36-
text: "<h3>If you're aged 75 to 79 (or turned 80 after 1 September 2024)</h3><p>Paragraph 1</p><p>Paragraph 2</p>",
32+
text: "<h3>If you're aged 75 or over</h3><p>Paragraph 1</p><p>Paragraph 2</p><h3>If you live in a care home for older adults</h3><p>Paragraph 3</p><p>Paragraph 4</p>",
3733
headline: "",
3834
name: "",
3935
};
@@ -63,12 +59,9 @@ describe("styleHowToGetSubsection for rsv in older adults", () => {
6359

6460
it("renders HTML if subsection contains rsv for older adults", () => {
6561
const { container } = render(<>{styleHowToGetSubsectionForRsv(mockRsvForOlderAdultsSubsection, 0, false)}</>);
66-
expect(container.innerHTML).toBe("<div><p>Paragraph 1</p><p>Paragraph 2</p></div>");
67-
});
68-
69-
it("renders HTML if newer subsection contains rsv for older adults", () => {
70-
const { container } = render(<>{styleHowToGetSubsectionForRsv(mockRsvForOlderAdultsNewerSubsection, 0, false)}</>);
71-
expect(container.innerHTML).toBe("<div><p>Paragraph 1</p><p>Paragraph 2</p></div>");
62+
expect(container.innerHTML).toBe(
63+
'<div><div><h3>If you\'re aged 75 or over</h3><p>Paragraph 1</p><p>Paragraph 2</p></div><p data-testid="pharmacy-booking-info">test</p><div><h3>If you live in a care home for older adults</h3><p>Paragraph 3</p><p>Paragraph 4</p></div></div>',
64+
);
7265
});
7366
});
7467

src/services/content-api/parsers/custom/rsv.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PharmacyBookingInfo } from "@src/app/_components/nbs/PharmacyBookingInfo";
2+
import { VaccineType } from "@src/models/vaccine";
13
import { ContentParsingError } from "@src/services/content-api/parsers/custom/exceptions";
24
import type { StyledPageSection, VaccinePageSection, VaccinePageSubsection } from "@src/services/content-api/types";
35
import { logger } from "@src/utils/logger";
@@ -7,9 +9,9 @@ import React from "react";
79

810
const log: Logger = logger.child({ module: "services-content-api-parsers-custom-rsv" });
911

10-
const olderAdultsRegExp: RegExp =
11-
/<h3>If you're aged \d+ to \d+(?: \(or turned \d+ after .*\))?<\/h3>((?:\s*<p>.*?<\/p>)+)/i;
12-
const paragraphsRegExp: RegExp = /<p>.*?<\/p>/g;
12+
const olderAdultsRegExp: RegExp = /<h3>If you're aged \d+ or over<\/h3>((?:\s*<p>.*?<\/p>)+)/i;
13+
const olderAdultsInCareHomeRegExp: RegExp =
14+
/<h3>If you live in a care home for older adults<\/h3>((?:\s*<p>.*?<\/p>)+)/i;
1315

1416
export const styleHowToGetSubsection = (subsection: VaccinePageSubsection, index: number, fragile: boolean) => {
1517
if (subsection.type !== "simpleElement") {
@@ -31,26 +33,33 @@ export const styleHowToGetSubsection = (subsection: VaccinePageSubsection, index
3133
}
3234
}
3335

34-
const paragraphsMatches = olderAdultsMatches[1].match(paragraphsRegExp);
35-
if (!paragraphsMatches) {
36+
const olderAdultsInCareHomeMatches = olderAdultsInCareHomeRegExp.exec(subsection.text);
37+
if (!olderAdultsInCareHomeMatches) {
3638
log.warn(
37-
{ context: { text: olderAdultsMatches[1] } },
38-
"HowToGetSubsection paragraph not found - has the content changed?",
39+
{ context: { text: subsection.text } },
40+
"HowToGetSubsection care home header not found - has the content changed?",
3941
);
4042
if (fragile) {
41-
throw new ContentParsingError("HowToGetSubsection paragraph not found - has the content changed?");
43+
throw new ContentParsingError("HowToGetSubsection care home header not found - has the content changed?");
4244
} else {
4345
return <></>;
4446
}
4547
}
4648

4749
return (
48-
<div
49-
key={index}
50-
dangerouslySetInnerHTML={{
51-
__html: sanitiseHtml(paragraphsMatches.join("")),
52-
}}
53-
/>
50+
<div key={index}>
51+
<div
52+
dangerouslySetInnerHTML={{
53+
__html: sanitiseHtml(olderAdultsMatches[0]),
54+
}}
55+
/>
56+
<PharmacyBookingInfo vaccineType={VaccineType.RSV} />
57+
<div
58+
dangerouslySetInnerHTML={{
59+
__html: sanitiseHtml(olderAdultsInCareHomeMatches[0]),
60+
}}
61+
/>
62+
</div>
5463
);
5564
};
5665

wiremock/__files/rsv-vaccine.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
{
282282
"position": 0,
283283
"identifier": "1",
284-
"text": "<p>There are different ways to get the RSV vaccine.</p><h3>If you're pregnant</h3><p>You should be offered the RSV vaccine around the time of your 28-week antenatal appointment.</p><p>Getting vaccinated as soon as possible from 28 weeks will provide the best protection for your baby. But the vaccine can be given later if needed, including up until you go into labour.</p><p>Speak to your maternity service or GP surgery if you're 28 weeks pregnant or more and have not been offered the vaccine.</p><h3>If you're aged 75 to 79 (or turned 80 after 1 September 2024)</h3><p>If you're aged 75 to 79 (or turned 80 after 1 September 2024) contact your GP surgery to book your RSV vaccination.</p><p>Your GP surgery may contact you about getting the RSV vaccine. This may be by letter, text, phone call or email.</p><p>You do not need to wait to be contacted before booking your vaccination.</p>",
284+
"text": "<p>There are different ways to get the RSV vaccine.</p><h3>If you're pregnant</h3><p>You should be offered the RSV vaccine around the time of your 28-week antenatal appointment.</p><p>Getting vaccinated as soon as possible from 28 weeks will provide the best protection for your baby. But the vaccine can be given later if needed, including up until you go into labour.</p><p>Speak to your maternity service or GP surgery if you're 28 weeks pregnant or more and have not been offered the vaccine.</p><h3>If you're aged 75 or over</h3><p>Contact your GP surgery to book your RSV vaccination.</p><p>Your GP surgery may contact you about getting the RSV vaccine. This may be by letter, text, phone call or email.</p><p>You do not need to wait to be contacted before booking your vaccination.</p><h3>If you live in a care home for older adults</h3><p>Speak to a member of staff at your care home or your GP surgery about how to get the RSV vaccine.</p><p>Your GP surgery may contact you about getting the RSV vaccine. This may be by letter, text, phone call or email.</p>",
285285
"@type": "WebPageElement",
286286
"name": "markdown",
287287
"headline": ""

0 commit comments

Comments
 (0)