generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathageBasedHub.test.tsx
More file actions
221 lines (175 loc) · 6.6 KB
/
ageBasedHub.test.tsx
File metadata and controls
221 lines (175 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { AgeGroup } from "@src/models/ageGroup";
import { VaccineInfo, VaccineType } from "@src/models/vaccine";
import { render, screen } from "@testing-library/react";
import React from "react";
import { AgeBasedHubInfo } from "./ageBasedHub";
jest.mock("@src/app/_components/hub/HubWarningCallout", () => ({
__esModule: true,
default: ({ heading, content }: never) => (
<div data-testid="hub-warning">
<h2>{heading}</h2>
<div>{content}</div>
</div>
),
}));
jest.mock("@src/app/_components/navigation/TransitionLink", () => ({
TransitionLink: ({ children, href, className }: never) => (
<a href={href} className={className}>
{children}
</a>
),
}));
describe("AgeBasedHubInfo", () => {
it("exports AgeBasedHubInfo and AgeGroup", () => {
expect(AgeBasedHubInfo).toBeDefined();
expect(AgeGroup).toBeDefined();
});
it("contains all expected age group keys", () => {
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.AGE_12_to_16);
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.AGE_17_to_24);
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.AGE_25_to_64);
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.AGE_65_to_74);
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.AGE_75_to_80);
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.AGE_81_PLUS);
expect(AgeBasedHubInfo).toHaveProperty(AgeGroup.UNKNOWN_AGE_GROUP);
});
describe("AGE_12_to_16", () => {
const info = AgeBasedHubInfo[AgeGroup.AGE_12_to_16]!;
it("has correct heading", () => {
expect(info.heading).toBe("Routine vaccines for children and teenagers aged 12 to 16");
});
it("has 4 vaccines", () => {
expect(info.vaccines).toHaveLength(4);
});
it("has correct vaccine names", () => {
expect(info.vaccines.map((v) => v.vaccineName)).toEqual([
VaccineType.HPV,
VaccineType.MENACWY,
VaccineType.TD_IPV_3_IN_1,
VaccineType.FLU_FOR_SCHOOL_AGED_CHILDREN,
]);
});
it("shows pregnancy hub content", () => {
expect(info.showPregnancyHubContent).toBe(true);
});
it("has no styledWarningCallout", () => {
expect(info.styledWarningCallout).toBeUndefined();
});
});
describe("AGE_17_to_24", () => {
const info = AgeBasedHubInfo[AgeGroup.AGE_17_to_24]!;
it("has correct heading", () => {
expect(info.heading).toBe("Routine vaccines for young people aged 17 to 24");
});
it("has no vaccines", () => {
expect(info.vaccines).toHaveLength(0);
});
it("shows pregnancy hub content", () => {
expect(info.showPregnancyHubContent).toBe(true);
});
it("renders styledWarningCallout correctly", () => {
render(info.styledWarningCallout!);
expect(screen.getByTestId("hub-warning")).toBeInTheDocument();
expect(screen.getByText("Are you up to date?")).toBeInTheDocument();
const listItems = screen.getAllByRole("listitem");
expect(listItems).toHaveLength(4);
const mmrLink = screen.getByRole("link", { name: /MMR vaccine/i });
expect(mmrLink).toHaveAttribute("href", `/vaccines/${VaccineInfo[VaccineType.MMR].urlPath}`);
});
});
describe("AGE_25_to_64", () => {
const info = AgeBasedHubInfo[AgeGroup.AGE_25_to_64]!;
it("has correct heading", () => {
expect(info.heading).toBe("Routine vaccines for adults aged 25 to 64");
});
it("has no vaccines", () => {
expect(info.vaccines).toHaveLength(0);
});
it("shows pregnancy hub content", () => {
expect(info.showPregnancyHubContent).toBe(true);
});
it("renders styledWarningCallout correctly", () => {
render(info.styledWarningCallout!);
expect(screen.getByTestId("hub-warning")).toBeInTheDocument();
expect(screen.getByText("Are you up to date?")).toBeInTheDocument();
const listItems = screen.getAllByRole("listitem");
expect(listItems).toHaveLength(2);
const mmrLink = screen.getByRole("link", { name: /MMR vaccine/i });
expect(mmrLink).toHaveAttribute("href", `/vaccines/${VaccineInfo[VaccineType.MMR].urlPath}`);
});
});
describe("AGE_65_to_74", () => {
const info = AgeBasedHubInfo[AgeGroup.AGE_65_to_74]!;
it("has correct heading", () => {
expect(info.heading).toBe("Adults aged 65 to 74 should get these routine vaccines");
});
it("has expected #vaccines", () => {
expect(info.vaccines).toHaveLength(5);
});
it("has correct vaccine names", () => {
expect(info.vaccines.map((v) => v.vaccineName)).toEqual([
VaccineType.PNEUMOCOCCAL,
VaccineType.FLU_FOR_ADULTS,
VaccineType.SHINGLES,
VaccineType.RSV,
VaccineType.COVID_19,
]);
});
it("does not show pregnancy hub content", () => {
expect(info.showPregnancyHubContent).toBe(false);
});
it("has no styledWarningCallout", () => {
expect(info.styledWarningCallout).toBeUndefined();
});
});
describe("AGE_75_to_80", () => {
const info = AgeBasedHubInfo[AgeGroup.AGE_75_to_80]!;
it("has correct heading", () => {
expect(info.heading).toBe("Adults aged 75 to 80 should get these routine vaccines");
});
it("has 5 vaccines", () => {
expect(info.vaccines).toHaveLength(5);
});
it("has correct vaccine names", () => {
expect(info.vaccines.map((v) => v.vaccineName)).toEqual([
VaccineType.PNEUMOCOCCAL,
VaccineType.FLU_FOR_ADULTS,
VaccineType.SHINGLES,
VaccineType.RSV,
VaccineType.COVID_19,
]);
});
it("does not show pregnancy hub content", () => {
expect(info.showPregnancyHubContent).toBe(false);
});
it("has no styledWarningCallout", () => {
expect(info.styledWarningCallout).toBeUndefined();
});
});
describe("AGE_81_PLUS", () => {
const info = AgeBasedHubInfo[AgeGroup.AGE_81_PLUS]!;
it("has correct heading", () => {
expect(info.heading).toBe("Adults aged 81 and over should get these routine vaccines");
});
it("has 4 vaccines", () => {
expect(info.vaccines).toHaveLength(4);
});
it("has correct vaccine names", () => {
expect(info.vaccines.map((v) => v.vaccineName)).toEqual([
VaccineType.PNEUMOCOCCAL,
VaccineType.FLU_FOR_ADULTS,
VaccineType.RSV,
VaccineType.COVID_19,
]);
});
it("does not show pregnancy hub content", () => {
expect(info.showPregnancyHubContent).toBe(false);
});
it("has no styledWarningCallout", () => {
expect(info.styledWarningCallout).toBeUndefined();
});
});
it("returns undefined for UNKNOWN_AGE_GROUP", () => {
expect(AgeBasedHubInfo[AgeGroup.UNKNOWN_AGE_GROUP]).toBeUndefined();
});
});