2026-08-10 17:12:14 -03:00
|
|
|
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: "",
|
2026-08-19 11:49:19 -03:00
|
|
|
vendorId: "",
|
2026-08-10 17:12:14 -03:00
|
|
|
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);
|
2026-09-02 15:11:31 -03:00
|
|
|
expect(completed.getAttribute("title") ?? "").toContain("Fill in");
|
2026-08-10 17:12:14 -03:00
|
|
|
fireEvent.click(completed);
|
|
|
|
|
expect(onChangeStatus).not.toHaveBeenCalledWith("Completed");
|
|
|
|
|
});
|
2026-09-02 15:11:31 -03:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
2026-08-10 17:12:14 -03:00
|
|
|
});
|