Skip to content

Commit 72bac5d

Browse files
VIA-630 Show or hide pregnancy hub content based on age group
1 parent daf3a79 commit 72bac5d

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

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

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,58 +31,71 @@ jest.mock("@src/app/_components/hub/PregnancyHubContent", () => ({
3131
.mockImplementation(() => <p data-testid={"pregnancy-hub-content"}>Pregnancy hub content test</p>),
3232
}));
3333

34-
const mockAgeGroup = AgeGroup.AGE_25_to_64;
35-
36-
const mockSessionValue: Partial<Session> = {
37-
expires: new Date(Date.now() + 60000).toISOString(),
38-
user: {
39-
nhs_number: "" as NhsNumber,
40-
age_group: mockAgeGroup,
41-
},
34+
const mockSessionDataForAgeGroup = (ageGroup: AgeGroup): Partial<Session> => {
35+
return {
36+
expires: new Date(Date.now() + 60000).toISOString(),
37+
user: {
38+
nhs_number: "" as NhsNumber,
39+
age_group: ageGroup,
40+
},
41+
};
4242
};
4343

44-
const mockSession = { data: mockSessionValue, status: "authenticated" };
44+
describe("Vaccination Hub Page", () => {
45+
describe("for all ages", () => {
46+
const mockAgeGroup = AgeGroup.AGE_25_to_64;
4547

46-
jest.mock("next-auth/react", () => ({
47-
useSession: () => mockSession,
48-
}));
48+
beforeEach(async () => {
49+
(auth as jest.Mock).mockResolvedValue(mockSessionDataForAgeGroup(mockAgeGroup));
4950

50-
describe("Vaccination Hub Page", () => {
51-
beforeEach(async () => {
52-
(auth as jest.Mock).mockResolvedValue(mockSessionValue);
51+
render(await VaccinationsHub());
52+
});
5353

54-
render(await VaccinationsHub());
55-
});
54+
it("renders main heading", async () => {
55+
expectHeadingToBeRendered();
56+
});
5657

57-
it("renders main heading", async () => {
58-
expectHeadingToBeRendered();
59-
});
58+
it("renders age based cards for user", () => {
59+
const ageBasedHubCards: HTMLElement = screen.getByTestId("age-based-hub-cards");
6060

61-
it("renders age based cards for user", () => {
62-
const ageBasedHubCards: HTMLElement = screen.getByTestId("age-based-hub-cards");
61+
expect(ageBasedHubCards).toBeVisible();
62+
expect(AgeBasedHubCards).toHaveBeenCalledWith(
63+
{
64+
ageGroup: mockAgeGroup,
65+
},
66+
undefined,
67+
);
68+
});
6369

64-
expect(ageBasedHubCards).toBeVisible();
65-
expect(AgeBasedHubCards).toHaveBeenCalledWith(
66-
{
67-
ageGroup: mockAgeGroup,
68-
},
69-
undefined,
70-
);
71-
});
70+
it("should show at risk expander ", () => {
71+
const atRiskHubExpander: HTMLElement = screen.getByTestId("at-risk-hub-expander");
72+
expect(atRiskHubExpander).toBeVisible();
73+
});
7274

73-
it("should show at risk expander ", () => {
74-
const atRiskHubExpander: HTMLElement = screen.getByTestId("at-risk-hub-expander");
75-
expect(atRiskHubExpander).toBeVisible();
76-
});
75+
it("should show pregnancy hub content ", () => {
76+
const pregnancyHubContent: HTMLElement = screen.getByTestId("pregnancy-hub-content");
7777

78-
it("should show pregnancy hub content ", () => {
79-
const pregnancyHubContent: HTMLElement = screen.getByTestId("pregnancy-hub-content");
78+
expect(pregnancyHubContent).toBeVisible();
79+
});
8080

81-
expect(pregnancyHubContent).toBeVisible();
81+
it("renders vaccines for all ages button", async () => {
82+
expectLinkToBeRendered("View vaccines for all ages", "/vaccines-for-all-ages");
83+
});
8284
});
8385

84-
it("renders vaccines for all ages button", async () => {
85-
expectLinkToBeRendered("View vaccines for all ages", "/vaccines-for-all-ages");
86+
describe("pregnancy hub content", () => {
87+
it.each([
88+
{ description: "hide", ageGroup: AgeGroup.AGE_65_to_74, shouldShowPregnancyContent: false },
89+
{ description: "show", ageGroup: AgeGroup.UNKNOWN_AGE_GROUP, shouldShowPregnancyContent: true },
90+
])(`$ageGroup should $description pregnancy content`, async ({ ageGroup, shouldShowPregnancyContent }) => {
91+
(auth as jest.Mock).mockResolvedValue(mockSessionDataForAgeGroup(ageGroup));
92+
93+
render(await VaccinationsHub());
94+
95+
const pregnancyHubContent: HTMLElement | null = screen.queryByTestId("pregnancy-hub-content");
96+
97+
shouldShowPregnancyContent ? expect(pregnancyHubContent).toBeVisible() : expect(pregnancyHubContent).toBeNull();
98+
});
8699
});
87100
});
88101

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PregnancyHubContent } from "@src/app/_components/hub/PregnancyHubConten
77
import BackToNHSAppLink from "@src/app/_components/nhs-app/BackToNHSAppLink";
88
import MainContent from "@src/app/_components/nhs-frontend/MainContent";
99
import { NHS_TITLE_SUFFIX, SERVICE_HEADING } from "@src/app/constants";
10-
import { AgeGroup } from "@src/models/ageBasedHub";
10+
import { AgeBasedHubDetails, AgeBasedHubInfo, AgeGroup } from "@src/models/ageBasedHub";
1111
import { Session } from "next-auth";
1212
import Link from "next/link";
1313
import React from "react";
@@ -17,6 +17,7 @@ const VaccinationsHub = async () => {
1717

1818
const session: Session | null = await auth();
1919
const ageGroup: AgeGroup = session?.user.age_group as AgeGroup;
20+
const hubInfoForAgeGroup: AgeBasedHubDetails | undefined = AgeBasedHubInfo[ageGroup];
2021

2122
return (
2223
<>
@@ -25,9 +26,8 @@ const VaccinationsHub = async () => {
2526
<MainContent>
2627
<h1 className={"nhsuk-heading-xl nhsuk-u-margin-bottom-3"}>{SERVICE_HEADING}</h1>
2728
<AgeBasedHubCards ageGroup={ageGroup} />
28-
{/*TODO VIA-630 control visibility of the following components based on age*/}
2929
<AtRiskHubExpander />
30-
<PregnancyHubContent />
30+
{(hubInfoForAgeGroup?.showPregnancyHubContent || hubInfoForAgeGroup === undefined) && <PregnancyHubContent />}
3131
<Link href={"/vaccines-for-all-ages"} className={"nhsuk-button nhsuk-button--secondary"}>
3232
View vaccines for all ages
3333
</Link>

src/models/ageBasedHub.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type AgeSpecificVaccineCardDetails = {
1818
export type AgeBasedHubDetails = {
1919
heading: string;
2020
vaccines: AgeSpecificVaccineCardDetails[];
21+
showPregnancyHubContent: boolean;
2122
};
2223

2324
// TODO: VIA-630 remove 'undefined' from the type definition below after all hubs are implemented?
@@ -32,6 +33,7 @@ const AgeBasedHubInfo: Record<AgeGroup, AgeBasedHubDetails | undefined> = {
3233
{ vaccineName: VaccineType.FLU_FOR_ADULTS, cardLinkDescription: "65 years and over" },
3334
{ vaccineName: VaccineType.SHINGLES, cardLinkDescription: "65 to 67 and 70 to 79 years" },
3435
],
36+
showPregnancyHubContent: false,
3537
},
3638
AGE_75_to_80: undefined,
3739
AGE_81_PLUS: undefined,

0 commit comments

Comments
 (0)