Skip to content

Commit 1956418

Browse files
committed
NHS register steps
1 parent b25866a commit 1956418

6 files changed

Lines changed: 415 additions & 49 deletions

File tree

src/app/[locale]/account/profile/cohort-discovery-request/components/NhsSdeAccessStepper/NhsSdeAccessStepper.test.tsx

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import userEvent from "@testing-library/user-event";
22
import NhsSdeAccessStepper from "./NhsSdeAccessStepper";
3-
import { render, screen } from "@/utils/testUtils";
3+
import { render, screen, waitFor } from "@/utils/testUtils";
44

55
const mockUseCohortStatus = jest.fn();
66
const mockUseFeatures = jest.fn();
7+
const mockSubmitIndicate = jest.fn().mockResolvedValue(true);
8+
const mockShowModal = jest.fn();
9+
10+
let lastModalProps: { onSuccess?: () => void | Promise<void> } | undefined;
711

812
jest.mock("@/hooks/useAuth", () => ({
913
__esModule: true,
@@ -20,9 +24,46 @@ jest.mock("@/providers/FeatureProvider", () => ({
2024
useFeatures: () => mockUseFeatures(),
2125
}));
2226

27+
jest.mock("@/hooks/usePost", () => ({
28+
__esModule: true,
29+
default: () => mockSubmitIndicate,
30+
}));
31+
32+
jest.mock("@/hooks/useModal", () => ({
33+
__esModule: true,
34+
default: () => ({
35+
showModal: (props: { onSuccess?: () => void }) => {
36+
lastModalProps = props;
37+
mockShowModal(props);
38+
},
39+
}),
40+
}));
41+
42+
jest.mock("@/utils/revalidateCache", () => ({
43+
__esModule: true,
44+
revalidateCache: jest.fn(),
45+
}));
46+
47+
jest.mock("@/components/RequestNhseSdeAccessButton", () => ({
48+
__esModule: true,
49+
default: ({ label }: { label?: string }) => (
50+
<button type="button">{label}</button>
51+
),
52+
}));
53+
54+
jest.mock("@/components/IndicateNhseSdeAccessButton", () => ({
55+
__esModule: true,
56+
default: ({ label, action }: { label?: string; action?: () => void }) => (
57+
<button type="button" onClick={() => action && action()}>
58+
{label}
59+
</button>
60+
),
61+
}));
62+
2363
const baseStatus = {
2464
requestStatus: null,
2565
nhseSdeRequestStatus: null,
66+
requestExpiry: null,
2667
isLoading: false,
2768
hasFetched: true,
2869
refetch: jest.fn(),
@@ -34,6 +75,8 @@ const renderStepper = () => render(<NhsSdeAccessStepper />);
3475

3576
describe("NhsSdeAccessStepper", () => {
3677
beforeEach(() => {
78+
jest.clearAllMocks();
79+
lastModalProps = undefined;
3780
mockUseCohortStatus.mockReturnValue(baseStatus);
3881
mockUseFeatures.mockReturnValue(baseFeatures);
3982
});
@@ -85,4 +128,87 @@ describe("NhsSdeAccessStepper", () => {
85128
screen.queryByText("Existing Cohort Discovery Access")
86129
).not.toBeInTheDocument();
87130
});
131+
132+
it("shows an Awaiting Action badge and activates step 2 when the NHS request is IN PROCESS", async () => {
133+
mockUseCohortStatus.mockReturnValue({
134+
...baseStatus,
135+
requestStatus: "APPROVED",
136+
nhseSdeRequestStatus: "IN PROCESS",
137+
});
138+
139+
renderStepper();
140+
141+
expect(screen.getByText("Awaiting Action")).toBeInTheDocument();
142+
expect(
143+
screen.getByRole("button", {
144+
name: "Open NHS SDE Registration Form",
145+
})
146+
).toBeInTheDocument();
147+
expect(
148+
screen.getByRole("button", {
149+
name: "I confirm I have completed the NHS Registration Form",
150+
})
151+
).toBeInTheDocument();
152+
});
153+
154+
it("advances to step 3 and fires the indicate POST via the confirm modal once the form is completed", async () => {
155+
mockUseCohortStatus.mockReturnValue({
156+
...baseStatus,
157+
requestStatus: "APPROVED",
158+
nhseSdeRequestStatus: "IN PROCESS",
159+
});
160+
161+
renderStepper();
162+
163+
await userEvent.click(
164+
screen.getByRole("button", {
165+
name: "I confirm I have completed the NHS Registration Form",
166+
})
167+
);
168+
169+
const indicateButton = screen.getByRole("button", {
170+
name: "I confirm I have been approved by the NHS Research SDE",
171+
});
172+
expect(indicateButton).toBeInTheDocument();
173+
174+
await userEvent.click(indicateButton);
175+
expect(mockShowModal).toHaveBeenCalled();
176+
177+
if (lastModalProps && lastModalProps.onSuccess) {
178+
await lastModalProps.onSuccess();
179+
}
180+
181+
await waitFor(() =>
182+
expect(mockSubmitIndicate).toHaveBeenCalledWith({})
183+
);
184+
});
185+
186+
it("shows a Pending badge when NHS approval has been requested", () => {
187+
mockUseCohortStatus.mockReturnValue({
188+
...baseStatus,
189+
requestStatus: "APPROVED",
190+
nhseSdeRequestStatus: "APPROVAL REQUESTED",
191+
});
192+
193+
renderStepper();
194+
195+
expect(screen.getByText("Pending")).toBeInTheDocument();
196+
expect(
197+
screen.queryByRole("button", {
198+
name: "Open NHS SDE Registration Form",
199+
})
200+
).not.toBeInTheDocument();
201+
});
202+
203+
it("shows an Approved badge when NHS access has been granted", () => {
204+
mockUseCohortStatus.mockReturnValue({
205+
...baseStatus,
206+
requestStatus: "APPROVED",
207+
nhseSdeRequestStatus: "APPROVED",
208+
});
209+
210+
renderStepper();
211+
212+
expect(screen.getByText("Approved")).toBeInTheDocument();
213+
});
88214
});

0 commit comments

Comments
 (0)