A full-featured CRM built with React, shadcn/ui, and Supabase.
Use vitest-browser-react in integration tests
Anibal Svarcas9e8653ceaae3
diff --git a/package-lock.json b/package-lock.jsonindex 75da29d1..179a0167 100644--- a/package-lock.json+++ b/package-lock.json@@ -79,8 +79,6 @@"@inquirer/prompts": "^8.2.0","@storybook/react-vite": "^9.1.19","@testing-library/jest-dom": "^6.6.3",- "@testing-library/react": "^16.3.0",- "@testing-library/user-event": "^14.6.1","@types/dompurify": "^3.0.5","@types/faker": "^5.5.9","@types/jsonexport": "^3.0.5",@@ -8214,34 +8212,6 @@"yarn": ">=1"}},- "node_modules/@testing-library/react": {- "version": "16.3.2",- "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-16.3.2.tgz",- "integrity": "sha512-XU5/SytQM+ykqMnAnvB2umaJNIOsLF3PVv//1Ew4CTcpz0/BRyy/af40qqrt7SjKpDdT1saBMc42CUok5gaw+g==",- "dev": true,- "license": "MIT",- "dependencies": {- "@babel/runtime": "^7.12.5"- },- "engines": {- "node": ">=18"- },- "peerDependencies": {- "@testing-library/dom": "^10.0.0",- "@types/react": "^18.0.0 || ^19.0.0",- "@types/react-dom": "^18.0.0 || ^19.0.0",- "react": "^18.0.0 || ^19.0.0",- "react-dom": "^18.0.0 || ^19.0.0"- },- "peerDependenciesMeta": {- "@types/react": {- "optional": true- },- "@types/react-dom": {- "optional": true- }- }- },"node_modules/@testing-library/user-event": {"version": "14.6.1","resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.6.1.tgz",diff --git a/package.json b/package.jsonindex 8a9f8dd7..1ff0dbcf 100644--- a/package.json+++ b/package.json@@ -96,8 +96,6 @@"@eslint/js": "^9.22.0","@inquirer/prompts": "^8.2.0","@testing-library/jest-dom": "^6.6.3",- "@testing-library/react": "^16.3.0",- "@testing-library/user-event": "^14.6.1","@types/dompurify": "^3.0.5","@types/faker": "^5.5.9","@types/jsonexport": "^3.0.5",diff --git a/src/components/atomic-crm/contacts/ContactList.integration.test.tsx b/src/components/atomic-crm/contacts/ContactList.integration.test.tsxindex dc07cb9f..c28feab0 100644--- a/src/components/atomic-crm/contacts/ContactList.integration.test.tsx+++ b/src/components/atomic-crm/contacts/ContactList.integration.test.tsx@@ -1,6 +1,5 @@-import { render, screen, waitFor } from "@testing-library/react";-import userEvent from "@testing-library/user-event";import { describe, expect, it } from "vitest";+import { render } from "vitest-browser-react";import {buildContact,@@ -18,18 +17,18 @@ describe("Contact list integration", () => {db: createCrmDb(),});- render(+ const screen = await render(<CrmTestProvider resource="contacts" scenario={scenario}><DesktopContactListHarness /></CrmTestProvider>,);- expect(- await screen.findByRole("heading", { name: "No contacts found" }),- ).toBeInTheDocument();- expect(- screen.getByText("It seems your contact list is empty."),- ).toBeVisible();+ await expect+ .element(screen.getByRole("heading", { name: "No contacts found" }))+ .toBeInTheDocument();+ await expect+ .element(screen.getByText("It seems your contact list is empty."))+ .toBeVisible();});it("renders contacts in the desktop success state", async () => {@@ -54,17 +53,17 @@ describe("Contact list integration", () => {}),});- render(+ const screen = await render(<CrmTestProvider resource="contacts" scenario={scenario}><DesktopContactListHarness /></CrmTestProvider>,);- expect(await screen.findByText("Ada Lovelace")).toBeVisible();- expect(screen.getByText("Grace Hopper")).toBeVisible();- expect(- screen.queryByRole("heading", { name: "No contacts found" }),- ).toBeNull();+ await expect.element(screen.getByText("Ada Lovelace")).toBeVisible();+ await expect.element(screen.getByText("Grace Hopper")).toBeVisible();+ await expect+ .element(screen.getByRole("heading", { name: "No contacts found" }))+ .not.toBeInTheDocument();});it("renders a loading skeleton for the desktop list content", async () => {@@ -75,15 +74,15 @@ describe("Contact list integration", () => {getListDelays: { contacts: 5_000 },});- const { container } = render(+ const screen = await render(<CrmTestProvider resource="contacts" scenario={scenario}><DesktopContactListContentHarness /></CrmTestProvider>,);- await waitFor(() => {- expect(container.querySelector('[data-slot="skeleton"]')).not.toBeNull();- });+ await expect+ .poll(() => screen.container.querySelector('[data-slot="skeleton"]'))+ .not.toBeNull();});it("renders the mobile error state when loading contacts fails", async () => {@@ -94,18 +93,21 @@ describe("Contact list integration", () => {failGetListOnce: { contacts: "Error loading contacts" },});- render(+ const screen = await render(<CrmTestProvider resource="contacts" scenario={scenario}><MobileContactListContentHarness /></CrmTestProvider>,);- expect(await screen.findByText("Error loading contacts")).toBeVisible();- expect(screen.getByRole("button", { name: /retry/i })).toBeVisible();+ await expect+ .element(screen.getByText("Error loading contacts"))+ .toBeVisible();+ await expect+ .element(screen.getByRole("button", { name: /retry/i }))+ .toBeVisible();});it("retries successfully in the mobile error state", async () => {- const user = userEvent.setup();const scenario = createCrmScenario({db: createCrmDb({contacts: [@@ -120,15 +122,17 @@ describe("Contact list integration", () => {failGetListOnce: { contacts: "Error loading contacts" },});- render(+ const screen = await render(<CrmTestProvider resource="contacts" scenario={scenario}><MobileContactListContentHarness /></CrmTestProvider>,);- await user.click(await screen.findByRole("button", { name: /retry/i }));+ await screen.getByRole("button", { name: /retry/i }).click();- expect(await screen.findByText("Grace Hopper")).toBeVisible();- expect(screen.queryByText("Error loading contacts")).toBeNull();+ await expect.element(screen.getByText("Grace Hopper")).toBeVisible();+ await expect+ .element(screen.getByText("Error loading contacts"))+ .not.toBeInTheDocument();});});diff --git a/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsx b/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsxindex 85461c30..a58bd94e 100644--- a/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsx+++ b/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsx@@ -1,6 +1,5 @@-import { render, screen, waitFor, within } from "@testing-library/react";-import userEvent from "@testing-library/user-event";import { describe, expect, it } from "vitest";+import { render } from "vitest-browser-react";import {buildContact,@@ -42,53 +41,49 @@ describe("TaskCreateSheet integration", () => {] as any,}),});- const user = userEvent.setup();- render(+ const screen = await render(<CrmTestProvider scenario={scenario}><OpenTaskCreateSheetHarness /></CrmTestProvider>,);- await user.type(- await screen.findByLabelText(/description/i),- "Follow up about onboarding",- );+ await screen+ .getByLabelText(/description/i)+ .fill("Follow up about onboarding");- const [contactInput, typeInput] = await screen.findAllByRole("combobox");+ const [contactInput, typeInput] = screen.getByRole("combobox").all();- await user.click(contactInput);- await user.click(await screen.findByText("Grace Hopper"));+ await contactInput.click();+ await screen.getByText("Grace Hopper").click();- await user.click(typeInput);- const typeOptions = await screen.findByRole("listbox");- await user.click(within(typeOptions).getByText("Call"));+ await typeInput.click();+ const typeOptions = screen.getByRole("listbox");+ await typeOptions.getByText("Call").click();const dueDateInput = screen.getByLabelText(/due date/i);- await user.clear(dueDateInput);- await user.type(dueDateInput, "2026-03-06T12:30");+ await dueDateInput.clear();+ await dueDateInput.fill("2026-03-06T12:30");- await user.click(screen.getByRole("button", { name: /^save$/i }));+ await screen.getByRole("button", { name: /^save$/i }).click();- expect(await screen.findByText("Task added")).toBeInTheDocument();+ await expect.element(screen.getByText("Task added")).toBeInTheDocument();- await waitFor(() => {- expect(screen.queryByText("Create Task")).toBeNull();- });+ await expect+ .element(screen.getByText("Create Task"))+ .not.toBeInTheDocument();- await waitFor(() => {- return expect(- scenario.dataProvider- .getList("tasks", {- filter: {},- pagination: { page: 1, perPage: 10 },- sort: { field: "id", order: "ASC" },- })- .then(({ data }) =>- data.some((task) => task.text === "Follow up about onboarding"),- ),- ).resolves.toBe(true);- });+ await expect+ .poll(async () => {+ const { data } = await scenario.dataProvider.getList("tasks", {+ filter: {},+ pagination: { page: 1, perPage: 10 },+ sort: { field: "id", order: "ASC" },+ });++ return data.some((task) => task.text === "Follow up about onboarding");+ })+ .toBe(true);const tasks = await scenario.dataProvider.getList("tasks", {filter: {},diff --git a/src/test/setup.integration.ts b/src/test/setup.integration.tsindex e2621932..6c06312d 100644--- a/src/test/setup.integration.ts+++ b/src/test/setup.integration.ts@@ -1,7 +1 @@-import "@testing-library/jest-dom/vitest";-import { cleanup } from "@testing-library/react";-import { afterEach } from "vitest";--afterEach(() => {- cleanup();-});+import "vitest-browser-react";