Skip to content

Commit 73d4c14

Browse files
VIA-630 Hub: Add 'at risk groups' expander and extract pregnancy component
1 parent 22aa047 commit 73d4c14

File tree

7 files changed

+169
-17
lines changed

7 files changed

+169
-17
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { AtRiskHubContent } from "@src/app/_components/hub/AtRiskHubContent";
2+
import { render, screen } from "@testing-library/react";
3+
4+
jest.mock("@src/app/_components/hub/AtRiskText", () => ({
5+
AtRiskText: jest.fn().mockImplementation(() => <p data-testid={"at-risk-text"}>At risk hub content test</p>),
6+
}));
7+
8+
describe("At risk hub content", () => {
9+
beforeEach(() => {
10+
render(AtRiskHubContent());
11+
});
12+
13+
it("should render heading as h2", () => {
14+
const atRiskHeading: HTMLElement = getHeading("Recommended vaccines for at-risk groups", 2);
15+
expect(atRiskHeading).toBeVisible();
16+
});
17+
18+
it("should include at risk text content", () => {
19+
const atRiskText: HTMLElement = screen.getByTestId("at-risk-text");
20+
21+
expect(atRiskText).toBeInTheDocument();
22+
});
23+
});
24+
25+
const getHeading = (text: string, level: number): HTMLElement => {
26+
return screen.getByRole("heading", {
27+
name: text,
28+
level: level,
29+
});
30+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { AtRiskText } from "@src/app/_components/hub/AtRiskText";
2+
import React, { JSX } from "react";
3+
4+
const AtRiskHubContent = (): JSX.Element => {
5+
return (
6+
<details className="nhsuk-details">
7+
<summary className="nhsuk-details__summary">
8+
<h2 className="nhsuk-heading-xs nhsuk-u-margin-0 nhsuk-u-font-weight-normal">
9+
<span className="nhsuk-details__summary-text">Recommended vaccines for at-risk groups</span>
10+
</h2>
11+
</summary>
12+
<div className="nhsuk-details__text">
13+
<AtRiskText />
14+
</div>
15+
</details>
16+
);
17+
};
18+
19+
export { AtRiskHubContent };
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const AtRiskText = () => {
2+
return (
3+
<>
4+
<h3 className="nhsuk-heading-xs nhsuk-u-margin-bottom-0">At-risk babies and children</h3>
5+
<p> Speak to your GP or health visitor.</p>
6+
<h3 className="nhsuk-heading-xs nhsuk-u-margin-bottom-0">Long-term health conditions</h3>
7+
<p>
8+
Speak to your GP or{" "}
9+
<a href={"https://www.nhs.uk/service-search/pharmacy/find-a-pharmacy/"} target="_blank" rel="noopener">
10+
pharmacy
11+
</a>{" "}
12+
about what vaccinations you might need.
13+
</p>
14+
<h3 className="nhsuk-heading-xs nhsuk-u-margin-bottom-0">Sexual health</h3>
15+
<p>
16+
{" "}
17+
NHS vaccines are recommended for men who have sex with men, sex workers or other people at higher risk. Ask at
18+
your{" "}
19+
<a
20+
href="https://www.nhs.uk/nhs-services/sexual-health-services/find-a-sexual-health-clinic/"
21+
target="_blank"
22+
rel="noopener"
23+
>
24+
sexual health clinic
25+
</a>
26+
.
27+
</p>
28+
<h3 className="nhsuk-heading-xs nhsuk-u-margin-bottom-0">Travel</h3>
29+
<p>
30+
{" "}
31+
If you&#39;re planning to{" "}
32+
<a href="https://www.nhs.uk/vaccinations/travel-vaccinations/" target="_blank" rel="noopener">
33+
travel outside the UK
34+
</a>
35+
, you may need to be vaccinated against some of the serious diseases found in other parts of the world. Speak to
36+
your GP.
37+
</p>
38+
<h3 className="nhsuk-heading-xs nhsuk-u-margin-bottom-0">Occupation</h3>
39+
<p> Check with your employer about what vaccinations you might need.</p>
40+
</>
41+
);
42+
};
43+
44+
export { AtRiskText };
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { PregnancyHubContent } from "@src/app/_components/hub/PregnancyHubContent";
2+
import { render, screen } from "@testing-library/react";
3+
4+
describe("Pregnancy hub content", () => {
5+
beforeEach(() => {
6+
render(<PregnancyHubContent />);
7+
});
8+
9+
it("renders subheading about pregnancy", () => {
10+
const subheading: HTMLElement = getHeading("Vaccines if you're pregnant", 2);
11+
expect(subheading).toBeVisible();
12+
});
13+
14+
it("renders subtext about pregnancy", () => {
15+
const subtext: HTMLElement = screen.getByText(
16+
"Some vaccines are recommended during pregnancy to protect the health of you and your baby.",
17+
);
18+
expect(subtext).toBeVisible();
19+
});
20+
21+
it("renders vaccines during pregnancy card link", async () => {
22+
expectLinkToBeRendered("Vaccines during pregnancy", "/vaccines-during-pregnancy");
23+
});
24+
});
25+
26+
const expectLinkToBeRendered = (text: string, href: string) => {
27+
const link: HTMLElement = screen.getByRole("link", { name: text });
28+
expect(link).toBeVisible();
29+
expect(link).toHaveAttribute("href", href);
30+
};
31+
32+
const getHeading = (text: string, level: number): HTMLElement => {
33+
return screen.getByRole("heading", {
34+
name: text,
35+
level: level,
36+
});
37+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import CardLink from "@src/app/_components/nhs-app/CardLink";
2+
3+
const PregnancyHubContent = () => {
4+
return (
5+
<>
6+
<h2 className="nhsuk-heading-s">Vaccines if you&#39;re pregnant</h2>
7+
<p>Some vaccines are recommended during pregnancy to protect the health of you and your baby.</p>
8+
<ul className="nhsapp-cards nhsapp-cards--stacked" data-testid={"vaccine-cardlinks-adults"}>
9+
<CardLink title={"Vaccines during pregnancy"} link={"/vaccines-during-pregnancy"} />
10+
</ul>
11+
</>
12+
);
13+
};
14+
15+
export { PregnancyHubContent };

src/app/check-and-book-vaccinations/page.test.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ jest.mock("@src/app/_components/hub/AgeBasedHubCards", () => ({
2020
.mockImplementation(() => <p data-testid={"age-based-hub-cards"}>Age based hub cards test</p>),
2121
}));
2222

23+
jest.mock("@src/app/_components/hub/AtRiskHubContent", () => ({
24+
AtRiskHubContent: jest
25+
.fn()
26+
.mockImplementation(() => <p data-testid={"at-risk-hub-content"}>At risk hub content test</p>),
27+
}));
28+
29+
jest.mock("@src/app/_components/hub/PregnancyHubContent", () => ({
30+
PregnancyHubContent: jest
31+
.fn()
32+
.mockImplementation(() => <p data-testid={"pregnancy-hub-content"}>Pregnancy hub content test</p>),
33+
}));
34+
2335
const mockAgeGroup = AgeGroup.AGE_25_to_64;
2436

2537
const mockSessionValue: Partial<Session> = {
@@ -60,20 +72,16 @@ describe("Vaccination Hub Page", () => {
6072
);
6173
});
6274

63-
it("renders subheading about pregnancy", () => {
64-
const subheading: HTMLElement = getHeading("Vaccines if you're pregnant", 2);
65-
expect(subheading).toBeVisible();
66-
});
75+
it("should show at risk expander ", () => {
76+
const atRiskHubContent: HTMLElement = screen.getByTestId("at-risk-hub-content");
6777

68-
it("renders subtext about pregnancy", () => {
69-
const subtext: HTMLElement = screen.getByText(
70-
"Some vaccines are recommended during pregnancy to protect the health of you and your baby.",
71-
);
72-
expect(subtext).toBeVisible();
78+
expect(atRiskHubContent).toBeVisible();
7379
});
7480

75-
it("renders vaccines during pregnancy card link", async () => {
76-
expectLinkToBeRendered("Vaccines during pregnancy", "/vaccines-during-pregnancy");
81+
it("should show pregnancy hub content ", () => {
82+
const pregnancyHubContent: HTMLElement = screen.getByTestId("pregnancy-hub-content");
83+
84+
expect(pregnancyHubContent).toBeVisible();
7785
});
7886

7987
it("renders vaccines for all ages button", async () => {

src/app/check-and-book-vaccinations/page.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import { auth } from "@project/auth";
44
import { AgeBasedHubCards } from "@src/app/_components/hub/AgeBasedHubCards";
5+
import { AtRiskHubContent } from "@src/app/_components/hub/AtRiskHubContent";
6+
import { PregnancyHubContent } from "@src/app/_components/hub/PregnancyHubContent";
57
import BackToNHSAppLink from "@src/app/_components/nhs-app/BackToNHSAppLink";
6-
import CardLink from "@src/app/_components/nhs-app/CardLink";
78
import MainContent from "@src/app/_components/nhs-frontend/MainContent";
89
import { NHS_TITLE_SUFFIX, SERVICE_HEADING } from "@src/app/constants";
910
import { AgeGroup } from "@src/models/ageBasedHub";
@@ -24,11 +25,9 @@ const VaccinationsHub = async () => {
2425
<MainContent>
2526
<h1 className={"nhsuk-heading-xl nhsuk-u-margin-bottom-3"}>{SERVICE_HEADING}</h1>
2627
<AgeBasedHubCards ageGroup={ageGroup} />
27-
<h2 className="nhsuk-heading-s">Vaccines if you&#39;re pregnant</h2>
28-
<p>Some vaccines are recommended during pregnancy to protect the health of you and your baby.</p>
29-
<ul className="nhsapp-cards nhsapp-cards--stacked" data-testid={"vaccine-cardlinks-adults"}>
30-
<CardLink title={"Vaccines during pregnancy"} link={"/vaccines-during-pregnancy"} />
31-
</ul>
28+
{/*TODO VIA-630 control visibility of the following components based on age*/}
29+
<AtRiskHubContent />
30+
<PregnancyHubContent />
3231
<Link href={"/vaccines-for-all-ages"} className={"nhsuk-button nhsuk-button--secondary"}>
3332
View vaccines for all ages
3433
</Link>

0 commit comments

Comments
 (0)