Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

add menu fixtures to reuse navigation logic

ThieryMichel2a821af48bac
diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts
index a0d6b4f2..6464c872 100644
--- a/e2e/fixtures.ts
+++ b/e2e/fixtures.ts
@@ -187,6 +187,25 @@ async function createContact({
return data;
}
+const getMenuMethod = ({
+ page,
+ isMobile,
+}: {
+ page: any;
+ isMobile: boolean;
+}) => ({
+ goToDashboard: async () => {
+ await page
+ .getByRole("link", { name: isMobile ? "Home" : "Dashboard" })
+ .click();
+ await page.waitForLoadState("networkidle");
+ },
+ goToContacts: async () => {
+ await page.getByRole("link", { name: "Contacts" }).click();
+ await page.waitForLoadState("networkidle");
+ },
+});
+
export const test = base.extend<{
resetDb: void;
createUser: typeof createUser;
@@ -194,6 +213,7 @@ export const test = base.extend<{
createCompany: typeof createCompany;
createContact: typeof createContact;
createNotes: typeof createNotes;
+ menu: ReturnType<typeof getMenuMethod>;
}>({
resetDb: [
// The first argument to a Playwright fixture function must use object destructuring ({}) — _ is not allowed.
@@ -225,6 +245,9 @@ export const test = base.extend<{
createNotes: async ({}, cb) => {
await cb(createNotes);
},
+ menu: async ({ page, isMobile }, cb) => {
+ await cb(getMenuMethod({ page, isMobile }));
+ },
});
export { expect };
diff --git a/e2e/onboarding.spec.ts b/e2e/onboarding.spec.ts
index 40a6978b..dce3932f 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 }) => {
+test("user onboarding", async ({ page, isMobile, menu }) => {
await page.goto("http://localhost:5175/");
// Expect a title "to contain" a substring.
@@ -65,9 +65,7 @@ test("user onboarding", async ({ page, isMobile }) => {
await expect(page.locator(isMobile ? "h2" : "h5")).toHaveText("Jane Smith");
await expect(page.getByText("CEO at Smith Corp")).toBeVisible();
- await page
- .getByRole("link", { name: isMobile ? "Home" : "Dashboard" })
- .click();
+ await menu.goToDashboard();
await page.waitForLoadState("networkidle");
await expect(page.getByText("2/3 done")).toBeVisible();
@@ -89,9 +87,7 @@ test("user onboarding", async ({ page, isMobile }) => {
).toBeVisible();
await expect(page.getByText("This is a note about Jane.")).toBeVisible();
- await page
- .getByRole("link", { name: isMobile ? "Home" : "Dashboard" })
- .click();
+ await menu.goToDashboard();
await page.waitForLoadState("networkidle");
diff --git a/e2e/userAddingATask.spec.ts b/e2e/userAddingATask.spec.ts
index aecf9863..74ec7081 100644
--- a/e2e/userAddingATask.spec.ts
+++ b/e2e/userAddingATask.spec.ts
@@ -38,7 +38,7 @@ test.describe("user adding a task", () => {
company_id: company.id,
});
});
- test("user adding a task", async ({ page, isMobile }) => {
+ test("user adding a task", async ({ page, isMobile, menu }) => {
await page.goto("http://localhost:5175/");
await page.getByLabel("Email").fill("[email protected]");
await page.getByLabel("Password").fill("password");
@@ -47,7 +47,7 @@ test.describe("user adding a task", () => {
await expect(page).toHaveTitle(/Atomic CRM/);
await expect(page.getByText("Latest Activity")).toBeVisible();
- await page.getByRole("link", { name: "Contacts" }).click();
+ await menu.goToContacts();
await page.waitForLoadState("networkidle");
await page.getByText("Jane Smith").click();
@@ -86,7 +86,7 @@ test.describe("user adding a task", () => {
await expect(page.getByText("Tasks").locator("..")).toHaveText(
/Follow up with Jane/,
);
- await page.getByRole("link", { name: "Dashboard" }).click();
+ await menu.goToDashboard();
await expect(page.getByText("Upcoming Tasks")).toBeVisible();
await expect(