A full-featured CRM built with React, shadcn/ui, and Supabase.
Add CRM browser coverage and stories
Anibal Svarcas134e150294ec
diff --git a/registry.json b/registry.jsonindex eecc98bb..a6a0d834 100644--- a/registry.json+++ b/registry.json@@ -77,6 +77,10 @@"path": "src/components/atomic-crm/tasks/TaskCreateSheet.tsx","type": "registry:component"},+ {+ "path": "src/components/atomic-crm/tasks/TaskCreateSheet.stories.tsx",+ "type": "registry:component"+ },{"path": "src/components/atomic-crm/tasks/Task.tsx","type": "registry:component"@@ -673,6 +677,10 @@"path": "src/components/atomic-crm/contacts/ContactList.tsx","type": "registry:component"},+ {+ "path": "src/components/atomic-crm/contacts/ContactList.stories.tsx",+ "type": "registry:component"+ },{"path": "src/components/atomic-crm/contacts/ContactInputs.tsx","type": "registry:component"diff --git a/src/components/atomic-crm/contacts/ContactList.integration.test.tsx b/src/components/atomic-crm/contacts/ContactList.integration.test.tsxnew file mode 100644index 00000000..e9eb0c55--- /dev/null+++ b/src/components/atomic-crm/contacts/ContactList.integration.test.tsx@@ -0,0 +1,134 @@+import { render, screen, waitFor } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { describe, expect, it } from "vitest";++import {+ buildContact,+ createCrmDb,+ createCrmScenario,+ CrmTestProvider,+ DesktopContactListContentHarness,+ DesktopContactListHarness,+ MobileContactListContentHarness,+} from "@/test/browser/atomic-crm/crmUiHarness";++describe("Contact list integration", () => {+ it("renders the empty state in the desktop list", async () => {+ const scenario = createCrmScenario({+ db: createCrmDb(),+ });++ 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();+ });++ it("renders contacts in the desktop success state", async () => {+ const scenario = createCrmScenario({+ db: createCrmDb({+ contacts: [+ buildContact({+ first_name: "Ada",+ id: 1,+ last_name: "Lovelace",+ last_seen: "2025-01-05T10:00:00.000Z",+ title: "CTO",+ }),+ buildContact({+ first_name: "Grace",+ id: 2,+ last_name: "Hopper",+ last_seen: "2025-01-06T11:00:00.000Z",+ title: "Rear Admiral",+ }),+ ] as any,+ }),+ });++ 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();+ });++ it("renders a loading skeleton for the desktop list content", async () => {+ const scenario = createCrmScenario({+ db: createCrmDb({+ contacts: [buildContact()] as any,+ }),+ getListDelays: { contacts: 5_000 },+ });++ const { container } = render(+ <CrmTestProvider resource="contacts" scenario={scenario}>+ <DesktopContactListContentHarness />+ </CrmTestProvider>,+ );++ await waitFor(() => {+ expect(container.querySelector('[data-slot="skeleton"]')).not.toBeNull();+ });+ });++ it("renders the mobile error state when loading contacts fails", async () => {+ const scenario = createCrmScenario({+ db: createCrmDb({+ contacts: [buildContact()] as any,+ }),+ failGetListOnce: { contacts: "Error loading contacts" },+ });++ render(+ <CrmTestProvider resource="contacts" scenario={scenario}>+ <MobileContactListContentHarness />+ </CrmTestProvider>,+ );++ expect(await screen.findByText("Error loading contacts")).toBeVisible();+ expect(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: [+ buildContact({+ first_name: "Grace",+ id: 2,+ last_name: "Hopper",+ title: "Rear Admiral",+ }),+ ] as any,+ }),+ failGetListOnce: { contacts: "Error loading contacts" },+ });++ render(+ <CrmTestProvider resource="contacts" scenario={scenario}>+ <MobileContactListContentHarness />+ </CrmTestProvider>,+ );++ await user.click(+ await screen.findByRole("button", { name: /retry/i }),+ );++ expect(await screen.findByText("Grace Hopper")).toBeVisible();+ expect(screen.queryByText("Error loading contacts")).toBeNull();+ });+});diff --git a/src/components/atomic-crm/contacts/ContactList.stories.tsx b/src/components/atomic-crm/contacts/ContactList.stories.tsxnew file mode 100644index 00000000..240a2b7c--- /dev/null+++ b/src/components/atomic-crm/contacts/ContactList.stories.tsx@@ -0,0 +1,88 @@+import type { Meta, StoryObj } from "@storybook/react-vite";++import {+ buildContact,+ createCrmDb,+ CrmStoryProvider,+ DesktopContactListContentHarness,+ DesktopContactListHarness,+ MobileContactListContentHarness,+} from "@/test/browser/atomic-crm/crmUiHarness";++const meta = {+ title: "Atomic CRM/Contacts/Contact List",+ parameters: {+ layout: "fullscreen",+ },+} satisfies Meta;++export default meta;++type Story = StoryObj<typeof meta>;++const successContacts = [+ buildContact({+ first_name: "Ada",+ id: 1,+ last_name: "Lovelace",+ last_seen: "2025-01-05T10:00:00.000Z",+ title: "CTO",+ }),+ buildContact({+ first_name: "Grace",+ id: 2,+ last_name: "Hopper",+ last_seen: "2025-01-06T11:00:00.000Z",+ title: "Rear Admiral",+ }),+];++export const EmptyDesktop: Story = {+ render: () => (+ <CrmStoryProvider+ resource="contacts"+ scenarioOptions={{ db: createCrmDb() }}+ >+ <DesktopContactListHarness />+ </CrmStoryProvider>+ ),+};++export const SuccessDesktop: Story = {+ render: () => (+ <CrmStoryProvider+ resource="contacts"+ scenarioOptions={{ db: createCrmDb({ contacts: successContacts as any }) }}+ >+ <DesktopContactListHarness />+ </CrmStoryProvider>+ ),+};++export const LoadingContent: Story = {+ render: () => (+ <CrmStoryProvider+ resource="contacts"+ scenarioOptions={{+ db: createCrmDb({ contacts: successContacts as any }),+ getListDelays: { contacts: 10_000 },+ }}+ >+ <DesktopContactListContentHarness />+ </CrmStoryProvider>+ ),+};++export const ErrorMobile: Story = {+ render: () => (+ <CrmStoryProvider+ resource="contacts"+ scenarioOptions={{+ db: createCrmDb({ contacts: successContacts as any }),+ failGetListOnce: { contacts: "Error loading contacts" },+ }}+ >+ <MobileContactListContentHarness />+ </CrmStoryProvider>+ ),+};diff --git a/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsx b/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsxnew file mode 100644index 00000000..85461c30--- /dev/null+++ b/src/components/atomic-crm/tasks/TaskCreateSheet.integration.test.tsx@@ -0,0 +1,115 @@+import { render, screen, waitFor, within } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { describe, expect, it } from "vitest";++import {+ buildContact,+ createCrmDb,+ createCrmScenario,+ CrmTestProvider,+ OpenTaskCreateSheetHarness,+} from "@/test/browser/atomic-crm/crmUiHarness";++describe("TaskCreateSheet integration", () => {+ it("creates a task for a selected contact and updates last_seen", async () => {+ const originalLastSeen = "2025-01-02T10:00:00.000Z";+ const scenario = createCrmScenario({+ db: createCrmDb({+ contacts: [+ buildContact({+ first_name: "Ada",+ id: 1,+ last_name: "Lovelace",+ last_seen: "2025-01-01T10:00:00.000Z",+ nb_tasks: 1,+ }),+ buildContact({+ first_name: "Grace",+ id: 2,+ last_name: "Hopper",+ last_seen: originalLastSeen,+ }),+ ] as any,+ tasks: [+ {+ contact_id: 1,+ due_date: "2025-01-03T12:00:00.000Z",+ id: 1,+ sales_id: 0,+ text: "Existing seeded task",+ type: "email",+ },+ ] as any,+ }),+ });+ const user = userEvent.setup();++ render(+ <CrmTestProvider scenario={scenario}>+ <OpenTaskCreateSheetHarness />+ </CrmTestProvider>,+ );++ await user.type(+ await screen.findByLabelText(/description/i),+ "Follow up about onboarding",+ );++ const [contactInput, typeInput] = await screen.findAllByRole("combobox");++ await user.click(contactInput);+ await user.click(await screen.findByText("Grace Hopper"));++ await user.click(typeInput);+ const typeOptions = await screen.findByRole("listbox");+ await user.click(within(typeOptions).getByText("Call"));++ const dueDateInput = screen.getByLabelText(/due date/i);+ await user.clear(dueDateInput);+ await user.type(dueDateInput, "2026-03-06T12:30");++ await user.click(screen.getByRole("button", { name: /^save$/i }));++ expect(await screen.findByText("Task added")).toBeInTheDocument();++ await waitFor(() => {+ expect(screen.queryByText("Create Task")).toBeNull();+ });++ 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);+ });++ const tasks = await scenario.dataProvider.getList("tasks", {+ filter: {},+ pagination: { page: 1, perPage: 10 },+ sort: { field: "id", order: "ASC" },+ });+ const createdTask = tasks.data.find(+ (task) => task.text === "Follow up about onboarding",+ );++ expect(createdTask).toMatchObject({+ contact_id: 2,+ text: "Follow up about onboarding",+ type: "call",+ });+ expect(tasks.data).toHaveLength(2);++ const updatedContact = await scenario.dataProvider.getOne("contacts", {+ id: 2,+ });+ expect(updatedContact.data.last_seen).not.toBe(originalLastSeen);+ expect(updatedContact.data.nb_tasks).toBe(1);+ });+});diff --git a/src/components/atomic-crm/tasks/TaskCreateSheet.stories.tsx b/src/components/atomic-crm/tasks/TaskCreateSheet.stories.tsxnew file mode 100644index 00000000..4c5c9704--- /dev/null+++ b/src/components/atomic-crm/tasks/TaskCreateSheet.stories.tsx@@ -0,0 +1,44 @@+import type { Meta, StoryObj } from "@storybook/react-vite";++import {+ buildContact,+ createCrmDb,+ CrmStoryProvider,+ OpenTaskCreateSheetHarness,+} from "@/test/browser/atomic-crm/crmUiHarness";++const meta = {+ title: "Atomic CRM/Tasks/Task Create Sheet",+ parameters: {+ layout: "fullscreen",+ },+} satisfies Meta;++export default meta;++type Story = StoryObj<typeof meta>;++export const GlobalTaskCreateOpen: Story = {+ render: () => (+ <CrmStoryProvider+ scenarioOptions={{+ db: createCrmDb({+ contacts: [+ buildContact({+ first_name: "Ada",+ id: 1,+ last_name: "Lovelace",+ }),+ buildContact({+ first_name: "Grace",+ id: 2,+ last_name: "Hopper",+ }),+ ] as any,+ }),+ }}+ >+ <OpenTaskCreateSheetHarness />+ </CrmStoryProvider>+ ),+};