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

CRDCDH-1743 Implement "Request Access" form #499

Draft
wants to merge 3 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
125 changes: 125 additions & 0 deletions src/components/AccessRequest/FormDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { cleanup, render, waitFor } from "@testing-library/react";

Check warning on line 1 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'cleanup' is defined but never used

Check warning on line 1 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'render' is defined but never used

Check warning on line 1 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'waitFor' is defined but never used
import { axe } from "jest-axe";

Check warning on line 2 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'axe' is defined but never used
import { MockedProvider, MockedResponse } from "@apollo/client/testing";
import { FC, useMemo } from "react";
import userEvent from "@testing-library/user-event";

Check warning on line 5 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'userEvent' is defined but never used
import {
Context as AuthContext,
ContextState as AuthContextState,
Status as AuthContextStatus,
} from "../Contexts/AuthContext";
import { LIST_ORG_NAMES, ListOrgNamesResp } from "../../graphql";

Check warning on line 11 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'LIST_ORG_NAMES' is defined but never used

Check warning on line 11 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'ListOrgNamesResp' is defined but never used
import FormDialog from "./FormDialog";

Check warning on line 12 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'FormDialog' is defined but never used

const mockUser: Omit<User, "role"> = {
_id: "",
firstName: "",
lastName: "",
email: "",
organization: null,
dataCommons: [],
studies: [],
IDP: "nih",
userStatus: "Active",
updateAt: "",
createdAt: "",
};

type MockParentProps = {
mocks: MockedResponse[];
role: UserRole;
children: React.ReactNode;
};

const MockParent: FC<MockParentProps> = ({ mocks, role, children }) => {

Check warning on line 34 in src/components/AccessRequest/FormDialog.test.tsx

View workflow job for this annotation

GitHub Actions / Lint Changes

'MockParent' is assigned a value but never used
const authValue: AuthContextState = useMemo<AuthContextState>(
() => ({
isLoggedIn: true,
status: AuthContextStatus.LOADED,
user: { ...mockUser, role },
}),
[role]
);

return (
<MockedProvider mocks={mocks} addTypename={false}>
<AuthContext.Provider value={authValue}>{children}</AuthContext.Provider>
</MockedProvider>
);
};

describe("Accessibility", () => {
beforeEach(() => {
jest.resetAllMocks();
});

it("should have no violations", async () => {
// const mocks: MockedResponse<ListOrgNamesResp> = {
// request: {
// query: LIST_ORG_NAMES,
// },
// result: {
// data: {
// listOrganizations: [],
// },
// },
// variableMatcher: () => true,
// };
// const mockOnClose = jest.fn();
// const { container } = render(<FormDialog open onClose={mockOnClose} />, {
// wrapper: ({ children }) => (
// <MockParent mocks={[mocks]} role="User">
// {children}
// </MockParent>
// ),
// });
// expect(await axe(container)).toHaveNoViolations();
});
});

describe("Basic Functionality", () => {
beforeEach(() => {
jest.resetAllMocks();
});

it("should render without crashing", () => {});

it("should close the dialog when the 'Close' button is clicked", async () => {});

it("should close the dialog when the 'X' icon is clicked", async () => {});

it("should close the dialog when the backdrop is clicked", async () => {});

it("should trim whitespace from the text fields before submitting", async () => {});

it("should gracefully handle API errors (Network)", async () => {});

it("should gracefully handle API errors (GraphQL)", async () => {});

it("should gracefully handle API errors (Failed Response)", async () => {});
});

describe("Implementation Requirements", () => {
beforeEach(() => {
jest.resetAllMocks();
});

it("should not submit the form if 'Role' or 'Organization' is invalid", async () => {});

it("should have a tooltip on the 'Role' input", async () => {});

it("should have a tooltip on the 'Organization' input", async () => {});

it("should have a tooltip on the 'Additional Info' input", async () => {});

// NOTE: ensure it validates and submits the entered data correctly
it("should allow free text in the Organization input", async () => {});

it("should limit 'Additional Info' to 200 characters", async () => {});

it("should pre-select the user's current role and organization if assigned", async () => {});

it("should not pre-select the user's current role if it's not a valid option", async () => {});

it("should not pre-select the user's current organization if one is not assigned", async () => {});
});
Loading
Loading