Skip to content

Commit

Permalink
🧪 test(toast): fix more toast tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Dec 19, 2023
1 parent d775ccd commit ea2449c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/_/utiis/getTableRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
14 changes: 11 additions & 3 deletions src/__tests__/admin/[entity]/config/form.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
Expand Down Expand Up @@ -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"
);
});
Expand Down Expand Up @@ -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"
);
});
Expand Down
11 changes: 9 additions & 2 deletions src/__tests__/admin/settings/theme.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 () => {
Expand Down
10 changes: 6 additions & 4 deletions src/__tests__/dashboard/[dashboardId]/widget/create.spec.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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"
);
});
});
12 changes: 4 additions & 8 deletions src/__tests__/integrations/variables__constants.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ describe("pages/integrations/variables => constants", () => {
</ApplicationRoot>
);

await userEvent.click(
screen.getByRole("button", { name: "Close Toast" })
);

const table = screen.getByRole("table");

const tableRows = await within(table).findAllByRole("row");
Expand Down Expand Up @@ -163,16 +159,16 @@ describe("pages/integrations/variables => constants", () => {
</ApplicationRoot>
);

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",
Expand Down

0 comments on commit ea2449c

Please sign in to comment.