From 69308037a444784784f8364b3d8b53b02148975e Mon Sep 17 00:00:00 2001 From: Alec M Date: Mon, 28 Oct 2024 14:42:30 -0400 Subject: [PATCH 1/4] fix: ENV based test failures --- src/components/DataSubmissions/DataUpload.test.tsx | 2 +- src/utils/dataModelUtils.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/DataSubmissions/DataUpload.test.tsx b/src/components/DataSubmissions/DataUpload.test.tsx index 8b138cfd..fdfa1978 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/utils/dataModelUtils.test.ts b/src/utils/dataModelUtils.test.ts index ba82b64b..f80c6aba 100644 --- a/src/utils/dataModelUtils.test.ts +++ b/src/utils/dataModelUtils.test.ts @@ -4,7 +4,7 @@ import * as utils from "./dataModelUtils"; global.fetch = jest.fn(); jest.mock("../env", () => ({ - ...jest.requireActual("../env"), + ...process.env, REACT_APP_DEV_TIER: undefined, })); From 66990693be689c94da5a73b44a9ef32474845ee0 Mon Sep 17 00:00:00 2001 From: Alec M Date: Wed, 30 Oct 2024 14:02:59 -0400 Subject: [PATCH 2/4] Revert "Temporarily disable failing tests" This reverts commit cbb196f29be59d36cd432e8f59abb0047aa2c11f. --- .../AccessRequest/FormDialog.test.tsx | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/src/components/AccessRequest/FormDialog.test.tsx b/src/components/AccessRequest/FormDialog.test.tsx index 599ea29b..9f624e38 100644 --- a/src/components/AccessRequest/FormDialog.test.tsx +++ b/src/components/AccessRequest/FormDialog.test.tsx @@ -158,31 +158,30 @@ 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"), - // }; + 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}, - // }); + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - // userEvent.click(getByTestId("access-request-dialog-submit-button")); + 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" } - // ); - // }); - // }); + 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 = { @@ -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", - // }, - // }, - // }, - // }; + 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}, - // }); + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - // userEvent.click(getByTestId("access-request-dialog-submit-button")); + 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")).toBeDisabled(); + }); - // await waitFor(() => { - // expect(getByTestId("access-request-dialog-submit-button")).not.toBeDisabled(); - // }); - // }); + await waitFor(() => { + expect(getByTestId("access-request-dialog-submit-button")).not.toBeDisabled(); + }); + }); }); describe("Implementation Requirements", () => { From d65ddb0c2f6e2e847182d8be960e7646432fb390 Mon Sep 17 00:00:00 2001 From: Alec M Date: Wed, 30 Oct 2024 14:03:24 -0400 Subject: [PATCH 3/4] Revert "Disable failing tests" This reverts commit 922f51a1934d305a21b640b8cbf2d649b8441713. --- .../AccessRequest/FormDialog.test.tsx | 100 +++++++++--------- src/components/HistoryDialog/index.test.tsx | 14 +-- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/components/AccessRequest/FormDialog.test.tsx b/src/components/AccessRequest/FormDialog.test.tsx index 9f624e38..c9aa67ff 100644 --- a/src/components/AccessRequest/FormDialog.test.tsx +++ b/src/components/AccessRequest/FormDialog.test.tsx @@ -183,65 +183,65 @@ describe("Basic Functionality", () => { }); }); - // 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")], - // }, - // }; + 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}, - // }); + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - // userEvent.click(getByTestId("access-request-dialog-submit-button")); + 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" } - // ); - // }); - // }); + 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")], - // }, - // }; + 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}, - // }); + const { getByTestId } = render(, { + wrapper: ({ children }) => {children}, + }); - // userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field + userEvent.type(getByTestId("access-request-organization-field"), "My Mock Organization"); // Required field - // userEvent.click(getByTestId("access-request-dialog-submit-button")); + 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" } - // ); - // }); - // }); + 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 = { 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", () => { From 81a9045bf927e9cfbe2399e8248c6c2109c15041 Mon Sep 17 00:00:00 2001 From: Alec M Date: Wed, 30 Oct 2024 14:03:43 -0400 Subject: [PATCH 4/4] Revert "More failing tests" This reverts commit 1ef93540655de716f8ae2876413535aad9132f73. --- .../AccessRequest/FormDialog.test.tsx | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/components/AccessRequest/FormDialog.test.tsx b/src/components/AccessRequest/FormDialog.test.tsx index c9aa67ff..86c79841 100644 --- a/src/components/AccessRequest/FormDialog.test.tsx +++ b/src/components/AccessRequest/FormDialog.test.tsx @@ -243,37 +243,37 @@ describe("Basic Functionality", () => { }); }); - // 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 (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 = {