Skip to content

Commit

Permalink
Merge pull request #576 from CBIIT/CRDCDH-2021
Browse files Browse the repository at this point in the history
CRDCDH-2021 Collaborators Dialog Updates
  • Loading branch information
amattu2 authored Jan 6, 2025
2 parents ae73c67 + eb122f3 commit 9a68a63
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 695 deletions.
8 changes: 0 additions & 8 deletions src/components/AccessRequest/FormDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const mockUser: User = {
lastName: "",
email: "",
role: "User",
organization: null,
dataCommons: [],
studies: [],
IDP: "nih",
Expand Down Expand Up @@ -536,13 +535,6 @@ describe("Implementation Requirements", () => {
const newUser: User = {
...mockUser,
role: "Admin", // Technically not even able to see this dialog
organization: {
orgID: "123",
orgName: "NCI",
status: "Active",
createdAt: "",
updateAt: "",
},
};

const { getByTestId } = render(<FormDialog open onClose={jest.fn()} />, {
Expand Down
1 change: 0 additions & 1 deletion src/components/AccessRequest/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const mockUser: Omit<User, "role" | "permissions"> = {
firstName: "",
lastName: "",
email: "",
organization: null,
dataCommons: [],
studies: [],
IDP: "nih",
Expand Down
11 changes: 2 additions & 9 deletions src/components/Collaborators/CollaboratorsDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ const mockUser: User = {
email: "[email protected]",
firstName: "John",
lastName: "Doe",
organization: {
orgID: "org-1",
orgName: "Organization 1",
status: "Active",
createdAt: "",
updateAt: "",
},
dataCommons: [],
studies: [],
IDP: "nih",
Expand All @@ -63,7 +56,7 @@ const mockCollaborators = [
{
collaboratorID: "user-2",
collaboratorName: "Jane Smith",
permission: "Can View",
permission: "Can Edit",
Organization: {
orgID: "org-2",
orgName: "Organization 2",
Expand Down Expand Up @@ -154,7 +147,7 @@ describe("CollaboratorsDialog Component", () => {
"Data SubmissionCollaborators" // line break between "Submission" and "Collaborators" text
);
expect(getByTestId("collaborators-dialog-description")).toHaveTextContent(
"Below is a list of collaborators who have been granted access to this data submission. Each collaborator can view or edit the submission based on the permissions assigned by the submission creator."
"Below is a list of collaborators who have been granted access to this data submission. Once added, each collaborator can contribute to the submission by uploading data, running validations, and submitting."
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/components/Collaborators/CollaboratorsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ const CollaboratorsDialog = ({ onClose, onSave, open, ...rest }: Props) => {
Collaborators
</StyledHeader>
<StyledDescription data-testid="collaborators-dialog-description">
Below is a list of collaborators who have been granted access to this data submission. Each
collaborator can view or edit the submission based on the permissions assigned by the
submission creator.
Below is a list of collaborators who have been granted access to this data submission. Once
added, each collaborator can contribute to the submission by uploading data, running
validations, and submitting.
</StyledDescription>

<form id="manage-collaborators-dialog-form" onSubmit={handleOnSave}>
Expand Down
121 changes: 12 additions & 109 deletions src/components/Collaborators/CollaboratorsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ const mockUser: User = {
email: "[email protected]",
firstName: "John",
lastName: "Doe",
organization: {
orgID: "org-1",
orgName: "Organization 1",
status: "Active",
createdAt: "",
updateAt: "",
},
dataCommons: [],
studies: [],
IDP: "nih",
Expand All @@ -65,32 +58,20 @@ const mockCollaborators: Collaborator[] = [
{
collaboratorID: "user-2",
collaboratorName: "Jane Smith",
permission: "Can View",
Organization: {
orgID: "org-2",
orgName: "Organization 2",
},
permission: "Can Edit",
},
];

const mockRemainingPotentialCollaborators: Collaborator[] = [
{
collaboratorID: "user-3",
collaboratorName: "Bob Johnson",
permission: "Can View",
Organization: {
orgID: "org-3",
orgName: "Organization 3",
},
permission: "Can Edit",
},
{
collaboratorID: "user-4",
collaboratorName: "Alice Williams",
permission: "Can View",
Organization: {
orgID: "org-4",
orgName: "Organization 4",
},
permission: "Can Edit",
},
];

Expand Down Expand Up @@ -196,8 +177,6 @@ describe("CollaboratorsTable Component", () => {
);

expect(getByTestId("header-collaborator")).toHaveTextContent("Collaborator");
expect(getByTestId("header-organization")).toHaveTextContent("Collaborator Organization");
expect(getByTestId("header-access")).toHaveTextContent("Access");
expect(getByTestId("header-remove")).toHaveTextContent("Remove");
});

Expand All @@ -215,12 +194,6 @@ describe("CollaboratorsTable Component", () => {
expect(collaboratorSelect).toBeInTheDocument();
expect(collaboratorSelect).toHaveValue("user-2");

const collaboratorOrg = getByTestId("collaborator-org-0");
expect(collaboratorOrg).toHaveTextContent("Organizati...");

const collaboratorPermissions = getByTestId("collaborator-permissions-0");
expect(collaboratorPermissions).toBeInTheDocument();

const removeButton = getByTestId("remove-collaborator-button-0");
expect(removeButton).toBeInTheDocument();
});
Expand Down Expand Up @@ -323,49 +296,10 @@ describe("CollaboratorsTable Component", () => {

expect(mockHandleUpdateCollaborator).toHaveBeenCalledWith(0, {
collaboratorID: "user-3",
permission: "Can View",
});
});

it("calls handleUpdateCollaborator when permission changes", () => {
const { getByTestId } = render(
<TestParent>
<CollaboratorsTable isEdit />
</TestParent>
);

const radioGroup = getByTestId("collaborator-permissions-0");

fireEvent.click(within(radioGroup).getByDisplayValue("Can Edit"));

expect(mockHandleUpdateCollaborator).toHaveBeenCalledWith(0, {
collaboratorID: "user-2",
permission: "Can Edit",
});
});

it("renders permission tooltips correctly", async () => {
const { getByText, getByTestId } = render(
<TestParent>
<CollaboratorsTable isEdit />
</TestParent>
);

const radioGroup = getByTestId("collaborator-permissions-0");

fireEvent.mouseOver(within(radioGroup).getByDisplayValue("Can View"));

await waitFor(() => {
expect(getByText(TOOLTIP_TEXT.COLLABORATORS_DIALOG.PERMISSIONS.CAN_VIEW)).toBeInTheDocument();
});

fireEvent.mouseOver(within(radioGroup).getByDisplayValue("Can Edit"));

await waitFor(() => {
expect(getByText(TOOLTIP_TEXT.COLLABORATORS_DIALOG.PERMISSIONS.CAN_EDIT)).toBeInTheDocument();
});
});

it("renders disabled add collaborator button tooltip correctly", async () => {
const { getByText, getByTestId } = render(
<TestParent>
Expand All @@ -387,11 +321,7 @@ describe("CollaboratorsTable Component", () => {
{
collaboratorID: "",
collaboratorName: "",
permission: "Can View",
Organization: {
orgID: "",
orgName: "",
},
permission: "Can Edit",
},
];

Expand Down Expand Up @@ -435,10 +365,6 @@ describe("CollaboratorsTable Component", () => {
collaboratorID: "user-5",
collaboratorName: "Emily Davis",
permission: "Can Edit",
Organization: {
orgID: "org-5",
orgName: "Organization 5",
},
},
];

Expand Down Expand Up @@ -470,11 +396,7 @@ describe("CollaboratorsTable Component", () => {
{
collaboratorID: "",
collaboratorName: "Jane Smith",
permission: "Can View",
Organization: {
orgID: "org-2",
orgName: "Organization 2",
},
permission: "Can Edit",
},
];

Expand Down Expand Up @@ -504,11 +426,7 @@ describe("CollaboratorsTable Component", () => {
{
collaboratorID: "user-2",
collaboratorName: null,
permission: "Can View",
Organization: {
orgID: "org-2",
orgName: "Organization 2",
},
permission: "Can Edit",
},
];

Expand All @@ -529,25 +447,20 @@ describe("CollaboratorsTable Component", () => {
);

const collaboratorSelect = getByTestId("collaborator-select-0");

expect(within(collaboratorSelect).getByTestId("truncated-text-label").textContent).toEqual(" ");
});

it("displays a space when collaboratorID is null", () => {
const mockCollaboratorsWithNullName = [
const mockCollaboratorsWithNullID = [
{
collaboratorID: null,
collaboratorName: "user-name",
permission: "Can View",
Organization: {
orgID: "org-2",
orgName: "Organization 2",
},
permission: "Can Edit",
},
];

mockUseCollaboratorsContext.mockReturnValue({
currentCollaborators: mockCollaboratorsWithNullName,
currentCollaborators: mockCollaboratorsWithNullID,
remainingPotentialCollaborators: mockRemainingPotentialCollaborators,
maxCollaborators: 5,
handleAddCollaborator: mockHandleAddCollaborator,
Expand All @@ -563,20 +476,15 @@ describe("CollaboratorsTable Component", () => {
);

const collaboratorSelect = getByTestId("collaborator-select-0-input");

expect(collaboratorSelect).toHaveValue("");
});

it("handles undefined collaborator permission by defaulting to empty string", () => {
it("handles undefined collaborator permission by defaulting to no selection (only 'Can Edit' is valid)", () => {
const mockCollaboratorsWithUndefinedPermission = [
{
collaboratorID: "user-2",
collaboratorName: "Jane Smith",
permission: undefined,
Organization: {
orgID: "org-2",
orgName: "Organization 2",
},
},
];

Expand All @@ -596,12 +504,7 @@ describe("CollaboratorsTable Component", () => {
</TestParent>
);

const radioGroup = getByTestId("collaborator-permissions-0");

const canViewRadio = within(radioGroup).getByDisplayValue("Can View") as HTMLInputElement;
const canEditRadio = within(radioGroup).getByDisplayValue("Can Edit") as HTMLInputElement;

expect(canViewRadio.checked).toBe(false);
expect(canEditRadio.checked).toBe(false);
const collaboratorSelect = getByTestId("collaborator-select-0-input");
expect(collaboratorSelect).toHaveValue("user-2");
});
});
Loading

0 comments on commit 9a68a63

Please sign in to comment.