Skip to content

Commit ec9b0af

Browse files
VIA-603 AS Add EmergencyCareCard component
1 parent 8e831e8 commit ec9b0af

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import EmergencyCareCard from "@src/app/_components/nhs-frontend/EmergencyCareCard";
2+
import { render, screen } from "@testing-library/react";
3+
4+
describe("EmergencyCareCard", () => {
5+
it("should render component", () => {
6+
render(<EmergencyCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
7+
8+
const emergencyCareCard: HTMLElement = screen.getByTestId("emergency-care-card");
9+
10+
expect(emergencyCareCard).toBeVisible();
11+
});
12+
13+
it("should render heading", () => {
14+
render(<EmergencyCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
15+
16+
const defaultLevel2Heading: HTMLElement = screen.getByRole("heading", {
17+
name: "Immediate action required: Contact GP:",
18+
level: 2,
19+
});
20+
21+
expect(defaultLevel2Heading).toBeVisible();
22+
});
23+
24+
it("should render heading at specified heading level", () => {
25+
render(
26+
<EmergencyCareCard heading={"Contact GP lvl 3:"} headingLevel={"h3"} content={<p>this is their contact</p>} />,
27+
);
28+
29+
const level3Heading: HTMLElement = screen.getByRole("heading", {
30+
name: "Immediate action required: Contact GP lvl 3:",
31+
level: 3,
32+
});
33+
34+
expect(level3Heading).toBeVisible();
35+
});
36+
37+
it("should render heading at level 2 by default if no heading level provided", () => {
38+
render(<EmergencyCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
39+
40+
const heading: HTMLElement = screen.getByRole("heading", {
41+
name: "Immediate action required: Contact GP:",
42+
level: 2,
43+
});
44+
45+
expect(heading).toBeVisible();
46+
});
47+
48+
it("should render content inside of care card", () => {
49+
render(<EmergencyCareCard heading={"Contact GP:"} content={<p>this is their contact</p>} />);
50+
51+
const content: HTMLElement = screen.getByText("this is their contact");
52+
53+
expect(content).toBeVisible();
54+
});
55+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client";
2+
3+
import { HeadingLevel } from "@src/services/content-api/types";
4+
import { Heading } from "@src/services/eligibility-api/types";
5+
import { Card } from "nhsuk-react-components";
6+
import { JSX } from "react";
7+
8+
import styles from "./styles.module.css";
9+
10+
interface EmergencyCareCardProps {
11+
heading: Heading | string | JSX.Element;
12+
headingLevel?: HeadingLevel;
13+
content: JSX.Element;
14+
}
15+
16+
// Ref: https://service-manual.nhs.uk/design-system/patterns/help-users-decide-when-and-where-to-get-care
17+
const EmergencyCareCard = ({ heading, headingLevel, content }: EmergencyCareCardProps) => {
18+
return (
19+
<Card cardType="emergency" data-testid="emergency-care-card">
20+
{headingLevel ? (
21+
<Card.Heading headingLevel={headingLevel}>{heading}</Card.Heading>
22+
) : (
23+
<Card.Heading>{heading}</Card.Heading>
24+
)}
25+
<Card.Content className={styles.careCardZeroMarginBottom}>{content}</Card.Content>
26+
</Card>
27+
);
28+
};
29+
30+
export default EmergencyCareCard;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { MarkdownWithStyling } from "@project/src/app/_components/markdown/MarkdownWithStyling";
2+
import EmergencyCareCard from "@src/app/_components/nhs-frontend/EmergencyCareCard";
23
import NonUrgentCareCard from "@src/app/_components/nhs-frontend/NonUrgentCareCard";
34
import UrgentCareCard from "@src/app/_components/nhs-frontend/UrgentCareCard";
45
import { VaccineType } from "@src/models/vaccine";
@@ -26,12 +27,14 @@ enum SubsectionTypes {
2627
NON_URGENT = "NON_URGENT",
2728
URGENT = "URGENT",
2829
CALLOUT = "CALLOUT",
30+
EMERGENCY = "EMERGENCY",
2931
}
3032

3133
const Subsections: Record<SubsectionTypes, string> = {
3234
[SubsectionTypes.INFORMATION]: "Information",
3335
[SubsectionTypes.NON_URGENT]: "non-urgent",
3436
[SubsectionTypes.URGENT]: "urgent",
37+
[SubsectionTypes.EMERGENCY]: "immediate",
3538
[SubsectionTypes.CALLOUT]: "Callout",
3639
};
3740

@@ -84,6 +87,16 @@ const styleSubsection = (subsection: VaccinePageSubsection, id: number, isLastSu
8487
content={_getDivWithSanitisedHtml(content)}
8588
/>
8689
);
90+
} else if (subsection.name === Subsections.EMERGENCY) {
91+
const { heading, headingLevel, content } = extractHeadingAndContent(subsection.text);
92+
return (
93+
<EmergencyCareCard
94+
key={id}
95+
heading={_getDivWithSanitisedHtml(heading)}
96+
headingLevel={headingLevel}
97+
content={_getDivWithSanitisedHtml(content)}
98+
/>
99+
);
87100
} else if (subsection.name === Subsections.CALLOUT) {
88101
const { heading, content } = extractHeadingAndContent(subsection.text);
89102
return (

0 commit comments

Comments
 (0)