Skip to content

Commit f1fa315

Browse files
VIA-630 Show vaccine cards for 64-75 on hub page
1 parent bb29546 commit f1fa315

File tree

5 files changed

+133
-3
lines changed

5 files changed

+133
-3
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { AgeBasedHubCards } from "@src/app/_components/hub/AgeBasedHubCards";
2+
import { AgeGroup } from "@src/models/ageBasedHub";
3+
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
4+
import { render, screen } from "@testing-library/react";
5+
6+
describe("Age based hub cards", () => {
7+
describe("for 65-74 year old group", () => {
8+
it("should render expected heading for age group", async () => {
9+
render(<AgeBasedHubCards ageGroup={AgeGroup.AGE_65_to_74} />);
10+
11+
const heading: HTMLElement = screen.getByRole("heading", {
12+
name: "Adults aged 65 to 74 should get these routine vaccines",
13+
level: 2,
14+
});
15+
16+
expect(heading).toBeVisible();
17+
});
18+
19+
it("should render card for each vaccine for age group", async () => {
20+
const expectedVaccinesFor65to74 = [VaccineType.PNEUMOCOCCAL, VaccineType.FLU_FOR_ADULTS, VaccineType.SHINGLES];
21+
22+
render(<AgeBasedHubCards ageGroup={AgeGroup.AGE_65_to_74} />);
23+
24+
expectedVaccinesFor65to74.map((vaccineType) => {
25+
const link: HTMLElement = screen.getByRole("link", { name: VaccineInfo[vaccineType].displayName.titleCase });
26+
27+
expect(link).toBeVisible();
28+
expect(link.getAttribute("href")).toEqual(`/vaccines/${VaccineInfo[vaccineType].urlPath}`);
29+
});
30+
});
31+
});
32+
33+
describe("for unknown age group", () => {
34+
it("should render empty component when age group is unknown", () => {
35+
const { container } = render(<AgeBasedHubCards ageGroup={AgeGroup.UNKNOWN_AGE_GROUP} />);
36+
expect(container).toBeEmptyDOMElement();
37+
});
38+
});
39+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import CardLinkWithDescription from "@src/app/_components/nhs-app/CardLinkWithDescription";
2+
import { AgeBasedHubDetails, AgeBasedHubInfo, AgeGroup } from "@src/models/ageBasedHub";
3+
import { VaccineInfo } from "@src/models/vaccine";
4+
import React, { JSX } from "react";
5+
6+
type AgeBasedHubProps = {
7+
ageGroup: AgeGroup;
8+
};
9+
10+
const AgeBasedHubCards = ({ ageGroup }: AgeBasedHubProps): JSX.Element => {
11+
const hubInfoForAgeGroup: AgeBasedHubDetails | undefined = AgeBasedHubInfo[ageGroup];
12+
13+
if (hubInfoForAgeGroup) {
14+
return (
15+
<>
16+
<h2 className="nhsuk-heading-s">{hubInfoForAgeGroup.heading}</h2>
17+
<ul className="nhsapp-cards nhsapp-cards--stacked">
18+
{hubInfoForAgeGroup.vaccines.map((ageSpecificVaccineCardDetails) => (
19+
<CardLinkWithDescription
20+
key={ageSpecificVaccineCardDetails.vaccineName}
21+
title={VaccineInfo[ageSpecificVaccineCardDetails.vaccineName].displayName.titleCase}
22+
description={ageSpecificVaccineCardDetails.cardLinkDescription}
23+
link={`/vaccines/${VaccineInfo[ageSpecificVaccineCardDetails.vaccineName].urlPath}`}
24+
/>
25+
))}
26+
</ul>
27+
</>
28+
);
29+
} else return <></>;
30+
};
31+
32+
export { AgeBasedHubCards };

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,65 @@
1+
import { auth } from "@project/auth";
2+
import { AgeBasedHubCards } from "@src/app/_components/hub/AgeBasedHubCards";
13
import VaccinationsHub from "@src/app/check-and-book-vaccinations/page";
24
import { SERVICE_HEADING } from "@src/app/constants";
5+
import { AgeGroup } from "@src/models/ageBasedHub";
6+
import { NhsNumber } from "@src/models/vaccine";
7+
import { Age } from "@src/utils/auth/types";
38
import { render, screen } from "@testing-library/react";
9+
import { Session } from "next-auth";
410

511
jest.mock("@src/app/_components/nhs-app/BackToNHSAppLink");
612

13+
jest.mock("@project/auth", () => ({
14+
auth: jest.fn(),
15+
}));
16+
17+
jest.mock("@src/app/_components/hub/AgeBasedHubCards", () => ({
18+
AgeBasedHubCards: jest
19+
.fn()
20+
.mockImplementation(() => <p data-testid={"age-based-hub-cards"}>Age based hub cards test</p>),
21+
}));
22+
23+
const mockAgeGroup = AgeGroup.AGE_25_to_64;
24+
25+
const mockSessionValue: Partial<Session> = {
26+
expires: new Date(Date.now() + 60000).toISOString(),
27+
user: {
28+
nhs_number: "" as NhsNumber,
29+
age: 25 as Age,
30+
age_group: mockAgeGroup,
31+
},
32+
};
33+
34+
const mockSession = { data: mockSessionValue, status: "authenticated" };
35+
36+
jest.mock("next-auth/react", () => ({
37+
useSession: () => mockSession,
38+
}));
39+
740
describe("Vaccination Hub Page", () => {
841
beforeEach(async () => {
9-
render(<VaccinationsHub />);
42+
(auth as jest.Mock).mockResolvedValue(mockSessionValue);
43+
44+
render(await VaccinationsHub());
1045
});
1146

1247
it("renders main heading", async () => {
1348
expectHeadingToBeRendered();
1449
});
1550

51+
it("renders age based cards for user", () => {
52+
const ageBasedHubCards: HTMLElement = screen.getByTestId("age-based-hub-cards");
53+
54+
expect(ageBasedHubCards).toBeVisible();
55+
expect(AgeBasedHubCards).toHaveBeenCalledWith(
56+
{
57+
ageGroup: mockAgeGroup,
58+
},
59+
undefined,
60+
);
61+
});
62+
1663
it("renders subheading about pregnancy", () => {
1764
const subheading: HTMLElement = getHeading("Vaccines if you're pregnant", 2);
1865
expect(subheading).toBeVisible();

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1+
"use server";
2+
3+
import { auth } from "@project/auth";
4+
import { AgeBasedHubCards } from "@src/app/_components/hub/AgeBasedHubCards";
15
import BackToNHSAppLink from "@src/app/_components/nhs-app/BackToNHSAppLink";
26
import CardLink from "@src/app/_components/nhs-app/CardLink";
37
import MainContent from "@src/app/_components/nhs-frontend/MainContent";
48
import { NHS_TITLE_SUFFIX, SERVICE_HEADING } from "@src/app/constants";
9+
import { AgeGroup } from "@src/models/ageBasedHub";
10+
import { Session } from "next-auth";
511
import Link from "next/link";
612
import React from "react";
713

8-
const VaccinationsHub = () => {
14+
const VaccinationsHub = async () => {
15+
// TODO: VIA-630 add missing request scoped storage wrapper. Check other new pages and add as required
16+
17+
const session: Session | null = await auth();
18+
const ageGroup: AgeGroup = session?.user.age_group as AgeGroup;
19+
920
return (
1021
<>
1122
<title>{`${SERVICE_HEADING} - ${NHS_TITLE_SUFFIX}`}</title>
1223
<BackToNHSAppLink />
1324
<MainContent>
1425
<h1 className={"nhsuk-heading-xl nhsuk-u-margin-bottom-3"}>{SERVICE_HEADING}</h1>
26+
<AgeBasedHubCards ageGroup={ageGroup} />
1527
<h2 className="nhsuk-heading-s">Vaccines if you&#39;re pregnant</h2>
1628
<p>Some vaccines are recommended during pregnancy to protect the health of you and your baby.</p>
1729
<ul className="nhsapp-cards nhsapp-cards--stacked" data-testid={"vaccine-cardlinks-adults"}>

src/models/ageBasedHub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type AgeSpecificVaccineCardDetails = {
1515
cardLinkDescription: string;
1616
};
1717

18-
type AgeBasedHubDetails = {
18+
export type AgeBasedHubDetails = {
1919
heading: string;
2020
vaccines: AgeSpecificVaccineCardDetails[];
2121
};

0 commit comments

Comments
 (0)