Skip to content

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

add test on user adding a task

ThieryMichel44deae34cc72
diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts
index f6038f33..a0d6b4f2 100644
--- a/e2e/fixtures.ts
+++ b/e2e/fixtures.ts
@@ -22,7 +22,6 @@ const TABLES = [
];
async function resetDb() {
- console.log("Resetting database...");
for (const table of TABLES) {
// Supabase client delete need a where clause to get executed, so we use one that will match on all rows (id is not null)
await adminSupabase.from(table).delete().not("id", "is", null);
@@ -30,15 +29,172 @@ async function resetDb() {
// Delete all auth users (cascades to sales via DB trigger)
const { data } = await adminSupabase.auth.admin.listUsers();
- console.log("auth users", { data });
await Promise.all(
data.users.map((user) => adminSupabase.auth.admin.deleteUser(user.id)),
);
+}
+
+async function createUser({
+ email,
+ password,
+}: {
+ email: string;
+ password: string;
+}) {
+ const { data, error } = await adminSupabase.auth.admin.createUser({
+ email,
+ password,
+ email_confirm: true,
+ });
+
+ if (error) {
+ throw new Error(`Failed to create user: ${error.message}`);
+ }
+
+ return data.user;
+}
+
+async function createSales({
+ first_name,
+ last_name,
+ email,
+ password,
+}: {
+ first_name: string;
+ last_name: string;
+ email: string;
+ password: string;
+}) {
+ const { data: userData, error: userError } =
+ await adminSupabase.auth.admin.createUser({
+ email,
+ password,
+ email_confirm: true,
+ });
+
+ if (userError) {
+ throw new Error(`Failed to create sales: ${userError.message}`);
+ }
+
+ const { data, error } = await adminSupabase
+ .from("sales")
+ .update({ first_name, last_name, administrator: false })
+ .eq("user_id", userData.user?.id)
+ .select()
+ .single();
+
+ if (error) {
+ throw new Error(`Failed to create sales: ${error.message}`);
+ }
+
+ return data;
+}
+
+async function createNotes({
+ contactId,
+ salesId,
+ notes,
+}: {
+ contactId: string | number;
+ salesId: string | number;
+ notes: {
+ text: string;
+ date?: string;
+ status?: "cold" | "warm" | "hot";
+ }[];
+}) {
+ if (notes.length === 0) return;
+
+ const { error } = await adminSupabase.from("contact_notes").insert(
+ notes.map(({ text, date, status = "cold" }) => ({
+ contact_id: contactId,
+ sales_id: salesId,
+ text,
+ date,
+ status,
+ })),
+ );
+
+ if (error) {
+ throw new Error(`Failed to create notes: ${error.message}`);
+ }
+}
+
+async function createCompany({ name }: { name: string }) {
+ const { data, error } = await adminSupabase
+ .from("companies")
+ .insert({ name })
+ .select("id")
+ .single();
+
+ if (error) {
+ throw new Error(`Failed to create company: ${error.message}`);
+ }
+
+ return data;
+}
+
+async function createContact({
+ first_name,
+ last_name,
+ title = "",
+ company_id = null,
+ sales_id,
+ notes = [],
+}: {
+ first_name: string;
+ last_name: string;
+ title?: string;
+ company_id?: string | number | null;
+ sales_id: string | number;
+ notes?: {
+ text: string;
+ date?: string;
+ status?: "cold" | "warm" | "hot";
+ }[];
+}) {
+ const { data, error } = await adminSupabase
+ .from("contacts")
+ .insert({
+ first_name,
+ last_name,
+ title,
+ company_id,
+ sales_id,
+ first_seen: new Date().toISOString(),
+ last_seen: new Date().toISOString(),
+ has_newsletter: false,
+ tags: [],
+ gender: "unknown",
+ status: "cold",
+ background: "",
+ email_jsonb: [],
+ phone_jsonb: [],
+ })
+ .select("id")
+ .single();
+
+ if (error) {
+ throw new Error(`Failed to create contact: ${error.message}`);
+ }
+
+ await createNotes({
+ contactId: data.id,
+ salesId: sales_id,
+ notes,
+ });
- console.log("Database reset success");
+ return data;
}
-export const test = base.extend<{ resetDb: void }>({
+export const test = base.extend<{
+ resetDb: void;
+ createUser: typeof createUser;
+ createSales: typeof createSales;
+ createCompany: typeof createCompany;
+ createContact: typeof createContact;
+ createNotes: typeof createNotes;
+}>({
resetDb: [
// The first argument to a Playwright fixture function must use object destructuring ({}) — _ is not allowed.
// Playwright uses this to statically analyze which fixtures are requested.
@@ -49,6 +205,26 @@ export const test = base.extend<{ resetDb: void }>({
},
{ auto: true },
],
+ // eslint-disable-next-line no-empty-pattern
+ createUser: async ({}, cb) => {
+ await cb(createUser);
+ },
+ // eslint-disable-next-line no-empty-pattern
+ createSales: async ({}, cb) => {
+ await cb(createSales);
+ },
+ // eslint-disable-next-line no-empty-pattern
+ createCompany: async ({}, cb) => {
+ await cb(createCompany);
+ },
+ // eslint-disable-next-line no-empty-pattern
+ createContact: async ({}, cb) => {
+ await cb(createContact);
+ },
+ // eslint-disable-next-line no-empty-pattern
+ createNotes: async ({}, cb) => {
+ await cb(createNotes);
+ },
});
export { expect };
diff --git a/e2e/userAddingATask.spec.ts b/e2e/userAddingATask.spec.ts
new file mode 100644
index 00000000..aecf9863
--- /dev/null
+++ b/e2e/userAddingATask.spec.ts
@@ -0,0 +1,102 @@
+import { expect, test } from "./fixtures";
+
+test.describe("user adding a task", () => {
+ test.beforeEach(async ({ createSales, createContact, createCompany }) => {
+ const sales = await createSales({
+ first_name: "John",
+ last_name: "Doe",
+ email: "[email protected]",
+ password: "password",
+ });
+
+ const company = await createCompany({
+ name: "Smith Corp",
+ });
+
+ await createContact({
+ first_name: "Jane",
+ last_name: "Smith",
+ title: "CEO",
+ sales_id: sales.id,
+ company_id: company.id,
+ notes: [{ text: "Met at a conference." }],
+ });
+
+ await createContact({
+ first_name: "Bob",
+ last_name: "Johnson",
+ title: "CTO",
+ sales_id: sales.id,
+ company_id: company.id,
+ });
+
+ await createContact({
+ first_name: "Alice",
+ last_name: "Williams",
+ title: "CFO",
+ sales_id: sales.id,
+ company_id: company.id,
+ });
+ });
+ test("user adding a task", async ({ page, isMobile }) => {
+ await page.goto("http://localhost:5175/");
+ await page.getByLabel("Email").fill("[email protected]");
+ await page.getByLabel("Password").fill("password");
+ await page.getByRole("button", { name: "Sign in" }).click();
+
+ await expect(page).toHaveTitle(/Atomic CRM/);
+ await expect(page.getByText("Latest Activity")).toBeVisible();
+
+ await page.getByRole("link", { name: "Contacts" }).click();
+ await page.waitForLoadState("networkidle");
+
+ await page.getByText("Jane Smith").click();
+ await page.waitForLoadState("networkidle");
+
+ if (isMobile) {
+ await page.getByRole("button", { name: "Create" }).click();
+ await page.getByRole("menuitem", { name: "Task" }).click();
+ } else {
+ await page.getByRole("button", { name: "Add Task" }).click();
+ }
+ await page.getByLabel("Description *").fill("Follow up with Jane");
+ await page.getByLabel("Due date").fill("2026-04-11T21:00");
+ await page.getByLabel("Type").click();
+ await page.getByRole("option", { name: "Call" }).click();
+
+ await page.getByRole("button", { name: "Save" }).click();
+
+ await expect(
+ page.getByText(
+ isMobile
+ ? "Create Task for Jane Smith"
+ : "Create a new task for Jane Smith",
+ ),
+ ).not.toBeVisible();
+
+ if (isMobile) {
+ await expect(page.getByText("1 Tasks")).toBeVisible();
+ await page.getByText("1 Tasks").click();
+
+ await expect(page.getByText("Follow up with Jane")).toBeVisible();
+ await expect(page.getByText("due 4/11/2026, 9:00:00 PM")).toBeVisible();
+ } else {
+ await expect(page.getByText("Tasks")).toBeVisible();
+
+ await expect(page.getByText("Tasks").locator("..")).toHaveText(
+ /Follow up with Jane/,
+ );
+ await page.getByRole("link", { name: "Dashboard" }).click();
+
+ await expect(page.getByText("Upcoming Tasks")).toBeVisible();
+ await expect(
+ page.getByText("Upcoming Tasks").locator("../.."),
+ ).toHaveText(/Follow up with Jane/);
+ await expect(
+ page.getByText("Follow up with Jane").locator(".."),
+ ).toHaveText(
+ "Call Follow up with Janedue 4/11/2026, 9:00:00 PM (Re: Jane Smith)",
+ );
+ }
+ });
+});
diff --git a/src/components/atomic-crm/tasks/TaskCreateSheet.tsx b/src/components/atomic-crm/tasks/TaskCreateSheet.tsx
index f5546ede..ba36199f 100644
--- a/src/components/atomic-crm/tasks/TaskCreateSheet.tsx
+++ b/src/components/atomic-crm/tasks/TaskCreateSheet.tsx
@@ -11,6 +11,7 @@ import {
import { CreateSheet } from "../misc/CreateSheet";
import { foreignKeyMapping } from "../notes/foreignKeyMapping";
import { TaskFormContent } from "./TaskFormContent";
+import { useQueryClient } from "@tanstack/react-query";
export interface TaskCreateSheetProps {
open: boolean;
@@ -35,6 +36,7 @@ export const TaskCreateSheet = ({
);
const [update] = useUpdate();
const dataProvider = useDataProvider();
+ const queryClient = useQueryClient();
const notify = useNotify();
if (!identity) return null;
@@ -46,11 +48,15 @@ export const TaskCreateSheet = ({
id: referenceRecordId,
});
if (!contact) return;
- update("contacts", {
+ await update("contacts", {
id: referenceRecordId as unknown as Identifier,
data: { last_seen: new Date().toISOString() },
previousData: contact,
});
+ queryClient.invalidateQueries({
+ queryKey: ["contacts", "getOne"],
+ });
+
notify("resources.tasks.added");
// No redirect, only close the sheet
onOpenChange(false);