import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { AssignedToCell } from "@/app/(protected)/workorders/_components/list/table/cells/assigned-to-cell"; const USERS = [ { id: "sarah", name: "Sarah Chen" }, { id: "morgan", name: "Morgan Blake" }, ]; describe("AssignedToCell", () => { it("lets any board user pick a dispatcher without a role/disabled prop", async () => { const user = userEvent.setup(); const onSave = vi.fn(); render(); const trigger = screen.getByRole("button", { name: /select dispatcher/i }); expect(trigger).toBeEnabled(); expect(trigger).not.toHaveAttribute("aria-disabled", "true"); await user.click(trigger); await user.click(await screen.findByRole("button", { name: /sarah chen/i })); expect(onSave).toHaveBeenCalledWith("sarah", "Sarah Chen"); }); it("can clear assignment to Unassigned", async () => { const user = userEvent.setup(); const onSave = vi.fn(); render(); await user.click(screen.getByRole("button", { name: /sarah chen/i })); await user.click(await screen.findByRole("button", { name: "Unassigned" })); expect(onSave).toHaveBeenCalledWith("", ""); }); it("still opens with an empty dispatcher list", async () => { const user = userEvent.setup(); const onSave = vi.fn(); render(); await user.click(screen.getByRole("button", { name: /select dispatcher/i })); await user.click(await screen.findByRole("button", { name: "Unassigned" })); expect(onSave).toHaveBeenCalledWith("", ""); }); });