Skip to content

Commit

Permalink
remove second firEvent in favour of userEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Aug 20, 2024
1 parent 50e9ccb commit cdd2315
Showing 1 changed file with 6 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useStore } from "pages/FlowEditor/lib/store";
import setupServiceSettingsScreen, {
mockWindowLocationObject,
} from "./helpers/setupServiceSettingsScreen";
import { fireEvent, screen } from "@testing-library/react";
import { screen } from "@testing-library/react";

const { getState, setState } = useStore;

Expand Down Expand Up @@ -96,61 +96,30 @@ describe("A team with a subdomain has an online, published service. ", () => {
jest
.spyOn(navigator.clipboard, "writeText")
.mockImplementation(() => Promise.resolve());

// render the <ServiceSettings/> comp
const user = await setupServiceSettingsScreen();
});

it("has a public link with the subdomain url in an <a> tag", async () => {
// render the <ServiceSettings/> comp
const { flowSlug, teamDomain } = getState();

await setupServiceSettingsScreen();
await activeLinkCheck(`https://${teamDomain}/${flowSlug}`);
});
it("has an enabled copy button", async () => {
// render the <ServiceSettings/> comp
await setupServiceSettingsScreen();
enabledCopyCheck();
});
it("can be copied to the clipboard", async () => {
const copyButton = screen.getByRole("button", { name: `copy` });

fireEvent.click(copyButton);

const { flowSlug, teamDomain } = getState();

expect(navigator.clipboard.writeText).toBeCalledWith(
`https://${teamDomain}/${flowSlug}`
);
});
});

describe("An active link is", () => {
beforeEach(async () => {
// setup state values that <ServiceSettings/> depends on
setState({
flowSettings: {},
flowStatus: "online",
teamDomain: "mockedteamdomain.com",
teamName: "mockTeam",
isFlowPublished: true,
flowSlug: "mock-planning-permish",
});

// render the <ServiceSettings/> comp
await setupServiceSettingsScreen();

jest
.spyOn(navigator.clipboard, "writeText")
.mockImplementation(() => Promise.resolve());
});
const user = await setupServiceSettingsScreen();

it("copied to the clipboard", async () => {
const copyButton = screen.getByRole("button", { name: `copy` });

fireEvent.click(copyButton);

const { flowSlug, teamDomain } = getState();
user.click(copyButton);

expect(await screen.findByText("copied")).toBeVisible();
expect(navigator.clipboard.writeText).toBeCalledWith(
`https://${teamDomain}/${flowSlug}`
);
Expand Down

0 comments on commit cdd2315

Please sign in to comment.