shoc-frontend-new/src/test/app/(protected)/workorders/status-cell-closability.test.tsx

78 lines
2.6 KiB
TypeScript
Raw Normal View History

import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { StatusCell } from "@/app/(protected)/workorders/_components/list/table/cells/status-cell";
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
const incompleteRow = {
id: "wo-1",
status: "Scheduled",
dispatcherId: "",
dispatcherName: "",
company: "",
vendorId: "",
tech: "",
completedDate: "",
woNumber: "",
pm: "",
docStatus: "",
mediaCount: 0,
type: "PM",
} as WorkOrderTableRow;
describe("StatusCell closability gate", () => {
it("does not submit Completed when required work-order data is missing", () => {
const onChangeStatus = vi.fn();
render(
<StatusCell wo={incompleteRow} onChangeStatus={onChangeStatus} onOpenSlideOver={vi.fn()} />,
);
fireEvent.click(screen.getByRole("button", { name: /scheduled/i }));
const completed = screen.getByRole("button", { name: /^completed$/i });
expect(completed.hasAttribute("disabled")).toBe(true);
expect(completed.getAttribute("title") ?? "").toContain("Fill in");
fireEvent.click(completed);
expect(onChangeStatus).not.toHaveBeenCalledWith("Completed");
});
it("does not offer Canceled", () => {
render(<StatusCell wo={incompleteRow} onChangeStatus={vi.fn()} onOpenSlideOver={vi.fn()} />);
fireEvent.click(screen.getByRole("button", { name: /scheduled/i }));
expect(screen.queryByRole("button", { name: /^canceled$/i })).toBeNull();
});
it("disables Scheduled when the row has no concrete date", () => {
const onChangeStatus = vi.fn();
render(
<StatusCell
wo={{ ...incompleteRow, status: "Pending", scheduledOn: "" }}
onChangeStatus={onChangeStatus}
onOpenSlideOver={vi.fn()}
/>,
);
fireEvent.click(screen.getByRole("button", { name: /pending/i }));
const scheduled = screen.getByRole("button", { name: /^scheduled$/i });
expect(scheduled).toBeDisabled();
fireEvent.click(scheduled);
expect(onChangeStatus).not.toHaveBeenCalled();
});
it("limits creation options to Incomplete, Pending, and Scheduled", () => {
render(
<StatusCell
wo={{ ...incompleteRow, status: "Incomplete" }}
statusOptions={["Incomplete", "Pending", "Scheduled"]}
onChangeStatus={vi.fn()}
onOpenSlideOver={vi.fn()}
/>,
);
fireEvent.click(screen.getByRole("button", { name: /incomplete/i }));
expect(screen.getByRole("button", { name: /^pending$/i })).toBeTruthy();
expect(screen.queryByRole("button", { name: /^en route$/i })).toBeNull();
});
});