diff --git a/src/components/AccessRequest/FormDialog.test.tsx b/src/components/AccessRequest/FormDialog.test.tsx index 599ea29b..86c79841 100644 --- a/src/components/AccessRequest/FormDialog.test.tsx +++ b/src/components/AccessRequest/FormDialog.test.tsx @@ -158,123 +158,122 @@ describe("Basic Functionality", () => { }); }); - // TODO: Fix this test failing in CI - // it("should gracefully handle API errors when submitting (Network)", async () => { - // const mock: MockedResponse = { - // request: { - // query: REQUEST_ACCESS, - // }, - // variableMatcher: () => true, - // error: new Error("Network error"), - // }; - - // const { getByTestId } = render(, { - // wrapper: ({ children }) => {children}, - // }); - - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - - // userEvent.click(getByTestId("access-request-dialog-submit-button")); - - // await waitFor(() => { - // expect(global.mockEnqueue).toHaveBeenCalledWith( - // "Unable to submit access request form. Please try again.", - // { variant: "error" } - // ); - // }); - // }); - - // it("should gracefully handle API errors when submitting (GraphQL)", async () => { - // const mock: MockedResponse = { - // request: { - // query: REQUEST_ACCESS, - // }, - // variableMatcher: () => true, - // result: { - // errors: [new GraphQLError("Mock GraphQL error")], - // }, - // }; - - // const { getByTestId } = render(, { - // wrapper: ({ children }) => {children}, - // }); - - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - - // userEvent.click(getByTestId("access-request-dialog-submit-button")); - - // await waitFor(() => { - // expect(global.mockEnqueue).toHaveBeenCalledWith( - // "Unable to submit access request form. Please try again.", - // { variant: "error" } - // ); - // }); - // }); - - // it("should gracefully handle API errors when submitting (Success with GraphQL Errors)", async () => { - // const mock: MockedResponse = { - // request: { - // query: REQUEST_ACCESS, - // }, - // variableMatcher: () => true, - // result: { - // data: { - // requestAccess: { - // success: true, - // message: "Mock success with GraphQL errors", - // }, - // }, - // errors: [new GraphQLError("Mock GraphQL error")], - // }, - // }; - - // const { getByTestId } = render(, { - // wrapper: ({ children }) => {children}, - // }); - - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - - // userEvent.click(getByTestId("access-request-dialog-submit-button")); - - // await waitFor(() => { - // expect(global.mockEnqueue).toHaveBeenCalledWith( - // "Unable to submit access request form. Please try again.", - // { variant: "error" } - // ); - // }); - // }); - - // it("should gracefully handle API errors when submitting (Error Response)", async () => { - // const mock: MockedResponse = { - // request: { - // query: REQUEST_ACCESS, - // }, - // variableMatcher: () => true, - // result: { - // data: { - // requestAccess: { - // success: false, - // message: "Mock error message", - // }, - // }, - // }, - // }; - - // const { getByTestId } = render(, { - // wrapper: ({ children }) => {children}, - // }); - - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - - // userEvent.click(getByTestId("access-request-dialog-submit-button")); - - // await waitFor(() => { - // expect(global.mockEnqueue).toHaveBeenCalledWith( - // "Unable to submit access request form. Please try again.", - // { variant: "error" } - // ); - // }); - // }); + it("should gracefully handle API errors when submitting (Network)", async () => { + const mock: MockedResponse = { + request: { + query: REQUEST_ACCESS, + }, + variableMatcher: () => true, + error: new Error("Network error"), + }; + + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); + + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + + userEvent.click(getByTestId("access-request-dialog-submit-button")); + + await waitFor(() => { + expect(global.mockEnqueue).toHaveBeenCalledWith( + "Unable to submit access request form. Please try again.", + { variant: "error" } + ); + }); + }); + + it("should gracefully handle API errors when submitting (GraphQL)", async () => { + const mock: MockedResponse = { + request: { + query: REQUEST_ACCESS, + }, + variableMatcher: () => true, + result: { + errors: [new GraphQLError("Mock GraphQL error")], + }, + }; + + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); + + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + + userEvent.click(getByTestId("access-request-dialog-submit-button")); + + await waitFor(() => { + expect(global.mockEnqueue).toHaveBeenCalledWith( + "Unable to submit access request form. Please try again.", + { variant: "error" } + ); + }); + }); + + it("should gracefully handle API errors when submitting (Success with GraphQL Errors)", async () => { + const mock: MockedResponse = { + request: { + query: REQUEST_ACCESS, + }, + variableMatcher: () => true, + result: { + data: { + requestAccess: { + success: true, + message: "Mock success with GraphQL errors", + }, + }, + errors: [new GraphQLError("Mock GraphQL error")], + }, + }; + + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); + + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + + userEvent.click(getByTestId("access-request-dialog-submit-button")); + + await waitFor(() => { + expect(global.mockEnqueue).toHaveBeenCalledWith( + "Unable to submit access request form. Please try again.", + { variant: "error" } + ); + }); + }); + + it("should gracefully handle API errors when submitting (Error Response)", async () => { + const mock: MockedResponse = { + request: { + query: REQUEST_ACCESS, + }, + variableMatcher: () => true, + result: { + data: { + requestAccess: { + success: false, + message: "Mock error message", + }, + }, + }, + }; + + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); + + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + + userEvent.click(getByTestId("access-request-dialog-submit-button")); + + await waitFor(() => { + expect(global.mockEnqueue).toHaveBeenCalledWith( + "Unable to submit access request form. Please try again.", + { variant: "error" } + ); + }); + }); it("should gracefully handle organization listing API errors (GraphQL)", async () => { const mock: MockedResponse = { @@ -318,39 +317,38 @@ describe("Basic Functionality", () => { }); }); - // TODO: Fix this test failing in CI - // it("should disable the submit button while the form is submitting", async () => { - // const mock: MockedResponse = { - // request: { - // query: REQUEST_ACCESS, - // }, - // variableMatcher: () => true, - // result: { - // data: { - // requestAccess: { - // success: true, - // message: "Mock success", - // }, - // }, - // }, - // }; - - // const { getByTestId } = render(, { - // wrapper: ({ children }) => {children}, - // }); - - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - - // userEvent.click(getByTestId("access-request-dialog-submit-button")); - - // await waitFor(() => { - // expect(getByTestId("access-request-dialog-submit-button")).toBeDisabled(); - // }); - - // await waitFor(() => { - // expect(getByTestId("access-request-dialog-submit-button")).not.toBeDisabled(); - // }); - // }); + it("should disable the submit button while the form is submitting", async () => { + const mock: MockedResponse = { + request: { + query: REQUEST_ACCESS, + }, + variableMatcher: () => true, + result: { + data: { + requestAccess: { + success: true, + message: "Mock success", + }, + }, + }, + }; + + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); + + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + + userEvent.click(getByTestId("access-request-dialog-submit-button")); + + await waitFor(() => { + expect(getByTestId("access-request-dialog-submit-button")).toBeDisabled(); + }); + + await waitFor(() => { + expect(getByTestId("access-request-dialog-submit-button")).not.toBeDisabled(); + }); + }); }); describe("Implementation Requirements", () => { diff --git a/src/components/DataSubmissions/DataUpload.test.tsx b/src/components/DataSubmissions/DataUpload.test.tsx index 43770106..be582ebf 100644 --- a/src/components/DataSubmissions/DataUpload.test.tsx +++ b/src/components/DataSubmissions/DataUpload.test.tsx @@ -14,7 +14,7 @@ import { RETRIEVE_CLI_CONFIG, RetrieveCLIConfigResp } from "../../graphql"; import { DataUpload } from "./DataUpload"; jest.mock("../../env", () => ({ - ...jest.requireActual("../../env"), + ...process.env, REACT_APP_BACKEND_API: "mocked-backend-api-url", })); diff --git a/src/components/HistoryDialog/index.test.tsx b/src/components/HistoryDialog/index.test.tsx index c02231b8..4f250214 100644 --- a/src/components/HistoryDialog/index.test.tsx +++ b/src/components/HistoryDialog/index.test.tsx @@ -1,3 +1,4 @@ +import { axe } from "jest-axe"; import { render, waitFor, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import HistoryDialog, { IconType } from "./index"; @@ -20,14 +21,13 @@ const BaseProps: React.ComponentProps = { onClose: () => {}, }; -// TODO: Fix this failing in CI -// describe("Accessibility", () => { -// it("should have no violations", async () => { -// const { container } = render(); +describe("Accessibility", () => { + it("should have no violations", async () => { + const { container } = render(); -// expect(await axe(container)).toHaveNoViolations(); -// }); -// }); + expect(await axe(container)).toHaveNoViolations(); + }); +}); describe("Basic Functionality", () => { it("should render without crashing", () => {