2026-08-21 15:48:29 -03:00
|
|
|
|
import { fireEvent, screen } from "@testing-library/react";
|
|
|
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
import { WoTableRow } from "@/app/(protected)/workorders/_components/list/table/wo-table-row";
|
|
|
|
|
|
import type { WoTableRowHandlers } from "@/app/(protected)/workorders/_components/list/table/wo-table-row";
|
|
|
|
|
|
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: 9,
|
|
|
|
|
|
woNumber: "24818000001",
|
|
|
|
|
|
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: "09:00 – 10:00",
|
|
|
|
|
|
status: "Completed",
|
|
|
|
|
|
docStatus: "Yes",
|
|
|
|
|
|
pocName: "",
|
|
|
|
|
|
pocPhone: "",
|
|
|
|
|
|
pocNotes: "",
|
|
|
|
|
|
dueDate: "2026-07-22",
|
|
|
|
|
|
rescheduleCount: 0,
|
|
|
|
|
|
carriedOver: 0,
|
|
|
|
|
|
originalWeek: "",
|
|
|
|
|
|
originalDate: "",
|
|
|
|
|
|
isPastDue: false,
|
|
|
|
|
|
scheduleWeekOnly: false,
|
|
|
|
|
|
isAddOn: false,
|
|
|
|
|
|
mediaCount: 1,
|
|
|
|
|
|
title: "",
|
|
|
|
|
|
priority: "",
|
|
|
|
|
|
primaryDispatchId: null,
|
|
|
|
|
|
rowVersion: "",
|
|
|
|
|
|
dispatchRowVersion: "",
|
|
|
|
|
|
flagColor: null,
|
|
|
|
|
|
additionalContacts: [],
|
|
|
|
|
|
upliftSummary: { hasUplift: false, pendingCount: 0 },
|
|
|
|
|
|
...overrides,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handlers: WoTableRowHandlers = {
|
|
|
|
|
|
onRowClick: vi.fn(),
|
|
|
|
|
|
onView: vi.fn(),
|
|
|
|
|
|
onEdit: vi.fn(),
|
|
|
|
|
|
onOpenMedia: vi.fn(),
|
|
|
|
|
|
onPatch: vi.fn(),
|
|
|
|
|
|
onScheduleDate: vi.fn(),
|
|
|
|
|
|
onScheduleWeek: vi.fn(),
|
|
|
|
|
|
onOpenSlideOver: vi.fn(),
|
|
|
|
|
|
onOpenCompDoc: vi.fn(),
|
|
|
|
|
|
onOpenUplifts: vi.fn(),
|
|
|
|
|
|
onReorder: vi.fn(),
|
|
|
|
|
|
onDragStart: vi.fn(),
|
|
|
|
|
|
onDragOver: vi.fn(),
|
|
|
|
|
|
onDrop: vi.fn(),
|
|
|
|
|
|
onDragEnd: vi.fn(),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
describe("WoTableRow completed selective lock", () => {
|
|
|
|
|
|
it("keeps Flag enabled and hides Edit on a Completed row", () => {
|
|
|
|
|
|
const row = makeRow();
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
<WoTableRow
|
|
|
|
|
|
row={row}
|
|
|
|
|
|
allRows={[row]}
|
|
|
|
|
|
users={[]}
|
|
|
|
|
|
sites={[]}
|
|
|
|
|
|
vendors={[]}
|
|
|
|
|
|
pmTypes={["HVAC"]}
|
|
|
|
|
|
isSelected={false}
|
|
|
|
|
|
isFlashing={false}
|
|
|
|
|
|
dragViz={{ dragId: null, overId: null }}
|
|
|
|
|
|
handlers={handlers}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>,
|
|
|
|
|
|
{ withAuth: false },
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-08-28 15:06:59 -03:00
|
|
|
|
expect(screen.getByRole("button", { name: "Add flag" })).toBeEnabled();
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Add flag" }));
|
2026-08-21 15:48:29 -03:00
|
|
|
|
expect(screen.getByText("Clear flag")).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.queryByTitle("Edit")).not.toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByTitle("View details")).toBeInTheDocument();
|
|
|
|
|
|
});
|
2026-08-24 09:31:29 -03:00
|
|
|
|
|
|
|
|
|
|
it("does not open the status menu on a Completed row", () => {
|
|
|
|
|
|
const row = makeRow();
|
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
<WoTableRow
|
|
|
|
|
|
row={row}
|
|
|
|
|
|
allRows={[row]}
|
|
|
|
|
|
users={[]}
|
|
|
|
|
|
sites={[]}
|
|
|
|
|
|
vendors={[]}
|
|
|
|
|
|
pmTypes={["HVAC"]}
|
|
|
|
|
|
isSelected={false}
|
|
|
|
|
|
isFlashing={false}
|
|
|
|
|
|
dragViz={{ dragId: null, overId: null }}
|
|
|
|
|
|
handlers={handlers}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>,
|
|
|
|
|
|
{ withAuth: false },
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByLabelText("Status is locked because this work order is completed"));
|
|
|
|
|
|
|
|
|
|
|
|
expect(screen.queryByRole("button", { name: /scheduled/i })).not.toBeInTheDocument();
|
|
|
|
|
|
expect(screen.queryByRole("button", { name: /in progress/i })).not.toBeInTheDocument();
|
|
|
|
|
|
expect(handlers.onPatch).not.toHaveBeenCalled();
|
|
|
|
|
|
});
|
2026-08-21 15:48:29 -03:00
|
|
|
|
});
|