mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 06:32:05 +00:00
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
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(<AssignedToCell dispatcherId="" users={USERS} highlight onSave={onSave} />);
|
|
|
|
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(<AssignedToCell dispatcherId="sarah" users={USERS} onSave={onSave} />);
|
|
|
|
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(<AssignedToCell dispatcherId="" users={[]} onSave={onSave} />);
|
|
|
|
await user.click(screen.getByRole("button", { name: /select dispatcher/i }));
|
|
await user.click(await screen.findByRole("button", { name: "Unassigned" }));
|
|
|
|
expect(onSave).toHaveBeenCalledWith("", "");
|
|
});
|
|
});
|