Skip to content

Commit 28bf25a

Browse files
VIA-301 MD: Embed UrgentCareCard into sections where needed
1 parent 8a4bc9d commit 28bf25a

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
2+
import { render, screen } from "@testing-library/react";
3+
4+
describe("NonUrgentCareCard", () => {
5+
it("should render component", () => {
6+
render(<NonUrgentCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
7+
8+
const nonUrgentCareCard: HTMLElement = screen.getByTestId("non-urgent-care-card");
9+
10+
expect(nonUrgentCareCard).toBeVisible();
11+
});
12+
13+
it("should render heading", () => {
14+
render(<NonUrgentCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
15+
16+
const heading: HTMLElement = screen.getByRole("heading", { name: "Non-urgent advice: Contact GP:", level: 2 });
17+
18+
expect(heading).toBeVisible();
19+
});
20+
21+
it("should render content inside of care card", () => {
22+
render(<NonUrgentCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
23+
24+
const content: HTMLElement = screen.getByText("this is their contact");
25+
26+
expect(content).toBeVisible();
27+
});
28+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import UrgentCareCard from "@src/app/_components/nhs-frontend/UrgentCareCard";
2+
import { render, screen } from "@testing-library/react";
3+
4+
describe("UrgentCareCard", () => {
5+
it("should render component", () => {
6+
render(<UrgentCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
7+
8+
const urgentCareCard: HTMLElement = screen.getByTestId("urgent-care-card");
9+
10+
expect(urgentCareCard).toBeVisible();
11+
});
12+
13+
it("should render heading", () => {
14+
render(<UrgentCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
15+
16+
const heading: HTMLElement = screen.getByRole("heading", { name: "Urgent advice: Contact GP:", level: 2 });
17+
18+
expect(heading).toBeVisible();
19+
});
20+
21+
it("should render content inside of care card", () => {
22+
render(<UrgentCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
23+
24+
const content: HTMLElement = screen.getByText("this is their contact");
25+
26+
expect(content).toBeVisible();
27+
});
28+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use client";
2+
3+
import { Heading } from "@src/services/eligibility-api/types";
4+
import { Card } from "nhsuk-react-components";
5+
import { JSX } from "react";
6+
7+
interface NonUrgentCareCardProps {
8+
heading: Heading | string | JSX.Element;
9+
content: JSX.Element;
10+
}
11+
12+
const UrgentCareCard = ({ heading, content }: NonUrgentCareCardProps) => {
13+
return (
14+
<Card cardType="urgent" data-testid="urgent-care-card">
15+
<Card.Heading>{heading}</Card.Heading>
16+
<Card.Content>{content}</Card.Content>
17+
</Card>
18+
);
19+
};
20+
21+
export default UrgentCareCard;

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe("ContentStylingService", () => {
4444
headline: "",
4545
};
4646

47+
const mockUrgentSubsection: VaccinePageSubsection = {
48+
type: "simpleElement",
49+
text: "<h3>Heading for Urgent Component</h3><p>This is a styled paragraph urgent subsection</p>",
50+
name: "urgent",
51+
headline: "",
52+
};
53+
4754
const mockTableSubsection: VaccinePageSubsection = {
4855
type: "tableElement",
4956
mainEntity: "<table><tr><th>Name</th><th>Age</th></tr><tr><td>Jane Smith</td><td>35</td></tr></table>",
@@ -122,6 +129,19 @@ describe("ContentStylingService", () => {
122129
expect(nonUrgent).toBeInTheDocument();
123130
});
124131

132+
it("should return styled urgent component for subsection", async () => {
133+
const styledSubsection: JSX.Element = styleSubsection(mockUrgentSubsection, 1);
134+
render(styledSubsection);
135+
136+
const text: HTMLElement = screen.getByText("This is a styled paragraph urgent subsection");
137+
const heading: HTMLElement = screen.getByText("Heading for Urgent Component");
138+
const nonUrgent: HTMLElement = screen.getByText("Urgent advice:");
139+
140+
expect(text).toBeInTheDocument();
141+
expect(heading).toBeInTheDocument();
142+
expect(nonUrgent).toBeInTheDocument();
143+
});
144+
125145
it("should return table component for subsection", async () => {
126146
const styledSubsection: JSX.Element = styleSubsection(mockTableSubsection, 1);
127147
render(styledSubsection);
@@ -155,20 +175,22 @@ describe("ContentStylingService", () => {
155175
it("should display several subsections of a concrete vaccine in one section", async () => {
156176
const mockSection: VaccinePageSection = {
157177
headline: "This is a heading",
158-
subsections: [mockMarkdownSubsection, mockNonUrgentSubsection, mockTableSubsection],
178+
subsections: [mockMarkdownSubsection, mockNonUrgentSubsection, mockUrgentSubsection, mockTableSubsection],
159179
};
160180

161181
const styledSection: StyledPageSection = styleSection(mockSection);
162182
render(styledSection.component);
163183

164184
const markdownSubsection: HTMLElement = screen.getByText("This is a styled paragraph markdown subsection");
165185
const nonUrgentSubsection: HTMLElement = screen.getByText("This is a styled paragraph non-urgent subsection");
186+
const urgentSubsection: HTMLElement = screen.getByText("This is a styled paragraph urgent subsection");
166187

167188
const columnOfTable: HTMLElement = screen.getByText("Name");
168189

169190
expect(styledSection.heading).toEqual(mockSection.headline);
170191
expect(markdownSubsection).toBeInTheDocument();
171192
expect(nonUrgentSubsection).toBeInTheDocument();
193+
expect(urgentSubsection).toBeInTheDocument();
172194
expect(columnOfTable).toBeInTheDocument();
173195
});
174196
});
@@ -189,7 +211,7 @@ describe("ContentStylingService", () => {
189211
};
190212
const mockSideEffectsSection: VaccinePageSection = {
191213
headline: "Side effects of the generic vaccine",
192-
subsections: [mockMarkdownSubsection, mockNonUrgentSubsection],
214+
subsections: [mockMarkdownSubsection, mockUrgentSubsection],
193215
};
194216
const mockContent: VaccinePageContent = {
195217
overview: "This is an overview",

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
2+
import UrgentCareCard from "@src/app/_components/nhs-frontend/UrgentCareCard";
23
import { VaccineTypes } from "@src/models/vaccine";
34
import { styleHowToGetSectionForRsv } from "@src/services/content-api/parsers/custom/rsv";
45
import { styleHowToGetSectionForRsvPregnancy } from "@src/services/content-api/parsers/custom/rsv-pregnancy";
@@ -19,12 +20,14 @@ import styles from "./styles.module.css";
1920
enum SubsectionTypes {
2021
INFORMATION = "INFORMATION",
2122
NON_URGENT = "NON_URGENT",
23+
URGENT = "URGENT",
2224
CALLOUT = "CALLOUT",
2325
}
2426

2527
const Subsections: Record<SubsectionTypes, string> = {
2628
[SubsectionTypes.INFORMATION]: "Information",
2729
[SubsectionTypes.NON_URGENT]: "non-urgent",
30+
[SubsectionTypes.URGENT]: "urgent",
2831
[SubsectionTypes.CALLOUT]: "Callout",
2932
};
3033

@@ -65,6 +68,15 @@ const styleSubsection = (subsection: VaccinePageSubsection, id: number): JSX.Ele
6568
content={_getDivWithSanitisedHtml(content)}
6669
/>
6770
);
71+
} else if (subsection.name === Subsections.URGENT) {
72+
const { heading, content } = extractHeadingAndContent(subsection.text);
73+
return (
74+
<UrgentCareCard
75+
key={id}
76+
heading={_getDivWithSanitisedHtml(heading)}
77+
content={_getDivWithSanitisedHtml(content)}
78+
/>
79+
);
6880
} else if (subsection.name === Subsections.CALLOUT) {
6981
const { heading, content } = extractHeadingAndContent(subsection.text);
7082
return (

0 commit comments

Comments
 (0)