diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Team/components/MembersTable.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Team/components/MembersTable.tsx index cda4de0aad..45d32eed65 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Team/components/MembersTable.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Team/components/MembersTable.tsx @@ -148,18 +148,20 @@ export const MembersTable = ({ ))} {showAddMemberButton && ( - - - { - setInitialValues(undefined); - setShowAddModal(true); - }} - > - Add a new editor - - - + + + + { + setInitialValues(undefined); + setShowAddModal(true); + }} + > + Add a new editor + + + + )} diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.serverSide.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.serverSide.test.tsx index 22fd4e5db2..7d0fb98a28 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.serverSide.test.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.serverSide.test.tsx @@ -5,7 +5,7 @@ import { vi } from "vitest"; import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor"; import { mockTeamMembersData } from "./mocks/mockTeamMembersData"; -import { alreadyExistingUser } from "./mocks/mockUsers"; +import { alreadyExistingUser, mockPlatformAdminUser } from "./mocks/mockUsers"; let initialState: FullStore; vi.mock( @@ -22,6 +22,7 @@ describe("when a user fills in the 'add a new editor' form correctly but there i beforeEach(async () => { useStore.setState({ teamMembers: [...mockTeamMembersData, alreadyExistingUser], + user: mockPlatformAdminUser, }); const { user } = await setupTeamMembersScreen(); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.userAlreadyExists.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.userAlreadyExists.test.tsx index 11f53bc288..d2ac094305 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.userAlreadyExists.test.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.userAlreadyExists.test.tsx @@ -5,7 +5,7 @@ import { vi } from "vitest"; import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor"; import { mockTeamMembersData } from "./mocks/mockTeamMembersData"; -import { alreadyExistingUser } from "./mocks/mockUsers"; +import { alreadyExistingUser, mockPlatformAdminUser } from "./mocks/mockUsers"; vi.mock( "pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx", @@ -23,6 +23,7 @@ describe("when a user fills in the 'add a new editor' form correctly but the use beforeEach(async () => { useStore.setState({ teamMembers: [...mockTeamMembersData, alreadyExistingUser], + user: mockPlatformAdminUser, }); const { user } = await setupTeamMembersScreen(); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.noExistingMembers.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.noExistingMembers.test.tsx index c3f5e64a4d..59a9aff7f2 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.noExistingMembers.test.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.noExistingMembers.test.tsx @@ -3,6 +3,7 @@ import { useStore } from "pages/FlowEditor/lib/store"; import { TeamMember } from "../types"; import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; +import { mockPlatformAdminUser } from "./mocks/mockUsers"; const mockTeamMembersDataWithNoTeamEditors: TeamMember[] = [ { @@ -16,7 +17,10 @@ const mockTeamMembersDataWithNoTeamEditors: TeamMember[] = [ describe("when a user views the 'Team members' screen but there are no existing team editors listed", () => { beforeEach(async () => { - useStore.setState({ teamMembers: mockTeamMembersDataWithNoTeamEditors }); + useStore.setState({ + teamMembers: mockTeamMembersDataWithNoTeamEditors, + user: mockPlatformAdminUser, + }); const { getByText } = await setupTeamMembersScreen(); getByText("No members found"); }); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.test.tsx index c82b41cf71..cbf0765d4f 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.test.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.test.tsx @@ -11,7 +11,11 @@ import { EditorUpsertModal } from "../components/EditorUpsertModal"; import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor"; import { mockTeamMembersData } from "./mocks/mockTeamMembersData"; -import { emptyTeamMemberObj } from "./mocks/mockUsers"; +import { + emptyTeamMemberObj, + mockPlainUser, + mockPlatformAdminUser, +} from "./mocks/mockUsers"; vi.mock( "pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx", @@ -27,7 +31,11 @@ let initialState: FullStore; describe("when a user presses 'add a new editor'", () => { beforeEach(async () => { - useStore.setState({ teamMembers: mockTeamMembersData, teamSlug: "planx" }); + useStore.setState({ + teamMembers: mockTeamMembersData, + user: mockPlatformAdminUser, + teamSlug: "planx", + }); const { user } = await setupTeamMembersScreen(); const teamEditorsTable = screen.getByTestId("team-editors"); @@ -45,8 +53,13 @@ describe("when a user presses 'add a new editor'", () => { describe("when a user fills in the 'add a new editor' form correctly", () => { afterAll(() => useStore.setState(initialState)); + beforeEach(async () => { - useStore.setState({ teamMembers: mockTeamMembersData, teamSlug: "planx" }); + useStore.setState({ + teamMembers: mockTeamMembersData, + user: mockPlatformAdminUser, + teamSlug: "planx", + }); const { user } = await setupTeamMembersScreen(); await userTriesToAddNewEditor(user); }); @@ -97,6 +110,7 @@ describe("'add a new editor' button is hidden from Templates team", () => { beforeEach(async () => { useStore.setState({ teamMembers: mockTeamMembersData, + user: mockPlatformAdminUser, teamSlug: "templates", }); }); @@ -109,3 +123,21 @@ describe("'add a new editor' button is hidden from Templates team", () => { expect(addEditorButton).not.toBeInTheDocument(); }); }); + +describe("when a user is not a platform admin", () => { + beforeEach(async () => { + useStore.setState({ + teamMembers: mockTeamMembersData, + user: mockPlainUser, + teamSlug: "templates", + }); + }); + + it("hides the button from non-admin users", async () => { + const { user: _user } = await setupTeamMembersScreen(); + const teamEditorsTable = screen.getByTestId("team-editors"); + const addEditorButton = + within(teamEditorsTable).queryByText("Add a new editor"); + expect(addEditorButton).not.toBeInTheDocument(); + }); +}); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.updateEditor.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.updateEditor.test.tsx index 7527470705..77c05d3c5e 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.updateEditor.test.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.updateEditor.test.tsx @@ -192,6 +192,7 @@ describe("when a user is not a platform admin", () => { await setupTeamMembersScreen(); }); + it("does not show an edit button", async () => { const teamEditorsTable = screen.getByTestId("team-editors"); const addEditorButton =