mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 06:32:05 +00:00
160 lines
4.5 KiB
TypeScript
160 lines
4.5 KiB
TypeScript
import { fireEvent, 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";
|
|
import { renderWithProviders } from "@/test/test-utils";
|
|
|
|
function makeRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
|
return {
|
|
id: 1,
|
|
woNumber: "1001",
|
|
site: "BK5",
|
|
type: "PM",
|
|
severity: null,
|
|
dispatcherId: "u1",
|
|
dispatcherName: "Alex",
|
|
scheduledOn: "2026-07-15",
|
|
completedDate: "2026-07-20",
|
|
targetWeek: "2026-07-15",
|
|
dayGroup: "07/15",
|
|
dayLabel: "Tue",
|
|
location: "Lobby",
|
|
locationId: "loc-1",
|
|
pm: "HVAC",
|
|
serviceNotes: "",
|
|
extraServices: [],
|
|
vendorId: "7",
|
|
company: "Acme",
|
|
tech: "Sam",
|
|
techPhone: "",
|
|
apptStart: "",
|
|
apptEnd: "",
|
|
apptTime: "",
|
|
status: "In Progress",
|
|
docStatus: "Yes",
|
|
pocName: "",
|
|
pocPhone: "",
|
|
pocNotes: "",
|
|
dueDate: "",
|
|
rescheduleCount: 0,
|
|
carriedOver: 0,
|
|
originalWeek: "",
|
|
originalDate: "",
|
|
isPastDue: false,
|
|
scheduleWeekOnly: false,
|
|
isAddOn: false,
|
|
mediaCount: 1,
|
|
title: "",
|
|
priority: "",
|
|
primaryDispatchId: null,
|
|
rowVersion: "",
|
|
dispatchRowVersion: "",
|
|
flagColor: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("StatusCell pending uplift closability", () => {
|
|
it("disables Completed with tooltip when uplift is pending", () => {
|
|
const onChangeStatus = vi.fn();
|
|
|
|
renderWithProviders(
|
|
<StatusCell
|
|
wo={makeRow({ hasPendingUplift: true })}
|
|
onChangeStatus={onChangeStatus}
|
|
onOpenSlideOver={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /in progress/i }));
|
|
|
|
const completed = screen.getByRole("button", { name: /completed/i });
|
|
expect(completed).toBeDisabled();
|
|
expect(completed).toHaveAttribute(
|
|
"title",
|
|
"This work order has an uplift pending approval and cannot be completed.",
|
|
);
|
|
|
|
fireEvent.click(completed);
|
|
expect(onChangeStatus).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("disables Completed with tooltip when board pendingUpliftCount maps to pending", () => {
|
|
const onChangeStatus = vi.fn();
|
|
|
|
renderWithProviders(
|
|
<StatusCell
|
|
wo={makeRow({
|
|
hasPendingUplift: true,
|
|
upliftSummary: { hasUplift: true, pendingCount: 1 },
|
|
})}
|
|
onChangeStatus={onChangeStatus}
|
|
onOpenSlideOver={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /in progress/i }));
|
|
|
|
const completed = screen.getByRole("button", { name: /completed/i });
|
|
expect(completed).toBeDisabled();
|
|
expect(completed).toHaveAttribute(
|
|
"title",
|
|
"This work order has an uplift pending approval and cannot be completed.",
|
|
);
|
|
});
|
|
|
|
it("allows Completed when no pending uplift", () => {
|
|
const onChangeStatus = vi.fn();
|
|
|
|
renderWithProviders(
|
|
<StatusCell wo={makeRow()} onChangeStatus={onChangeStatus} onOpenSlideOver={vi.fn()} />,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /in progress/i }));
|
|
fireEvent.click(screen.getByRole("button", { name: /completed/i }));
|
|
|
|
expect(onChangeStatus).toHaveBeenCalledWith("Completed");
|
|
});
|
|
|
|
it("disables Completed when company is missing (SH-183)", () => {
|
|
const onChangeStatus = vi.fn();
|
|
|
|
renderWithProviders(
|
|
<StatusCell
|
|
wo={makeRow({ company: "" })}
|
|
onChangeStatus={onChangeStatus}
|
|
onOpenSlideOver={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /in progress/i }));
|
|
|
|
const completed = screen.getByRole("button", { name: /completed/i });
|
|
expect(completed).toBeDisabled();
|
|
expect(completed).toHaveAttribute("title", "Missing: Company");
|
|
fireEvent.click(completed);
|
|
expect(onChangeStatus).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows Completed when technician is empty if company is set (SH-183)", () => {
|
|
const onChangeStatus = vi.fn();
|
|
|
|
renderWithProviders(
|
|
<StatusCell
|
|
wo={makeRow({ tech: "" })}
|
|
onChangeStatus={onChangeStatus}
|
|
onOpenSlideOver={vi.fn()}
|
|
/>,
|
|
{ withAuth: false },
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /in progress/i }));
|
|
fireEvent.click(screen.getByRole("button", { name: /completed/i }));
|
|
|
|
expect(onChangeStatus).toHaveBeenCalledWith("Completed");
|
|
});
|
|
});
|