Skip to content

Commit

Permalink
Fixing Tests so far
Browse files Browse the repository at this point in the history
  • Loading branch information
lambeb committed Oct 28, 2024
1 parent 64016e9 commit a445ce3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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,
},
Expand All @@ -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"
}
Expand All @@ -141,13 +148,14 @@ 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"
}
});
});

});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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", () => {
Expand Down Expand Up @@ -61,7 +66,7 @@ describe("ReissueNewDonorCaseConfirmation navigation", () => {
const initialEntries = [
{
pathname: "/reissueNewDonorCaseConfirmation",
state: { questionnaire: ipsQuestionnaire, role: "IPS Manager" },
state: { questionnaire: ipsQuestionnaire, user: "testuser" },
},
];
beforeEach(() => {
Expand All @@ -88,8 +93,9 @@ describe("ReissueNewDonorCaseConfirmation navigation", () => {

expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", {
state: {
donorCasesResponseMessage: "",
donorCasesStatusCode: 0,
section: "reissueNewDonorCase",
responseMessage: "",
statusCode: 0,
role: "",
questionnaire: ipsQuestionnaire,
},
Expand All @@ -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"
}
});

Expand All @@ -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"
}
});
});
Expand Down
8 changes: 8 additions & 0 deletions src/features/step_definitions/helpers/apiMockObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ cloudFunctionAxiosError.response = {
},
};

export const mockSectionForDonorCasesCreation = {
data: "createDonorCases"
};

export const mockSectionForReissueNewDonorCase = {
data: "reissueNewDonorCase"
};

export const mockSuccessResponseForDonorCasesCreation = {
data: "Success",
status: 200,
Expand Down

0 comments on commit a445ce3

Please sign in to comment.