Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Test Failures #511

Draft
wants to merge 6 commits into
base: 3.1.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 148 additions & 150 deletions src/components/AccessRequest/FormDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestAccessResp, RequestAccessInput> = {
// request: {
// query: REQUEST_ACCESS,
// },
// variableMatcher: () => true,
// error: new Error("Network error"),
// };

// const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
// wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
// });

// 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<RequestAccessResp, RequestAccessInput> = {
// request: {
// query: REQUEST_ACCESS,
// },
// variableMatcher: () => true,
// result: {
// errors: [new GraphQLError("Mock GraphQL error")],
// },
// };

// const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
// wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
// });

// 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<RequestAccessResp, RequestAccessInput> = {
// 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(<FormDialog open onClose={jest.fn()} />, {
// wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
// });

// 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<RequestAccessResp, RequestAccessInput> = {
// request: {
// query: REQUEST_ACCESS,
// },
// variableMatcher: () => true,
// result: {
// data: {
// requestAccess: {
// success: false,
// message: "Mock error message",
// },
// },
// },
// };

// const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
// wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
// });

// 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<RequestAccessResp, RequestAccessInput> = {
request: {
query: REQUEST_ACCESS,
},
variableMatcher: () => true,
error: new Error("Network error"),
};

const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
});

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<RequestAccessResp, RequestAccessInput> = {
request: {
query: REQUEST_ACCESS,
},
variableMatcher: () => true,
result: {
errors: [new GraphQLError("Mock GraphQL error")],
},
};

const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
});

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<RequestAccessResp, RequestAccessInput> = {
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(<FormDialog open onClose={jest.fn()} />, {
wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
});

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<RequestAccessResp, RequestAccessInput> = {
request: {
query: REQUEST_ACCESS,
},
variableMatcher: () => true,
result: {
data: {
requestAccess: {
success: false,
message: "Mock error message",
},
},
},
};

const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
});

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<ListOrgNamesResp> = {
Expand Down Expand Up @@ -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<RequestAccessResp, RequestAccessInput> = {
// request: {
// query: REQUEST_ACCESS,
// },
// variableMatcher: () => true,
// result: {
// data: {
// requestAccess: {
// success: true,
// message: "Mock success",
// },
// },
// },
// };

// const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
// wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
// });

// 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<RequestAccessResp, RequestAccessInput> = {
request: {
query: REQUEST_ACCESS,
},
variableMatcher: () => true,
result: {
data: {
requestAccess: {
success: true,
message: "Mock success",
},
},
},
};

const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
wrapper: ({ children }) => <MockParent mocks={[emptyOrgMock, mock]}>{children}</MockParent>,
});

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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataSubmissions/DataUpload.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}));

Expand Down
14 changes: 7 additions & 7 deletions src/components/HistoryDialog/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -20,14 +21,13 @@ const BaseProps: React.ComponentProps<typeof HistoryDialog> = {
onClose: () => {},
};

// TODO: Fix this failing in CI
// describe("Accessibility", () => {
// it("should have no violations", async () => {
// const { container } = render(<HistoryDialog {...BaseProps} />);
describe("Accessibility", () => {
it("should have no violations", async () => {
const { container } = render(<HistoryDialog {...BaseProps} />);

// expect(await axe(container)).toHaveNoViolations();
// });
// });
expect(await axe(container)).toHaveNoViolations();
});
});

describe("Basic Functionality", () => {
it("should render without crashing", () => {
Expand Down
Loading