Skip to content

Commit

Permalink
add user data for platformAdmin and plain user, create test for non p…
Browse files Browse the repository at this point in the history
…latfrom admin
  • Loading branch information
RODO94 committed Sep 16, 2024
1 parent 88e7dd1 commit 7d449a2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { vi } from "vitest";

import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { mockPlainUser, mockPlatformAdminUser } from "./mocks/mockUsers";

vi.mock(
"pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx",
Expand All @@ -16,13 +17,18 @@ vi.mock(

describe("when a user presses 'edit button'", () => {
beforeEach(async () => {
useStore.setState({ teamMembers: mockTeamMembersData });
useStore.setState({
teamMembers: mockTeamMembersData,
user: mockPlatformAdminUser,
});

const { user } = await setupTeamMembersScreen();

const teamEditorsTable = screen.getByTestId("team-editors");
const addEditorButton = await within(teamEditorsTable).findByTestId(
"edit-button-0",
);

user.click(addEditorButton);
// Start each test with an open modal
});
Expand All @@ -32,7 +38,7 @@ describe("when a user presses 'edit button'", () => {
const firstNameInput = await screen.findByLabelText("First name");
const lastNameInput = await screen.findByLabelText("Last name");
const emailInput = await screen.findByLabelText("Email address");

// 29 - 159
// Sorted based on first letter of first name Bill > Donella in Mocks
expect(firstNameInput).toHaveDisplayValue(mockTeamMembersData[1].firstName);
expect(lastNameInput).toHaveDisplayValue(mockTeamMembersData[1].lastName);
Expand Down Expand Up @@ -161,3 +167,21 @@ describe("when a user correctly updates an Editor", () => {
).toBeInTheDocument();
});
});

describe("when a user is not a platform admin", () => {
beforeEach(async () => {
useStore.setState({
teamMembers: mockTeamMembersData,
user: mockPlainUser,
});

await setupTeamMembersScreen();
});
it("does not show an edit button", async () => {
const teamEditorsTable = screen.getByTestId("team-editors");
const addEditorButton =
within(teamEditorsTable).queryByTestId("edit-button-0");

expect(addEditorButton).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { User } from "@opensystemslab/planx-core/types";

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

export const alreadyExistingUser: TeamMember = {
Expand All @@ -15,3 +17,39 @@ export const emptyTeamMemberObj: TeamMember = {
id: 3,
role: "teamEditor",
};

export const mockPlatformAdminUser: User = {
isPlatformAdmin: true,
firstName: "r",
lastName: "r",
email: "r",
id: 909,
teams: [
{
role: "teamEditor",
team: {
name: "planX",
slug: "planx",
id: 0,
},
},
],
};

export const mockPlainUser: User = {
isPlatformAdmin: false,
firstName: "r",
lastName: "r",
email: "r",
id: 909,
teams: [
{
role: "teamEditor",
team: {
name: "planX",
slug: "planx",
id: 0,
},
},
],
};

0 comments on commit 7d449a2

Please sign in to comment.