Skip to content

Commit df93669

Browse files
VIA-618 SB Render markdown in Flu in pregnancy page.
1 parent 0198043 commit df93669

File tree

11 files changed

+93
-13
lines changed

11 files changed

+93
-13
lines changed

src/_lambda/content-cache-hydrator/handler.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jest.mock("@src/utils/requestContext", () => ({
3434
},
3535
}));
3636
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
37+
const mockMarkdownWithStylingHtml = "<ul><li>sausage</li><li>egg</li><li>chips</li></ul>";
38+
jest.mock("@project/src/app/_components/markdown/MarkdownWithStyling", () => ({
39+
MarkdownWithStyling: () => mockMarkdownWithStylingHtml,
40+
}));
3741

3842
const mockValidCacheReadResult: ReadCachedContentResult = { cacheStatus: "valid", cacheContent: "some-content" };
3943
const mockInvalidatedCacheReadResult: ReadCachedContentResult = { cacheStatus: "invalidated", cacheContent: "" };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Callout } from "@src/app/_components/content/Callout";
1+
import Callout from "@src/app/_components/content/Callout";
22
import { VaccineType } from "@src/models/vaccine";
33
import { mockStyledContent } from "@test-data/content-api/data";
44
import { render, screen } from "@testing-library/react";

src/app/_components/content/Callout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ const Callout = (props: { styledVaccineContent: StyledVaccineContent; vaccineTyp
1515
);
1616
return element;
1717
};
18-
export { Callout };
18+
export default Callout;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Recommendation from "@src/app/_components/content/Recommendation";
2+
import { mockStyledContent, mockStyledContentWithoutRecommendation } from "@test-data/content-api/data";
3+
import { render, screen } from "@testing-library/react";
4+
import React from "react";
5+
6+
describe("Recommendation component", () => {
7+
it("renders correctly", () => {
8+
render(<Recommendation styledVaccineContent={mockStyledContent} />);
9+
10+
const RecommendationText: HTMLElement = screen.getByTestId("recommendation");
11+
12+
expect(RecommendationText).toBeInTheDocument();
13+
});
14+
15+
it("does not render if no recommendation present", () => {
16+
render(<Recommendation styledVaccineContent={mockStyledContentWithoutRecommendation} />);
17+
18+
const RecommendationText: HTMLElement | null = screen.queryByTestId("Recommendation component");
19+
20+
expect(RecommendationText).not.toBeInTheDocument();
21+
});
22+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
2+
import { StyledVaccineContent } from "@src/services/content-api/types";
3+
import { JSX } from "react";
4+
5+
const Recommendation = (props: { styledVaccineContent: StyledVaccineContent }): JSX.Element => {
6+
const element = props.styledVaccineContent.recommendation ? (
7+
<div data-testid="recommendation">
8+
<NonUrgentCareCard
9+
heading={props.styledVaccineContent.recommendation.heading}
10+
content={props.styledVaccineContent.recommendation.component}
11+
/>
12+
</div>
13+
) : (
14+
<></>
15+
);
16+
17+
return element;
18+
};
19+
export default Recommendation;

src/app/_components/vaccine/Vaccine.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"use server";
22

33
import { auth } from "@project/auth";
4-
import { Callout } from "@src/app/_components/content/Callout";
4+
import Callout from "@src/app/_components/content/Callout";
55
import { FindOutMoreLink } from "@src/app/_components/content/FindOutMore";
66
import { HowToGetVaccineFallback } from "@src/app/_components/content/HowToGetVaccineFallback";
77
import { MoreInformation } from "@src/app/_components/content/MoreInformation";
88
import { Overview } from "@src/app/_components/content/Overview";
9+
import Recommendation from "@src/app/_components/content/Recommendation";
910
import { EligibilityVaccinePageContent } from "@src/app/_components/eligibility/EligibilityVaccinePageContent";
10-
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
1111
import { RSVPregnancyInfo } from "@src/app/_components/vaccine-custom/RSVPregnancyInfo";
1212
import { NhsNumber, VaccineDetails, VaccineInfo, VaccineType } from "@src/models/vaccine";
1313
import { getContentForVaccine } from "@src/services/content-api/content-service";
@@ -69,15 +69,8 @@ const VaccineComponent = async ({ vaccineType }: VaccineProps): Promise<JSX.Elem
6969
{contentError != ContentErrorTypes.CONTENT_LOADING_ERROR && styledVaccineContent != undefined && (
7070
<>
7171
<Overview styledVaccineContent={styledVaccineContent} vaccineType={vaccineType} />
72+
<Recommendation styledVaccineContent={styledVaccineContent} />
7273
<Callout styledVaccineContent={styledVaccineContent} vaccineType={vaccineType} />
73-
{styledVaccineContent.recommendation && (
74-
<div data-testid="recommendation">
75-
<NonUrgentCareCard
76-
heading={styledVaccineContent.recommendation.heading}
77-
content={styledVaccineContent.recommendation.component}
78-
/>
79-
</div>
80-
)}
8174
</>
8275
)}
8376

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { Readable } from "stream";
1212

1313
jest.mock("@aws-sdk/client-s3");
1414
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
15+
const mockMarkdownWithStylingHtml = "<ul><li>sausage</li><li>egg</li><li>chips</li></ul>";
16+
jest.mock("@project/src/app/_components/markdown/MarkdownWithStyling", () => ({
17+
MarkdownWithStyling: () => mockMarkdownWithStylingHtml,
18+
}));
1519

1620
const mockRsvResponse = {
1721
Body: new Readable({

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { ConfigMock, configBuilder } from "@test-data/config/builders";
1010
jest.mock("@src/services/content-api/gateway/content-reader-service");
1111
jest.mock("@src/utils/config");
1212
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
13+
const mockMarkdownWithStylingHtml = "<ul><li>sausage</li><li>egg</li><li>chips</li></ul>";
14+
jest.mock("@project/src/app/_components/markdown/MarkdownWithStyling", () => ({
15+
MarkdownWithStyling: () => mockMarkdownWithStylingHtml,
16+
}));
1317

1418
describe("getContentForVaccine()", () => {
1519
const mockedConfig = config as ConfigMock;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const mockNBSBookingActionHTML = "NBS Booking Link Test";
2020
jest.mock("@src/app/_components/nbs/NBSBookingAction", () => ({
2121
NBSBookingAction: () => mockNBSBookingActionHTML,
2222
}));
23+
const mockMarkdownWithStylingHtml = "<ul><li>sausage</li><li>egg</li><li>chips</li></ul>";
24+
jest.mock("@project/src/app/_components/markdown/MarkdownWithStyling", () => ({
25+
MarkdownWithStyling: () => mockMarkdownWithStylingHtml,
26+
}));
2327
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
2428

2529
describe("ContentStylingService", () => {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MarkdownWithStyling } from "@project/src/app/_components/markdown/MarkdownWithStyling";
12
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
23
import UrgentCareCard from "@src/app/_components/nhs-frontend/UrgentCareCard";
34
import { VaccineType } from "@src/models/vaccine";
@@ -161,7 +162,10 @@ function styleCallout(callout: HeadingWithContent | undefined): HeadingWithConte
161162

162163
function styleRecommendation(recommendation: HeadingWithContent | undefined): StyledPageSection | undefined {
163164
if (recommendation) {
164-
return { heading: recommendation.heading, component: <>{recommendation.content}</> };
165+
return {
166+
heading: recommendation.heading,
167+
component: <MarkdownWithStyling content={recommendation.content} delineator={false} />,
168+
};
165169
}
166170
return undefined;
167171
}

0 commit comments

Comments
 (0)