Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/stage-1-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
npm ci --strict-peer-deps
- name: "Check types with tsc"
run: |
tsc --noEmit
npx tsc --noEmit
- name: "Run linting check"
run: |
make test-lint
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ terraform 1.11.2
pre-commit 3.6.0
vale 3.6.0
nodejs 22.13.1
gitleaks 8.30.1

# ==============================================================================
# The section below is reserved for Docker image versions.
Expand Down
4 changes: 2 additions & 2 deletions e2e/elid-copy-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const elidCopyThatDiffersByEnvironment: Record<string, UserCopy> = {
},
["integration"]: {
user15: {
bulletPoint2: "did not turn 80 after 1 September 2024",
bulletPoint2: "do not live in a care home for older adults",
infoTextHeading: "If you think this is incorrect",
infoTextParagraph: "Speak to your healthcare professional if you think you should be offered this vaccine.",
},
user01: {
bulletPoint1: "are aged between 75 and 79",
bulletPoint1: "are aged 75 or over",
},
user13: {
cardParagraphTextv1: "We believe you had the RSV vaccination on 3 April 2025.",
Expand Down
2 changes: 1 addition & 1 deletion e2e/general/eligibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test.describe("Eligibility", () => {
level: 2,
name: "We do not believe you can have it",
});
const bulletPoint1: Locator = eligibility.getByText("are not aged 75 to 79", { exact: true }).first();
const bulletPoint1: Locator = eligibility.getByText("are not aged 75 or over", { exact: true }).first();
const bulletPoint2: Locator = eligibility
.getByText(elidCopyForEnvironment.user15.bulletPoint2, { exact: true })
.first();
Expand Down
2 changes: 1 addition & 1 deletion scripts/config/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
hooks:
- id: check-types
name: Check types with tsc
entry: tsc --noEmit
entry: npx tsc --noEmit
language: system
pass_filenames: false
- id: run-prettier
Expand Down
29 changes: 3 additions & 26 deletions src/app/_components/eligibility/RSVEligibilityFallback.test.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { RSVEligibilityFallback } from "@src/app/_components/eligibility/RSVEligibilityFallback";
import { PharmacyBookingInfo } from "@src/app/_components/nbs/PharmacyBookingInfo";
import { VaccineTypes } from "@src/models/vaccine";
import { render, screen, within } from "@testing-library/react";

jest.mock("@src/app/_components/nbs/PharmacyBookingInfo", () => ({
PharmacyBookingInfo: jest
.fn()
.mockImplementation(() => <p data-testid={"pharmacy-booking-info"}>Pharmacy booking test</p>),
}));

describe("RSVEligibilityFallback", () => {
const vaccineType = VaccineTypes.RSV;
const howToGetVaccineFallback = <div>How Section styled component</div>;

it("should display fallback care card", async () => {
await render(
<RSVEligibilityFallback howToGetVaccineFallback={howToGetVaccineFallback} vaccineType={vaccineType} />,
);
render(<RSVEligibilityFallback howToGetVaccineFallback={howToGetVaccineFallback} vaccineType={vaccineType} />);

const fallbackHeading: HTMLElement = screen.getByText("The RSV vaccine is recommended if you:");
const fallbackBulletPoint1: HTMLElement = screen.getByText("are aged 75 or over");
Expand All @@ -27,27 +18,13 @@ describe("RSVEligibilityFallback", () => {
expect(fallbackBulletPoint2).toBeVisible();
});

it("should include Pharmacy booking info for specified vaccine", () => {
render(<RSVEligibilityFallback howToGetVaccineFallback={howToGetVaccineFallback} vaccineType={vaccineType} />);

const pharmacyBookingInfo: HTMLElement = screen.getByTestId("pharmacy-booking-info");
expect(pharmacyBookingInfo).toBeVisible();

expect(PharmacyBookingInfo).toHaveBeenCalledWith(
{
vaccineType: vaccineType,
},
undefined,
);
});

it("should display 'If this applies' paragraph with provided how-to-get content", async () => {
it("should display provided how-to-get content", async () => {
render(<RSVEligibilityFallback howToGetVaccineFallback={howToGetVaccineFallback} vaccineType={vaccineType} />);

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

const fallbackHeading: HTMLElement = within(fallback).getByRole("heading", {
name: "If this applies to you",
name: "",
level: 3,
});
const howToGetContent: HTMLElement = within(fallback).getByText("How Section styled component");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { PharmacyBookingInfo } from "@src/app/_components/nbs/PharmacyBookingInfo";
import Expander from "@src/app/_components/nhs-frontend/Expander";
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
import styles from "@src/app/_components/vaccine/styles.module.css";
import { HEADINGS } from "@src/app/constants";
import { VaccineTypes } from "@src/models/vaccine";
import React, { JSX } from "react";

Expand All @@ -23,8 +21,7 @@ const RSVEligibilityFallback = (props: {
</div>
}
/>
<Expander title={HEADINGS.IF_THIS_APPLIES} component={props.howToGetVaccineFallback} notExpandable={true} />
<PharmacyBookingInfo vaccineType={props.vaccineType} />
<Expander title={""} component={props.howToGetVaccineFallback} notExpandable={true} />
<hr />
</div>
);
Expand Down
1 change: 0 additions & 1 deletion src/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export const HEADINGS = {
WHAT_VACCINE_IS_FOR: "What this vaccine is for",
WHO_SHOULD_HAVE_VACCINE: "Who should have this vaccine",
HOW_TO_GET_VACCINE: "How to get the vaccine",
IF_THIS_APPLIES: "If this applies to you",
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const mockNBSBookingActionHTML = "NBS Booking Link Test";
jest.mock("@src/app/_components/nbs/NBSBookingAction", () => ({
NBSBookingAction: () => mockNBSBookingActionHTML,
}));
jest.mock("@src/app/_components/nbs/PharmacyBookingInfo", () => ({
PharmacyBookingInfo: () => <div>Pharmacy Booking Info</div>,
}));
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));

describe("ContentStylingService", () => {
Expand All @@ -32,7 +35,7 @@ describe("ContentStylingService", () => {

const mockRsvMarkdownSubsection: VaccinePageSubsection = {
type: "simpleElement",
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>",
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>",
name: "markdown",
headline: "Headline",
};
Expand Down Expand Up @@ -209,8 +212,9 @@ describe("ContentStylingService", () => {
expect(styledVaccineContent.whoVaccineIsFor.heading).toEqual("Who is this Vaccine For");
expect(styledVaccineContent.howToGetVaccine.heading).toEqual("How to get this Vaccine");

const expectedRsvSection = "<div><p>para1</p><p>para2</p></div>";
const expectedRsvPregnancySection = `<div><div><p>para3</p><p>para4</p></div></div>`;
const expectedRsvSection =
"<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>";
const expectedRsvPregnancySection = `<div><div><p>para5</p><p>para6</p></div></div>`;
const { container } = render(styledVaccineContent.howToGetVaccine.component);
if (vaccine === VaccineTypes.RSV) {
expect(container).toContainHTML(expectedRsvSection);
Expand Down
21 changes: 7 additions & 14 deletions src/services/content-api/parsers/custom/both.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { render } from "@testing-library/react";
import React from "react";

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

const mockRsvForOlderAdultsSubsection: VaccinePageSubsection = {
type: "simpleElement",
text: "<h3>If you're aged 75 to 79</h3><p>Paragraph 1</p><p>Paragraph 2</p>",
headline: "",
name: "",
};

const mockRsvForOlderAdultsNewerSubsection: VaccinePageSubsection = {
type: "simpleElement",
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>",
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>",
headline: "",
name: "",
};
Expand Down Expand Up @@ -63,12 +59,9 @@ describe("styleHowToGetSubsection for rsv in older adults", () => {

it("renders HTML if subsection contains rsv for older adults", () => {
const { container } = render(<>{styleHowToGetSubsectionForRsv(mockRsvForOlderAdultsSubsection, 0, false)}</>);
expect(container.innerHTML).toBe("<div><p>Paragraph 1</p><p>Paragraph 2</p></div>");
});

it("renders HTML if newer subsection contains rsv for older adults", () => {
const { container } = render(<>{styleHowToGetSubsectionForRsv(mockRsvForOlderAdultsNewerSubsection, 0, false)}</>);
expect(container.innerHTML).toBe("<div><p>Paragraph 1</p><p>Paragraph 2</p></div>");
expect(container.innerHTML).toBe(
'<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>',
);
});
});

Expand Down
37 changes: 23 additions & 14 deletions src/services/content-api/parsers/custom/rsv.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PharmacyBookingInfo } from "@src/app/_components/nbs/PharmacyBookingInfo";
import { VaccineTypes } from "@src/models/vaccine";
import { ContentParsingError } from "@src/services/content-api/parsers/custom/exceptions";
import type { StyledPageSection, VaccinePageSection, VaccinePageSubsection } from "@src/services/content-api/types";
import { logger } from "@src/utils/logger";
Expand All @@ -7,9 +9,9 @@ import React from "react";

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

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

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

const paragraphsMatches = olderAdultsMatches[1].match(paragraphsRegExp);
if (!paragraphsMatches) {
const olderAdultsInCareHomeMatches = olderAdultsInCareHomeRegExp.exec(subsection.text);
if (!olderAdultsInCareHomeMatches) {
log.warn(
{ context: { text: olderAdultsMatches[1] } },
"HowToGetSubsection paragraph not found - has the content changed?",
{ context: { text: subsection.text } },
"HowToGetSubsection care home header not found - has the content changed?",
);
if (fragile) {
throw new ContentParsingError("HowToGetSubsection paragraph not found - has the content changed?");
throw new ContentParsingError("HowToGetSubsection care home header not found - has the content changed?");
} else {
return <></>;
}
}

return (
<div
key={index}
dangerouslySetInnerHTML={{
__html: sanitiseHtml(paragraphsMatches.join("")),
}}
/>
<div key={index}>
<div
dangerouslySetInnerHTML={{
__html: sanitiseHtml(olderAdultsMatches[0]),
}}
/>
<PharmacyBookingInfo vaccineType={VaccineTypes.RSV} />
<div
dangerouslySetInnerHTML={{
__html: sanitiseHtml(olderAdultsInCareHomeMatches[0]),
}}
/>
</div>
);
};

Expand Down
2 changes: 1 addition & 1 deletion wiremock/__files/rsv-vaccine.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
{
"position": 0,
"identifier": "1",
"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>",
"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>",
"@type": "WebPageElement",
"name": "markdown",
"headline": ""
Expand Down
Loading