From ea2449c25deebfa108d9565e3cde59820c5eeab7 Mon Sep 17 00:00:00 2001 From: Ayobami Akingbade Date: Tue, 19 Dec 2023 16:37:42 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test(toast):=20fix=20more=20toas?= =?UTF-8?q?t=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/_/utiis/getTableRows.ts | 2 +- src/__tests__/admin/[entity]/config/form.spec.tsx | 14 +++++++++++--- src/__tests__/admin/settings/theme.spec.tsx | 11 +++++++++-- .../[dashboardId]/widget/[widgetId]/index.spec.tsx | 10 ++++++---- .../dashboard/[dashboardId]/widget/create.spec.tsx | 10 ++++++---- .../integrations/variables__constants.spec.tsx | 12 ++++-------- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/__tests__/_/utiis/getTableRows.ts b/src/__tests__/_/utiis/getTableRows.ts index 5d00ebcff..638c3643b 100644 --- a/src/__tests__/_/utiis/getTableRows.ts +++ b/src/__tests__/_/utiis/getTableRows.ts @@ -3,5 +3,5 @@ import { within } from "@testing-library/react"; export const getTableRows = async (widget: HTMLElement) => { const allRoles = await within(widget).findAllByRole("row"); - return allRoles.map((row) => row.textContent); + return allRoles.map((row) => row.textContent.trim()); }; diff --git a/src/__tests__/admin/[entity]/config/form.spec.tsx b/src/__tests__/admin/[entity]/config/form.spec.tsx index 4a3f157bc..bde49b673 100644 --- a/src/__tests__/admin/[entity]/config/form.spec.tsx +++ b/src/__tests__/admin/[entity]/config/form.spec.tsx @@ -69,7 +69,7 @@ describe("pages/admin/[entity]/config/form", () => { within(currentTab).getByRole("button", { name: "Save Form Scripts" }) ); - expect((await screen.findAllByRole("status"))[0]).toHaveTextContent( + expect(await screen.findByRole("status")).toHaveTextContent( "Form Scripts Saved Successfully" ); }); @@ -106,11 +106,15 @@ describe("pages/admin/[entity]/config/form", () => { "Updated" ); + await userEvent.click( + screen.getByRole("button", { name: "Close Toast" }) + ); + await userEvent.click( within(currentTab).getByRole("button", { name: "Save Form Scripts" }) ); - expect((await screen.findAllByRole("status"))[0]).toHaveTextContent( + expect(await screen.findByRole("status")).toHaveTextContent( "Expression: •JS-Error: SyntaxError: Unexpected identifier" ); }); @@ -144,11 +148,15 @@ describe("pages/admin/[entity]/config/form", () => { await userEvent.clear(within(currentTab).getByLabelText("Script")); + await userEvent.click( + screen.getByRole("button", { name: "Close Toast" }) + ); + await userEvent.click( within(currentTab).getByRole("button", { name: "Save Form Scripts" }) ); - expect((await screen.findAllByRole("status"))[0]).toHaveTextContent( + expect(await screen.findByRole("status")).toHaveTextContent( "Form Scripts Saved Successfully" ); }); diff --git a/src/__tests__/admin/settings/theme.spec.tsx b/src/__tests__/admin/settings/theme.spec.tsx index ea6238e97..2f060be63 100644 --- a/src/__tests__/admin/settings/theme.spec.tsx +++ b/src/__tests__/admin/settings/theme.spec.tsx @@ -90,15 +90,22 @@ describe("pages/admin/settings/theme", () => { target: { value: "#654321" }, }); + await userEvent.click( + screen.getAllByRole("button", { name: "Close Toast" })[0] + ); + await userEvent.click( + screen.getAllByRole("button", { name: "Close Toast" })[1] + ); + await userEvent.click( screen.getByRole("button", { name: "Save Theme Settings" }) ); - expect((await screen.findAllByRole("status"))[2]).toHaveTextContent( + expect((await screen.findAllByRole("status"))[0]).toHaveTextContent( "Theme Settings Saved Successfully" ); - expect((await screen.findAllByRole("status"))[3]).toHaveTextContent( + expect((await screen.findAllByRole("status"))[1]).toHaveTextContent( "Theme Preference Saved Successfully" ); }); diff --git a/src/__tests__/dashboard/[dashboardId]/widget/[widgetId]/index.spec.tsx b/src/__tests__/dashboard/[dashboardId]/widget/[widgetId]/index.spec.tsx index 3c33eff2f..2f40449f6 100644 --- a/src/__tests__/dashboard/[dashboardId]/widget/[widgetId]/index.spec.tsx +++ b/src/__tests__/dashboard/[dashboardId]/widget/[widgetId]/index.spec.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { render, screen, waitFor } from "@testing-library/react"; +import { render, screen } from "@testing-library/react"; import { ApplicationRoot } from "frontend/components/ApplicationRoot"; import UpdateDashboardWidget from "pages/dashboard/[dashboardId]/widget/[widgetId]/index"; @@ -110,9 +110,11 @@ describe("pages/dashboard/[dashboardId]/widget/[widgetId]/index", () => { screen.getByRole("button", { name: "Update Dashboard Widget" }) ); - await waitFor(async () => { - expect(await screen.findAllByRole("status")).toHaveLength(2); - }); + await userEvent.click(screen.getByRole("button", { name: "Close Toast" })); + + expect(await screen.findByRole("status")).toHaveTextContent( + "Dashboard Widget Updated Successfully" + ); }); it("should render error when widget is not present", async () => { diff --git a/src/__tests__/dashboard/[dashboardId]/widget/create.spec.tsx b/src/__tests__/dashboard/[dashboardId]/widget/create.spec.tsx index e29966605..e21ff395b 100644 --- a/src/__tests__/dashboard/[dashboardId]/widget/create.spec.tsx +++ b/src/__tests__/dashboard/[dashboardId]/widget/create.spec.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { render, screen, waitFor } from "@testing-library/react"; +import { render, screen } from "@testing-library/react"; import { ApplicationRoot } from "frontend/components/ApplicationRoot"; import CreateDashboardWidget from "pages/dashboard/[dashboardId]/widget/create"; @@ -110,12 +110,14 @@ describe("pages/dashboard/[dashboardId]/widget/create", () => { expect(screen.queryByLabelText("Color")).not.toBeInTheDocument(); expect(screen.queryByLabelText("Icon")).not.toBeInTheDocument(); + await userEvent.click(screen.getByRole("button", { name: "Close Toast" })); + await userEvent.click( screen.getByRole("button", { name: "Create Dashboard Widget" }) ); - await waitFor(async () => { - expect(await screen.findAllByRole("status")).toHaveLength(2); - }); + expect(await screen.findByRole("status")).toHaveTextContent( + "Dashboard Widget Created Successfully" + ); }); }); diff --git a/src/__tests__/integrations/variables__constants.spec.tsx b/src/__tests__/integrations/variables__constants.spec.tsx index d2193f046..037a69b50 100644 --- a/src/__tests__/integrations/variables__constants.spec.tsx +++ b/src/__tests__/integrations/variables__constants.spec.tsx @@ -107,10 +107,6 @@ describe("pages/integrations/variables => constants", () => { ); - await userEvent.click( - screen.getByRole("button", { name: "Close Toast" }) - ); - const table = screen.getByRole("table"); const tableRows = await within(table).findAllByRole("row"); @@ -163,16 +159,16 @@ describe("pages/integrations/variables => constants", () => { ); - await userEvent.click( - screen.getByRole("button", { name: "Close Toast" }) - ); - const table = screen.getByRole("table"); const tableRows = await within(table).findAllByRole("row"); expect(tableRows).toHaveLength(5); + await userEvent.click( + screen.getByRole("button", { name: "Close Toast" }) + ); + await userEvent.click( within(tableRows[2]).getByRole("button", { name: "Delete Button",