Skip to content

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

Merge branch 'main' into test-harness

fzaninotto7b3e60bf817d
diff --cc src/components/atomic-crm/contacts/ContactList.stories.tsx
index d898e894,9eb45040..45345c21
--- a/src/components/atomic-crm/contacts/ContactList.stories.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.stories.tsx
@@@ -31,52 -37,109 +31,78 @@@ const successContacts =
}),
];
-const bulkTagContacts = [
- buildContact({
- first_name: "Ada",
- id: 1,
- last_name: "Lovelace",
- tags: [1],
- }),
- buildContact({
- first_name: "Grace",
- id: 2,
- last_name: "Hopper",
- tags: [],
- }),
-];
-
-const bulkCreateContacts = Array.from({ length: 30 }, (_, index) =>
- buildContact({
- first_name: `Contact${index + 1}`,
- id: index + 1,
- last_name: "Tester",
- tags: [],
- }),
+export const DesktopEmpty = () => (
+ <StoryWrapper>
+ <ResourceContextProvider value="contacts">
+ <ContactList />
+ </ResourceContextProvider>
+ </StoryWrapper>
);
-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 DesktopSuccess = () => (
+ <StoryWrapper data={{ contacts: successContacts }}>
+ <ResourceContextProvider value="contacts">
+ <ContactList />
+ </ResourceContextProvider>
+ </StoryWrapper>
+);
-export const LoadingContent: Story = {
- render: () => (
- <CrmStoryProvider
- resource="contacts"
- scenarioOptions={{
- db: createCrmDb({ contacts: successContacts as any }),
- getListDelays: { contacts: 10_000 },
- }}
- >
- <DesktopContactListContentHarness />
- </CrmStoryProvider>
- ),
-};
+export const DesktopLoading = () => (
+ <StoryWrapper
+ dataProvider={{
+ getList: async (resource) => {
+ if (resource === "contacts") {
+ await new Promise(() => {});
+ }
+ return { data: [], total: 0 };
+ },
+ }}
+ >
+ <ResourceContextProvider value="contacts">
+ <ContactList />
+ </ResourceContextProvider>
+ </StoryWrapper>
+);
-export const ErrorMobile: Story = {
- render: () => (
- <CrmStoryProvider
- resource="contacts"
- scenarioOptions={{
- db: createCrmDb({ contacts: successContacts as any }),
- failGetListOnce: { contacts: "Error loading contacts" },
- }}
- >
- <MobileContactListContentHarness />
- </CrmStoryProvider>
- ),
-};
+export const DesktopError = () => (
+ <StoryWrapper
+ dataProvider={{
+ getList: async (resource) => {
+ if (resource === "contacts") {
+ throw new Error("Error loading contacts");
+ }
+ return { data: [], total: 0 };
+ },
+ }}
+ >
+ <ResourceContextProvider value="contacts">
+ <ContactList />
+ </ResourceContextProvider>
+ </StoryWrapper>
+);
+
-export const BulkTagDesktop: Story = {
- render: () => (
- <CrmStoryProvider
- resource="contacts"
- scenarioOptions={{
- db: createCrmDb({
- contacts: bulkTagContacts as any,
- tags: [{ color: "#A5B4FC", id: 1, name: "VIP" }] as any,
- }),
- }}
- >
- <DesktopContactListHarness />
- </CrmStoryProvider>
- ),
++const dataForBulkAddTag = {
++ contacts: [
++ buildContact({
++ first_name: "Ada",
++ id: 1,
++ last_name: "Lovelace",
++ tags: [1],
++ }),
++ buildContact({
++ first_name: "Grace",
++ id: 2,
++ last_name: "Hopper",
++ tags: [],
++ }),
++ ],
++ tags: [{ color: "#A5B4FC", id: 1, name: "VIP" }],
+ };
+
-export const BulkCreateTagDesktop: Story = {
- render: () => (
- <CrmStoryProvider
- resource="contacts"
- scenarioOptions={{
- db: createCrmDb({
- contacts: bulkCreateContacts as any,
- }),
- }}
- >
- <DesktopContactListHarness />
- </CrmStoryProvider>
- ),
-};
++export const BulkTagButton = () => (
++ <StoryWrapper data={dataForBulkAddTag}>
++ <ResourceContextProvider value="contacts">
++ <ContactList />
++ </ResourceContextProvider>
++ </StoryWrapper>
++);
diff --cc src/components/atomic-crm/contacts/ContactList.test.tsx
index dec147df,3092967c..0809847a
--- a/src/components/atomic-crm/contacts/ContactList.test.tsx
+++ b/src/components/atomic-crm/contacts/ContactList.test.tsx
@@@ -1,15 -1,27 +1,16 @@@
-import { composeStories } from "@storybook/react-vite";
-import { describe, expect, it, vi } from "vitest";
import { render } from "vitest-browser-react";
-import * as stories from "./ContactList.stories";
-
-const {
- BulkCreateTagDesktop,
- BulkTagDesktop,
- EmptyDesktop,
- ErrorMobile,
- LoadingContent,
- SuccessDesktop,
-} = composeStories(stories);
-
-const getSelectionCheckboxes = (container: HTMLElement) =>
- Array.from(container.querySelectorAll('[data-slot="checkbox"]')).map(
- (element) => element as HTMLElement,
- );
-
-describe("Contact list", () => {
- it("renders the empty state in the desktop list", async () => {
- const screen = await render(<EmptyDesktop />);
-
+import {
+ DesktopEmpty,
+ DesktopSuccess,
+ DesktopLoading,
+ DesktopError,
++ BulkTagButton,
+} from "./ContactList.stories";
+
+describe("ContactList", () => {
+ it("renders an invite to create the first contact when the app is empty", async () => {
+ const screen = await render(<DesktopEmpty />);
await expect
.element(screen.getByRole("heading", { name: "No contacts found" }))
.toBeInTheDocument();
@@@ -36,11 -48,114 +37,92 @@@
.not.toBeNull();
});
+ it("renders an error notification when loading contacts fails", async () => {
+ const screen = await render(<DesktopError />);
+
+ await expect
+ .element(screen.getByText("Error loading contacts"))
+ .toBeVisible();
+ });
++
+ it("shows the bulk tag button only after selecting contacts", async () => {
- const screen = await render(<BulkTagDesktop />);
++ const screen = await render(<BulkTagButton />);
+
+ await expect
+ .element(screen.getByRole("button", { name: /^tag$/i }))
+ .not.toBeInTheDocument();
+
+ await expect
+ .poll(() => getSelectionCheckboxes(screen.container).length)
+ .toBe(2);
+
+ const [selectionCheckbox] = getSelectionCheckboxes(screen.container);
+ await selectionCheckbox.click();
+
+ await expect
+ .element(screen.getByRole("button", { name: /^tag$/i }))
+ .toBeVisible();
+ });
+
+ it("adds an existing tag to selected contacts without duplicating it", async () => {
- const screen = await render(<BulkTagDesktop />);
++ const screen = await render(<BulkTagButton />);
+
+ await expect
+ .poll(() => getSelectionCheckboxes(screen.container).length)
+ .toBe(2);
+
+ const checkboxes = getSelectionCheckboxes(screen.container);
+ await checkboxes[0].click();
+ await checkboxes[1].click();
+
+ await screen.getByRole("button", { name: /^tag$/i }).click();
+ await screen.getByRole("button", { name: "VIP" }).click();
+
+ await expect
+ .element(screen.getByText("Tag added to 1 contact"))
+ .toBeInTheDocument();
+ await expect
+ .poll(() => screen.getByText("VIP").all().length)
+ .toBeGreaterThanOrEqual(2);
++ // close the notification
++ await screen.getByRole("button", { name: /close/i }).click();
+ });
+
+ it("creates a new tag inline and applies it to the full selected list", async () => {
- const screen = await render(<BulkCreateTagDesktop />);
++ const screen = await render(<BulkTagButton />);
+
+ await expect
+ .poll(() => getSelectionCheckboxes(screen.container).length)
- .toBeGreaterThan(0);
++ .toBe(2);
+
- const [selectionCheckbox] = getSelectionCheckboxes(screen.container);
- await selectionCheckbox.click();
- await screen.getByRole("button", { name: /select all/i }).click();
++ const checkboxes = getSelectionCheckboxes(screen.container);
++ await checkboxes[0].click();
++ await checkboxes[1].click();
+
- await screen.getByRole("button", { name: /^tag$/i }).click();
- await screen.getByRole("button", { name: /create new tag/i }).click();
++ await screen.getByRole("button", { name: /^Tag$/ }).click();
++ await screen.getByRole("button", { name: /Create new tag/ }).click();
+
+ await expect
+ .element(
+ screen.getByText(
+ "Create a new tag and apply it to the selected contacts.",
+ ),
+ )
+ .toBeVisible();
+
+ await screen.getByLabelText("Tag name").fill("Prospect");
- await screen.getByRole("button", { name: /^save$/i }).click();
++ await screen.getByRole("button", { name: /^Save$/ }).click();
+
+ await expect
- .element(screen.getByText("Tag added to 30 contacts"))
++ .element(screen.getByText("Tag added to 2 contacts"))
+ .toBeInTheDocument();
+ await expect.element(screen.getByText("Prospect").first()).toBeVisible();
- await expect
- .element(screen.getByText("Add tag to contacts"))
- .not.toBeInTheDocument();
- });
-
- it("renders the mobile error state when loading contacts fails", async () => {
- const consoleError = vi
- .spyOn(console, "error")
- .mockImplementation(() => {});
- try {
- const screen = await render(<ErrorMobile />);
-
- await expect
- .element(screen.getByText("Error loading contacts"))
- .toBeVisible();
- await expect
- .element(screen.getByRole("button", { name: /retry/i }))
- .toBeVisible();
- } finally {
- consoleError.mockRestore();
- }
- });
-
- it("retries successfully in the mobile error state", async () => {
- const consoleError = vi
- .spyOn(console, "error")
- .mockImplementation(() => {});
- try {
- const screen = await render(<ErrorMobile />);
-
- await screen.getByRole("button", { name: /retry/i }).click();
-
- await expect.element(screen.getByText("Ada Lovelace")).toBeVisible();
- await expect
- .element(screen.getByText("Error loading contacts"))
- .not.toBeInTheDocument();
- } finally {
- consoleError.mockRestore();
- }
++ // close the notification
++ await screen.getByRole("button", { name: /close/i }).click();
+ });
});
++
++const getSelectionCheckboxes = (container: HTMLElement) =>
++ Array.from(container.querySelectorAll('[data-slot="checkbox"]')).map(
++ (element) => element as HTMLElement,
++ );