mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 14:42:05 +00:00
65 lines
2 KiB
TypeScript
65 lines
2 KiB
TypeScript
import { renderHook } from "@testing-library/react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { useWoTableRowHandlers } from "@/app/(protected)/workorders/_components/list/table/use-wo-table-row-handlers";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
const existingRow = { id: "wo-99", woNumber: "12345678901" } as WorkOrderTableRow;
|
|
|
|
function buildTableData() {
|
|
return {
|
|
dragState: { current: { dragId: null, overId: null } },
|
|
setDragViz: vi.fn(),
|
|
reorderRows: vi.fn(),
|
|
endDrag: vi.fn(),
|
|
setUnschedOpen: vi.fn(),
|
|
triggerFlash: vi.fn(),
|
|
revealScheduledRow: vi.fn(),
|
|
setSelectedId: vi.fn(),
|
|
} as never;
|
|
}
|
|
|
|
describe("useWoTableRowHandlers onDuplicateFound", () => {
|
|
it("delegates to onDuplicateFound instead of opening the slide-over", () => {
|
|
const onDuplicateFound = vi.fn();
|
|
const onOpenSlideOver = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(),
|
|
weekMonday: "2026-07-20",
|
|
onNavigateToDay: vi.fn(),
|
|
onOpenSlideOver,
|
|
onOpenMedia: vi.fn(),
|
|
onPatch: vi.fn(),
|
|
onScheduleHighlight: vi.fn(),
|
|
onDuplicateFound,
|
|
}),
|
|
);
|
|
|
|
result.current.onDuplicateFound?.(existingRow);
|
|
|
|
expect(onDuplicateFound).toHaveBeenCalledWith(existingRow);
|
|
expect(onOpenSlideOver).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("forwards patch options so vendor persist can toast on success", () => {
|
|
const onPatch = vi.fn();
|
|
const onSuccess = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(),
|
|
weekMonday: "2026-07-20",
|
|
onNavigateToDay: vi.fn(),
|
|
onOpenSlideOver: vi.fn(),
|
|
onOpenMedia: vi.fn(),
|
|
onPatch,
|
|
onScheduleHighlight: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
result.current.onPatch("wo-1", { vendorId: "9" }, { onSuccess });
|
|
|
|
expect(onPatch).toHaveBeenCalledWith("wo-1", { vendorId: "9" }, { onSuccess });
|
|
});
|
|
});
|