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: handle no existing team members case when adding a new editor #3608

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,64 @@ export const MembersTable = ({

if (members.length === 0) {
return (
<Table>
<TableHead>
<TableRow>
<TableCell>
<strong>No members found</strong>
</TableCell>
</TableRow>
</TableHead>
</Table>
<>
<Table>
<TableHead>
<TableRow>
<TableCell>
<strong>No members found</strong>
</TableCell>
</TableRow>
</TableHead>
{showAddMemberButton && (
<TableRow>
<TableCell colSpan={3}>
<AddButton onClick={() => setShowModal(true)}>
Add a new editor
</AddButton>
</TableCell>
</TableRow>
)}
</Table>
{showAddMemberButton && (
<Snackbar
open={showSuccessToast}
autoHideDuration={6000}
onClose={handleCloseSuccessToast}
>
<Alert
onClose={handleCloseSuccessToast}
severity="success"
sx={{ width: "100%" }}
>
Successfully added a user
</Alert>
</Snackbar>
)}
{showAddMemberButton && (
<Snackbar
open={showErrorToast}
autoHideDuration={6000}
onClose={handleCloseErrorToast}
>
<Alert
onClose={handleCloseErrorToast}
severity="error"
sx={{ width: "100%" }}
>
Failed to add new user, please try again
</Alert>
</Snackbar>
Comment on lines +78 to +106
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unwieldy, should be removed in upcoming useToast PR

)}
{showModal && (
<AddNewEditorModal
setShowSuccessToast={setShowSuccessToast}
setShowErrorToast={setShowErrorToast}
showModal={showModal}
setShowModal={setShowModal}
/>
)}
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { screen, within } from "@testing-library/react";
import { useStore } from "pages/FlowEditor/lib/store";

import { TeamMember } from "../types";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";

const mockTeamMembersDataWithNoTeamEditors: TeamMember[] = [
{
firstName: "Donella",
lastName: "Meadows",
email: "[email protected]",
id: 1,
role: "platformAdmin",
},
];

describe("when a user views the 'Team members' screen but there are no existing team editors listed", () => {
beforeEach(async () => {
useStore.setState({ teamMembers: mockTeamMembersDataWithNoTeamEditors });
const { getByText } = await setupTeamMembersScreen();
getByText("No members found");
});

it("shows the 'add a new editor' button", async () => {
const teamEditorsTable = screen.getByTestId("team-editors");
expect(
await within(teamEditorsTable).findByText("Add a new editor"),
).toBeVisible();
});
});
Loading