diff --git a/src/components/createDonorCasePage/createDonorCasesConfirmation.test.tsx b/src/components/createDonorCasePage/createDonorCasesConfirmation.test.tsx index 230cd838..1ea6977b 100644 --- a/src/components/createDonorCasePage/createDonorCasesConfirmation.test.tsx +++ b/src/components/createDonorCasePage/createDonorCasesConfirmation.test.tsx @@ -8,7 +8,12 @@ import { MemoryRouter, RouterProvider, createMemoryRouter, useNavigate, useParam import CreateDonorCasesConfirmation from "./createDonorCasesConfirmation"; import "@testing-library/jest-dom"; import axios from "axios"; -import { cloudFunctionAxiosError, ipsQuestionnaire, mockSuccessResponseForDonorCasesCreation } from "../../features/step_definitions/helpers/apiMockObjects"; +import { + cloudFunctionAxiosError, + ipsQuestionnaire, + mockSectionForDonorCasesCreation, + mockSuccessResponseForDonorCasesCreation +} from "../../features/step_definitions/helpers/apiMockObjects"; jest.mock("axios"); @@ -81,15 +86,16 @@ describe("CreateDonorCasesConfirmation navigation", () => { }); it("should redirect back to the questionnaire details page if user clicks Cancel", async () => { - + act(() => { fireEvent.click(screen.getByRole("button", { name: "Cancel" })); }); expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", { state: { - donorCasesResponseMessage: "", - donorCasesStatusCode: 0, + section: "createDonorCases", + responseMessage: "", + statusCode: 0, role: "", questionnaire: ipsQuestionnaire, }, @@ -113,8 +119,9 @@ describe("CreateDonorCasesConfirmation navigation", () => { expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", { state: { - donorCasesResponseMessage: mockSuccessResponseForDonorCasesCreation.data, - donorCasesStatusCode: mockSuccessResponseForDonorCasesCreation.status, + section: mockSectionForDonorCasesCreation.data, + responseMessage: mockSuccessResponseForDonorCasesCreation.data, + statusCode: mockSuccessResponseForDonorCasesCreation.status, questionnaire: ipsQuestionnaire, role: "IPS Manager" } @@ -141,8 +148,9 @@ describe("CreateDonorCasesConfirmation navigation", () => { expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", { state: { - donorCasesResponseMessage: (cloudFunctionAxiosError as any).response.data.message, - donorCasesStatusCode: 500, + section: "createDonorCases", + responseMessage: (cloudFunctionAxiosError as any).response.data.message, + statusCode: 500, questionnaire: ipsQuestionnaire, role: "IPS Manager" } @@ -150,4 +158,4 @@ describe("CreateDonorCasesConfirmation navigation", () => { }); }); -}); \ No newline at end of file +}); diff --git a/src/components/reissueNewDonorCasePage/reissueNewDonorCaseConfirmation.test.tsx b/src/components/reissueNewDonorCasePage/reissueNewDonorCaseConfirmation.test.tsx index b9545bf9..c76648c3 100644 --- a/src/components/reissueNewDonorCasePage/reissueNewDonorCaseConfirmation.test.tsx +++ b/src/components/reissueNewDonorCasePage/reissueNewDonorCaseConfirmation.test.tsx @@ -8,7 +8,12 @@ import { MemoryRouter, RouterProvider, createMemoryRouter, useNavigate, useParam import ReissueNewDonorCaseConfirmation from "./reissueNewDonorCaseConfirmation"; import "@testing-library/jest-dom"; import axios from "axios"; -import { cloudFunctionAxiosError, ipsQuestionnaire, mockSuccessResponseForReissueNewDonorCase } from "../../features/step_definitions/helpers/apiMockObjects"; +import { + cloudFunctionAxiosError, + ipsQuestionnaire, + mockSectionForReissueNewDonorCase, + mockSuccessResponseForReissueNewDonorCase +} from "../../features/step_definitions/helpers/apiMockObjects"; jest.mock("axios"); @@ -29,7 +34,7 @@ describe("ReissueNewDonorCaseConfirmation rendering", () => { }); it("displays correct prompt to reissue new donor case", () => { - expect(screen.getByText("Reissue new donor case for ?")).toBeInTheDocument(); + expect(screen.getByText("Reissue a new donor case for on behalf of ?")).toBeInTheDocument(); }); it("displays the correct number of breadcrumbs", () => { @@ -61,7 +66,7 @@ describe("ReissueNewDonorCaseConfirmation navigation", () => { const initialEntries = [ { pathname: "/reissueNewDonorCaseConfirmation", - state: { questionnaire: ipsQuestionnaire, role: "IPS Manager" }, + state: { questionnaire: ipsQuestionnaire, user: "testuser" }, }, ]; beforeEach(() => { @@ -88,8 +93,9 @@ describe("ReissueNewDonorCaseConfirmation navigation", () => { expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", { state: { - donorCasesResponseMessage: "", - donorCasesStatusCode: 0, + section: "reissueNewDonorCase", + responseMessage: "", + statusCode: 0, role: "", questionnaire: ipsQuestionnaire, }, @@ -106,17 +112,18 @@ describe("ReissueNewDonorCaseConfirmation navigation", () => { expect(mockedAxios.post).toHaveBeenCalledWith( "/api/cloudFunction/reissueNewDonorCase", - { questionnaire_name: ipsQuestionnaire.name, role: "IPS Manager" }, + { questionnaire_name: ipsQuestionnaire.name, role: "testuser" }, { headers: { "Content-Type": "application/json" } } ); expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", { state: { - donorCasesResponseMessage: mockSuccessResponseForReissueNewDonorCase.data, - donorCasesStatusCode: mockSuccessResponseForReissueNewDonorCase.status, + section: mockSectionForReissueNewDonorCase.data, + responseMessage: mockSuccessResponseForReissueNewDonorCase.data, + statusCode: mockSuccessResponseForReissueNewDonorCase.status, questionnaire: ipsQuestionnaire, - role: "IPS Manager" + role: "testuser" } }); @@ -134,17 +141,18 @@ describe("ReissueNewDonorCaseConfirmation navigation", () => { expect(mockedAxios.post).toHaveBeenCalledWith( "/api/cloudFunction/reissueNewDonorCase", - { questionnaire_name: ipsQuestionnaire.name, role: "IPS Manager" }, + { questionnaire_name: ipsQuestionnaire.name, role: "testuser" }, { headers: { "Content-Type": "application/json" } } ); expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", { state: { - donorCasesResponseMessage: (cloudFunctionAxiosError as any).response.data.message, - donorCasesStatusCode: 500, + section: "reissueNewDonorCase", + responseMessage: (cloudFunctionAxiosError as any).response.data.message, + statusCode: 500, questionnaire: ipsQuestionnaire, - role: "IPS Manager" + role: "testuser" } }); }); diff --git a/src/features/step_definitions/helpers/apiMockObjects.ts b/src/features/step_definitions/helpers/apiMockObjects.ts index b279a0e1..8db7590d 100644 --- a/src/features/step_definitions/helpers/apiMockObjects.ts +++ b/src/features/step_definitions/helpers/apiMockObjects.ts @@ -84,6 +84,14 @@ cloudFunctionAxiosError.response = { }, }; +export const mockSectionForDonorCasesCreation = { + data: "createDonorCases" +}; + +export const mockSectionForReissueNewDonorCase = { + data: "reissueNewDonorCase" +}; + export const mockSuccessResponseForDonorCasesCreation = { data: "Success", status: 200,