mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 00:02:06 +00:00
test(workorders): cover completed-date Clear through the board row (SH-390)
Clear on an open row reaches the board patch with completedDate empty; Completed and Canceled rows offer no Clear and send no patch.
This commit is contained in:
parent
460397dacb
commit
55f548d507
1 changed files with 128 additions and 0 deletions
|
|
@ -0,0 +1,128 @@
|
||||||
|
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: "Incomplete",
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeHandlers(): WoTableRowHandlers {
|
||||||
|
return {
|
||||||
|
onRowClick: vi.fn(),
|
||||||
|
onView: vi.fn(),
|
||||||
|
onEdit: vi.fn(),
|
||||||
|
onOpenMedia: vi.fn(),
|
||||||
|
onPatch: vi.fn(),
|
||||||
|
onScheduleDate: vi.fn(),
|
||||||
|
onScheduleWeek: vi.fn(),
|
||||||
|
onScheduleRange: 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(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderRow(row: WorkOrderTableRow, handlers: WoTableRowHandlers) {
|
||||||
|
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 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("WoTableRow completed date Clear (SH-390)", () => {
|
||||||
|
it("clears the completed date of an open row through the board patch", async () => {
|
||||||
|
const handlers = makeHandlers();
|
||||||
|
renderRow(makeRow(), handlers);
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /07-20/ }));
|
||||||
|
fireEvent.click(await screen.findByRole("button", { name: /clear/i }));
|
||||||
|
|
||||||
|
expect(handlers.onPatch).toHaveBeenCalledTimes(1);
|
||||||
|
expect(vi.mocked(handlers.onPatch).mock.calls[0].slice(0, 2)).toEqual([
|
||||||
|
9,
|
||||||
|
{ completedDate: "" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(["Completed", "Canceled"])("offers no Clear on a %s row", async (status) => {
|
||||||
|
const handlers = makeHandlers();
|
||||||
|
renderRow(makeRow({ status }), handlers);
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByRole("button", { name: /07-20/ }));
|
||||||
|
|
||||||
|
expect(await screen.findByRole("button", { name: "20" })).toBeInTheDocument();
|
||||||
|
expect(screen.queryByRole("button", { name: /clear/i })).not.toBeInTheDocument();
|
||||||
|
expect(handlers.onPatch).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Reference in a new issue