From cdd2315068278c71fd5fdd21fce42bbeb912504c Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 20 Aug 2024 13:22:45 +0100 Subject: [PATCH] remove second firEvent in favour of userEvent --- .../ServiceSettings.PublicLinks.test.tsx | 43 +++---------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/tests/ServiceSettings.PublicLinks.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/tests/ServiceSettings.PublicLinks.test.tsx index 9acc653696..8ed977efd4 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/tests/ServiceSettings.PublicLinks.test.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/tests/ServiceSettings.PublicLinks.test.tsx @@ -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; @@ -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 comp - const user = await setupServiceSettingsScreen(); }); it("has a public link with the subdomain url in an tag", async () => { // render the comp const { flowSlug, teamDomain } = getState(); + await setupServiceSettingsScreen(); await activeLinkCheck(`https://${teamDomain}/${flowSlug}`); }); it("has an enabled copy button", async () => { // render the 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 depends on - setState({ - flowSettings: {}, - flowStatus: "online", - teamDomain: "mockedteamdomain.com", - teamName: "mockTeam", - isFlowPublished: true, - flowSlug: "mock-planning-permish", - }); - // render the 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}` );