A full-featured CRM built with React, shadcn/ui, and Supabase.
Add unit tests
fzaninotto877730968043
diff --git a/src/components/atomic-crm/notes/NoteInputsMobile.stories.tsx b/src/components/atomic-crm/notes/NoteInputsMobile.stories.tsxnew file mode 100644index 00000000..a8a30f11--- /dev/null+++ b/src/components/atomic-crm/notes/NoteInputsMobile.stories.tsx@@ -0,0 +1,57 @@+import type { Meta, StoryObj } from "@storybook/react-vite";+import { Form } from "ra-core";++import { NoteInputsMobile } from "./NoteInputsMobile";+import { SaveButton } from "@/components/admin/form";+import { StoryWrapper } from "@/test/StoryWrapper";++type NoteInputsMobileStoryProps = React.ComponentProps<+ typeof NoteInputsMobile+> & {+ defaultValues?: Record<string, unknown>;+ withSaveButton?: boolean;+};++export const NoteInputsMobileStory = ({+ defaultValues,+ ...props+}: NoteInputsMobileStoryProps) => (+ <StoryWrapper>+ <Form defaultValues={defaultValues}>+ <NoteInputsMobile {...props} />+ <SaveButton type="button" className="mt-6" />+ </Form>+ </StoryWrapper>+);++const meta = {+ title: "Atomic CRM/Notes/Note Inputs Mobile",+ includeStories: [+ "Default",+ "WithSaveButton",+ "WithSelectContact",+ "WithAttachmentDefault",+ ],+ render: (args) => <NoteInputsMobileStory {...args} />,+} satisfies Meta<typeof NoteInputsMobileStory>;++export default meta;++type Story = StoryObj<typeof meta>;++export const Default: Story = {};++export const WithSelectContact: Story = {+ args: {+ selectContact: true,+ },+};++export const WithAttachmentDefault: Story = {+ args: {+ defaultValues: {+ attachments: [{ src: "blob:test", title: "evidence.pdf" }],+ },+ withSaveButton: true,+ },+};diff --git a/src/components/atomic-crm/notes/NoteInputsMobile.test.tsx b/src/components/atomic-crm/notes/NoteInputsMobile.test.tsxnew file mode 100644index 00000000..74ac4064--- /dev/null+++ b/src/components/atomic-crm/notes/NoteInputsMobile.test.tsx@@ -0,0 +1,76 @@+import { composeStories } from "@storybook/react-vite";+import { render } from "vitest-browser-react";+import * as stories from "./NoteInputsMobile.stories";++const { Default, WithAttachmentDefault, WithSelectContact } =+ composeStories(stories);++describe("NoteInputsMobile", () => {+ it("renders the note textarea", async () => {+ const screen = await render(<Default />);++ await expect.element(screen.getByPlaceholder("Add a note")).toBeVisible();+ });++ it("renders the attach document button", async () => {+ const screen = await render(<Default />);++ await expect+ .element(screen.getByRole("button", { name: "Attach document" }))+ .toBeVisible();+ });++ it("does not render the contact selector by default", async () => {+ const screen = await render(<Default />);++ await expect.element(screen.getByText("Contact")).not.toBeInTheDocument();+ });++ it("renders the contact selector when selectContact is true", async () => {+ const screen = await render(<WithSelectContact />);++ await expect.element(screen.getByText("Contact")).toBeVisible();+ });++ it("shows a validation error when submitting an empty note without attachments", async () => {+ const screen = await render(<Default />);++ await screen.getByRole("button", { name: "Save" }).click();++ await expect+ .element(screen.getByText("A note or an attachment is required"))+ .toBeVisible();+ });++ it("treats whitespace-only note text as empty", async () => {+ const screen = await render(<Default />);++ await screen.getByPlaceholder("Add a note").fill(" ");+ await screen.getByRole("button", { name: "Save" }).click();++ await expect+ .element(screen.getByText("A note or an attachment is required"))+ .toBeVisible();+ });++ it("allows submitting a note with text only", async () => {+ const screen = await render(<Default />);++ await screen.getByPlaceholder("Add a note").fill("Call summary");+ await screen.getByRole("button", { name: "Save" }).click();++ await expect+ .element(screen.getByText("A note or an attachment is required"))+ .not.toBeInTheDocument();+ });++ it("allows submitting a note with an attachment and no text", async () => {+ const screen = await render(<WithAttachmentDefault />);++ await screen.getByRole("button", { name: "Save" }).click();++ await expect+ .element(screen.getByText("A note or an attachment is required"))+ .not.toBeInTheDocument();+ });+});