Skip to content

Commit

Permalink
test: Update tests and file names
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 30, 2024
1 parent 9c5c17b commit e4422f9
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const AddNewEditorErrors = {
export const AddNewMemberErrors = {
USER_ALREADY_EXISTS: {
regex: /violates unique constraint "users_email_key"/i,
errorMessage: "User already exists",
},
};
export const isUserAlreadyExistsError = (error: string) =>
AddNewEditorErrors.USER_ALREADY_EXISTS.regex.test(error);
AddNewMemberErrors.USER_ALREADY_EXISTS.regex.test(error);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Yup from "yup";

export const upsertEditorSchema = Yup.object({
export const upsertMemberSchema = Yup.object({
firstName: Yup.string().required("Enter a first name"),
lastName: Yup.string().required("Enter a last name"),
email: Yup.string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { waitFor, within } from "@testing-library/react";
import { useStore } from "pages/FlowEditor/lib/store";
import { vi } from "vitest";

import { DEMO_TEAM_ID } from "../components/EditorUpsertModal";
import { DEMO_TEAM_ID } from "../components/UserUpsertModal";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { userTriesToAddNewMember } from "./helpers/userTriesToAddNewMember";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { mockPlatformAdminUser } from "./mocks/mockUsers";

Expand Down Expand Up @@ -34,9 +34,9 @@ describe("adding a new user to the Demo team", () => {
expect(currentUsers).toHaveLength(3);

const { user, getByTestId } = await setupTeamMembersScreen();
await userTriesToAddNewEditor(user);
await userTriesToAddNewMember(user);

const membersTable = getByTestId("members-table-add-editor");
const membersTable = getByTestId("members-table-add-member");

await waitFor(() => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FullStore, useStore } from "pages/FlowEditor/lib/store";
import { vi } from "vitest";

import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { userTriesToAddNewMember } from "./helpers/userTriesToAddNewMember";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { alreadyExistingUser, mockPlatformAdminUser } from "./mocks/mockUsers";

Expand All @@ -17,7 +17,7 @@ vi.mock(
}),
);

describe("when a user fills in the 'add a new editor' form correctly but there is a server-side error", () => {
describe("when a user fills in the 'add a new member' form correctly but there is a server-side error", () => {
afterAll(() => useStore.setState(initialState));
beforeEach(async () => {
useStore.setState({
Expand All @@ -26,7 +26,7 @@ describe("when a user fills in the 'add a new editor' form correctly but there i
});

const { user } = await setupTeamMembersScreen();
await userTriesToAddNewEditor(user);
await userTriesToAddNewMember(user);
});

it("shows an appropriate error message", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FullStore, useStore } from "pages/FlowEditor/lib/store";
import { vi } from "vitest";

import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { userTriesToAddNewMember } from "./helpers/userTriesToAddNewMember";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import { alreadyExistingUser, mockPlatformAdminUser } from "./mocks/mockUsers";

Expand All @@ -18,7 +18,7 @@ vi.mock(
);
let initialState: FullStore;

describe("when a user fills in the 'add a new editor' form correctly but the user already exists", () => {
describe("when a user fills in the 'add a new member' form correctly but the user already exists", () => {
afterAll(() => useStore.setState(initialState));
beforeEach(async () => {
useStore.setState({
Expand All @@ -27,7 +27,7 @@ describe("when a user fills in the 'add a new editor' form correctly but the use
});

const { user } = await setupTeamMembersScreen();
await userTriesToAddNewEditor(user);
await userTriesToAddNewMember(user);
});

it("shows an appropriate error message", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const mockTeamMembersDataWithNoTeamEditors: TeamMember[] = [
},
];

describe("when a user views the 'Team members' screen but there are no existing team editors listed", () => {
describe("when a user views the 'Team members' screen but there are no existing team members listed", () => {
beforeEach(async () => {
useStore.setState({
teamMembers: mockTeamMembersDataWithNoTeamEditors,
Expand All @@ -25,10 +25,10 @@ describe("when a user views the 'Team members' screen but there are no existing
getByText("No members found");
});

it("shows the 'add a new editor' button", async () => {
const teamEditorsTable = screen.getByTestId("team-editors");
it("shows the 'add a new member' button", async () => {
const teamMembersTable = screen.getByTestId("team-members");
expect(
await within(teamEditorsTable).findByText("Add a new editor"),
await within(teamMembersTable).findByText("Add a new member"),
).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { vi } from "vitest";
import { axe } from "vitest-axe";

import { setup } from "../../../../../testUtils";
import { EditorUpsertModal } from "../components/EditorUpsertModal";
import { UserUpsertModal } from "../components/UserUpsertModal";
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen";
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor";
import { userTriesToAddNewMember } from "./helpers/userTriesToAddNewMember";
import { mockTeamMembersData } from "./mocks/mockTeamMembersData";
import {
emptyTeamMemberObj,
Expand All @@ -29,7 +29,7 @@ vi.mock(

let initialState: FullStore;

describe("when a user presses 'add a new editor'", () => {
describe("when a user presses 'add a new member'", () => {
beforeEach(async () => {
useStore.setState({
teamMembers: mockTeamMembersData,
Expand All @@ -39,11 +39,11 @@ describe("when a user presses 'add a new editor'", () => {
});
const { user } = await setupTeamMembersScreen();

const teamEditorsTable = screen.getByTestId("team-editors");
const addEditorButton = await within(teamEditorsTable).findByText(
"Add a new editor",
const teamMembersTable = screen.getByTestId("team-members");
const addMemberButton = await within(teamMembersTable).findByText(
"Add a new member",
);
user.click(addEditorButton);
user.click(addMemberButton);
});

it("opens the modal and displays the input fields", async () => {
Expand All @@ -52,7 +52,7 @@ describe("when a user presses 'add a new editor'", () => {
});
});

describe("when a user fills in the 'add a new editor' form correctly", () => {
describe("when a user fills in the 'add a new member' form correctly", () => {
afterAll(() => useStore.setState(initialState));

beforeEach(async () => {
Expand All @@ -63,11 +63,11 @@ describe("when a user fills in the 'add a new editor' form correctly", () => {
teamId: 1,
});
const { user } = await setupTeamMembersScreen();
await userTriesToAddNewEditor(user);
await userTriesToAddNewMember(user);
});

it("adds the new user row to the Team Editors table", async () => {
const membersTable = screen.getByTestId("members-table-add-editor");
it("adds the new user row to the Team Members table", async () => {
const membersTable = screen.getByTestId("members-table-add-member");

await waitFor(() => {
expect(
Expand All @@ -89,7 +89,7 @@ describe("when a user fills in the 'add a new editor' form correctly", () => {
});
});

describe("when the addNewEditor modal is rendered", () => {
describe("when the addNewMember modal is rendered", () => {
beforeEach(async () => {
useStore.setState({
teamSlug: "planx",
Expand All @@ -100,7 +100,7 @@ describe("when the addNewEditor modal is rendered", () => {
it("should not have any accessibility issues", async () => {
const { container } = setup(
<DndProvider backend={HTML5Backend}>
<EditorUpsertModal
<UserUpsertModal
showModal={true}
setShowModal={() => {}}
initialValues={emptyTeamMemberObj}
Expand All @@ -115,7 +115,7 @@ describe("when the addNewEditor modal is rendered", () => {
});
});

describe("'add a new editor' button is hidden from Templates team", () => {
describe("'add a new member' button is hidden from Templates team", () => {
beforeEach(async () => {
useStore.setState({
teamMembers: mockTeamMembersData,
Expand All @@ -126,11 +126,11 @@ describe("'add a new editor' button is hidden from Templates team", () => {
});

it("hides the button on the Templates team", 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();
await setupTeamMembersScreen();
const teamMembers = screen.getByTestId("team-members");
const addMemberButton =
within(teamMembers).queryByText("Add a new member");
expect(addMemberButton).not.toBeInTheDocument();
});
});

Expand All @@ -145,10 +145,10 @@ describe("when a user is not a platform admin", () => {
});

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();
await setupTeamMembersScreen();
const teamMembersTable = screen.getByTestId("team-members");
const addMemberButton =
within(teamMembersTable).queryByText("Add a new member");
expect(addMemberButton).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe("when a user presses 'remove' button", () => {
});
const { user, container } = await setupTeamMembersScreen();

const teamEditorsTable = screen.getByTestId("team-editors");
const removeRowButton = await within(teamEditorsTable).findByTestId(
const teamMembersTable = screen.getByTestId("team-members");
const removeRowButton = await within(teamMembersTable).findByTestId(
"remove-button-3",
);
axeContainer = container;
Expand Down Expand Up @@ -79,10 +79,10 @@ describe("when a user clicks 'Remove user' button", () => {
});
const { user } = await setupTeamMembersScreen();

const teamEditorsTable = screen.getByTestId("team-editors");
const teamMembersTable = screen.getByTestId("team-members");

const removeRowButton =
within(teamEditorsTable).getByTestId("remove-button-3");
within(teamMembersTable).getByTestId("remove-button-3");

await user.click(removeRowButton);

Expand Down Expand Up @@ -127,9 +127,9 @@ describe("'remove' button is hidden from Templates team", () => {

it("hides the button on the Templates team", async () => {
const { user: _user } = await setupTeamMembersScreen();
const teamEditorsTable = screen.getByTestId("team-editors");
const teamMembersTable = screen.getByTestId("team-members");
const editButton =
within(teamEditorsTable).queryByTestId("remove-button-3");
within(teamMembersTable).queryByTestId("remove-button-3");
expect(editButton).not.toBeInTheDocument();
});
});
Expand All @@ -146,9 +146,9 @@ describe("when a user is not a platform admin", () => {
await setupTeamMembersScreen();
});
it("does not show a remove button", async () => {
const teamEditorsTable = screen.getByTestId("team-editors");
const teamMembersTable = screen.getByTestId("team-members");
const addEditorButton =
within(teamEditorsTable).queryByTestId("remove-button-0");
within(teamMembersTable).queryByTestId("remove-button-0");

expect(addEditorButton).not.toBeInTheDocument();
});
Expand Down
Loading

0 comments on commit e4422f9

Please sign in to comment.