Skip to content

Commit

Permalink
Fix click issue by mocking platformAdmin user
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion committed Jan 18, 2025
1 parent 119d35b commit e7ce8a6
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { screen, waitFor } from "@testing-library/react";
// eslint-disable-next-line no-restricted-imports
import userEvent, {
PointerEventsCheckLevel,
} from "@testing-library/user-event";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { setup } from "testUtils";

import { ChecklistEditor } from "./Editor";

const { getState } = useStore;

describe("Checklist editor component", () => {
beforeEach(() => {
getState().setUser({
id: 1,
firstName: "Editor",
lastName: "Test",
isPlatformAdmin: true,
email: "test@test.com",
teams: [],
jwt: "x.y.z",
});
});

it("renders without error", () => {
setup(
<DndProvider backend={HTML5Backend}>
Expand All @@ -36,28 +48,18 @@ describe("Checklist editor component", () => {
expect(groupedOptionsEditor).toBeInTheDocument();
});

it.todo(
"displays the options editor when the 'add new option' button is clicked",
async () => {
setup(
<DndProvider backend={HTML5Backend}>
<ChecklistEditor text={""} />
</DndProvider>,
);
it("displays the options editor when the 'add new option' button is clicked", async () => {
const { user } = setup(
<DndProvider backend={HTML5Backend}>
<ChecklistEditor text={""} />
</DndProvider>,
);

await waitFor(() =>
userEvent.click(
screen.getByRole("button", { name: /add new option/i }),
{
pointerEventsCheck: PointerEventsCheckLevel.Never,
},
),
);
await user.click(screen.getByRole("button", { name: /add new option/i }));

const optionsEditor = await screen.findByPlaceholderText("Option");
expect(optionsEditor).toBeInTheDocument();
},
);
const optionsEditor = await screen.findByPlaceholderText("Option");
expect(optionsEditor).toBeInTheDocument();
});

it.todo("adds a new section when the 'add new group' button is clicked");

Expand Down

0 comments on commit e7ce8a6

Please sign in to comment.