A full-featured CRM built with React, shadcn/ui, and Supabase.
dismiss toast in test to avoid flakyness
ThieryMichela882e1314c17
diff --git a/e2e/fixtures.ts b/e2e/fixtures.tsindex c7fbdc5e..fecd8fbd 100644--- a/e2e/fixtures.ts+++ b/e2e/fixtures.ts@@ -1,4 +1,4 @@-import { test as base, expect } from "@playwright/test";+import { test as base, expect, type Page } from "@playwright/test";import { createClient } from "@supabase/supabase-js";const adminSupabase = createClient(@@ -193,7 +193,7 @@ async function createContact({return data;}-const getMenuMethod = ({ page }: { page: any; isMobile: boolean }) => ({+const getMenuMethod = ({ page }: { page: Page; isMobile: boolean }) => ({goToDashboard: async () => {await page.getByRole("link", { name: "Dashboard" }).click();await page.waitForLoadState("networkidle");@@ -204,6 +204,13 @@ const getMenuMethod = ({ page }: { page: any; isMobile: boolean }) => ({},});+const dismissToast = async (page: Page, content: string) => {+ await expect(page.getByText(content)).toBeVisible();+ await page.getByLabel("Close toast").click();+ // Since we are in optimistic UI, dismissing the toast trigger the request to the api linked to the toast message+ await page.waitForLoadState("networkidle");+};+export const test = base.extend<{resetDb: void;createUser: typeof createUser;@@ -212,6 +219,7 @@ export const test = base.extend<{createContact: typeof createContact;createNotes: typeof createNotes;menu: ReturnType<typeof getMenuMethod>;+ dismissToast: (content: string) => Promise<void>;}>({resetDb: [// The first argument to a Playwright fixture function must use object destructuring ({}) — _ is not allowed.@@ -246,6 +254,9 @@ export const test = base.extend<{menu: async ({ page, isMobile }, cb) => {await cb(getMenuMethod({ page, isMobile }));},+ dismissToast: async ({ page }, cb) => {+ await cb((content: string) => dismissToast(page, content));+ },});export { expect };diff --git a/e2e/onboarding.spec.ts b/e2e/onboarding.spec.tsindex 053b8482..9ba45c10 100644--- a/e2e/onboarding.spec.ts+++ b/e2e/onboarding.spec.ts@@ -1,6 +1,6 @@import { test, expect } from "./fixtures";-test("user onboarding", async ({ page, isMobile, menu }) => {+test("user onboarding", async ({ page, isMobile, menu, dismissToast }) => {await page.goto("http://localhost:5175/");// Expect a title "to contain" a substring.@@ -60,7 +60,7 @@ test("user onboarding", async ({ page, isMobile, menu }) => {await page.getByRole("button", { name: "Save" }).click();- await page.waitForLoadState("networkidle");+ await dismissToast("Element created");await expect(page.locator(isMobile ? "h2" : "h5")).toHaveText("Jane Smith");await expect(page.getByText("CEO at Smith Corp")).toBeVisible();@@ -79,9 +79,7 @@ test("user onboarding", async ({ page, isMobile, menu }) => {.getByRole("button", { name: isMobile ? "Save" : "Add this note" }).click();- await expect(page.getByText("Element created")).toBeVisible();- await expect(page.getByText("Element created")).toBeHidden();- await page.waitForLoadState("networkidle");+ await dismissToast("Note added");await expect(page.getByText(isMobile ? "Me" : "You added a note", { exact: false }),diff --git a/e2e/userAddingATask.spec.ts b/e2e/userAddingATask.spec.tsindex 8099aa9c..42d34284 100644--- a/e2e/userAddingATask.spec.ts+++ b/e2e/userAddingATask.spec.ts@@ -39,7 +39,7 @@ test.describe("user adding a task", () => {company_id: company.id,});});- test("user adding a task", async ({ page, isMobile, menu }) => {+ test("user adding a task", async ({ page, isMobile, menu, dismissToast }) => {await page.goto("http://localhost:5175/");await page.getByLabel("Email").fill("[email protected]");await page.getByLabel("Password").fill("password");@@ -67,13 +67,7 @@ test.describe("user adding a task", () => {await page.getByRole("button", { name: "Save" }).click();- await expect(- page.getByText(- isMobile- ? "Create Task for Jane Smith"- : "Create a new task for Jane Smith",- ),- ).not.toBeVisible();+ await dismissToast("Task added");if (isMobile) {await expect(page.getByText("1 task")).toBeVisible();