mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 10:02:04 +00:00
Board Clear uses empty-week patch; slide-over Save derives Pending via mergeAutoSchedulePatch.
186 lines
5.7 KiB
TypeScript
186 lines
5.7 KiB
TypeScript
import { renderHook } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { useWoTableRowHandlers } from "@/app/(protected)/workorders/_components/list/table/use-wo-table-row-handlers";
|
|
import {
|
|
applySchedulePatch,
|
|
applyScheduleRangePatch,
|
|
} from "@/domain/work-orders/use-cases/use-work-order-table-mutations";
|
|
|
|
const { rescheduleNotify, weekMoveNotify } = vi.hoisted(() => ({
|
|
rescheduleNotify: vi.fn(),
|
|
weekMoveNotify: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/app/(protected)/workorders/_components/list/table/reschedule-notify", () => ({
|
|
rescheduleNotify,
|
|
weekMoveNotify,
|
|
}));
|
|
|
|
function buildTableData(revealScheduledRow = vi.fn()) {
|
|
return {
|
|
dragState: { current: { dragId: null, overId: null } },
|
|
setDragViz: vi.fn(),
|
|
reorderRows: vi.fn(),
|
|
endDrag: vi.fn(),
|
|
revealScheduledRow,
|
|
setSelectedId: vi.fn(),
|
|
} as never;
|
|
}
|
|
|
|
describe("useWoTableRowHandlers schedule navigation", () => {
|
|
beforeEach(() => {
|
|
rescheduleNotify.mockClear();
|
|
weekMoveNotify.mockClear();
|
|
});
|
|
|
|
it("selects the scheduled weekday in the same week so the row stays visible", () => {
|
|
const onNavigateToDay = vi.fn();
|
|
const onPatch = vi.fn();
|
|
const revealScheduledRow = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(revealScheduledRow),
|
|
weekMonday: "2026-05-18",
|
|
onNavigateToDay,
|
|
onOpenSlideOver: vi.fn(),
|
|
onOpenMedia: vi.fn(),
|
|
onPatch,
|
|
onScheduleHighlight: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
result.current.onScheduleDate("wo-1", "2026-05-21");
|
|
|
|
expect(onPatch).toHaveBeenCalledWith("wo-1", applySchedulePatch("2026-05-21", false));
|
|
expect(onNavigateToDay).toHaveBeenCalledWith("2026-05-21");
|
|
expect(revealScheduledRow).toHaveBeenCalledWith("wo-1");
|
|
expect(rescheduleNotify).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("sends cross-week view-it navigation to the target day, not Monday", () => {
|
|
const onNavigateToDay = vi.fn();
|
|
const revealScheduledRow = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(revealScheduledRow),
|
|
weekMonday: "2026-05-18",
|
|
onNavigateToDay,
|
|
onOpenSlideOver: vi.fn(),
|
|
onOpenMedia: vi.fn(),
|
|
onPatch: vi.fn(),
|
|
onScheduleHighlight: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
result.current.onScheduleDate("wo-1", "2026-05-27");
|
|
|
|
expect(onNavigateToDay).not.toHaveBeenCalled();
|
|
expect(rescheduleNotify).toHaveBeenCalledWith(
|
|
"2026-05-27",
|
|
expect.objectContaining({ onNavigate: expect.any(Function) }),
|
|
);
|
|
|
|
const { onNavigate } = rescheduleNotify.mock.calls[0][1] as { onNavigate: () => void };
|
|
onNavigate();
|
|
expect(onNavigateToDay).toHaveBeenCalledWith("2026-05-27");
|
|
expect(revealScheduledRow).toHaveBeenCalledWith("wo-1");
|
|
});
|
|
|
|
it("lands a range on the start day and reveals the row", () => {
|
|
const onNavigateToDay = vi.fn();
|
|
const onPatch = vi.fn();
|
|
const revealScheduledRow = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(revealScheduledRow),
|
|
weekMonday: "2026-05-18",
|
|
onNavigateToDay,
|
|
onOpenSlideOver: vi.fn(),
|
|
onOpenMedia: vi.fn(),
|
|
onPatch,
|
|
onScheduleHighlight: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
result.current.onScheduleRange("wo-1", "2026-05-21", "2026-05-23");
|
|
|
|
expect(onPatch).toHaveBeenCalledWith(
|
|
"wo-1",
|
|
applyScheduleRangePatch("2026-05-21", "2026-05-23"),
|
|
);
|
|
expect(onNavigateToDay).toHaveBeenCalledWith("2026-05-21");
|
|
expect(revealScheduledRow).toHaveBeenCalledWith("wo-1");
|
|
expect(rescheduleNotify).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("opens Advanced Filters for week-only moves instead of the removed Unscheduled section", () => {
|
|
const onNavigateToDay = vi.fn();
|
|
const onOpenAdvancedFilters = vi.fn();
|
|
const onPatch = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(),
|
|
weekMonday: "2026-05-18",
|
|
onNavigateToDay,
|
|
onOpenAdvancedFilters,
|
|
onOpenSlideOver: vi.fn(),
|
|
onOpenMedia: vi.fn(),
|
|
onPatch,
|
|
onScheduleHighlight: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
result.current.onScheduleWeek("wo-1", "2026-05-25");
|
|
|
|
expect(onPatch).toHaveBeenCalledWith(
|
|
"wo-1",
|
|
expect.objectContaining({
|
|
scheduledOn: "",
|
|
scheduleWeekOnly: true,
|
|
targetWeek: "2026-05-25",
|
|
}),
|
|
);
|
|
expect(weekMoveNotify).toHaveBeenCalled();
|
|
|
|
const { onNavigate } = weekMoveNotify.mock.calls[0][1] as { onNavigate: () => void };
|
|
onNavigate();
|
|
expect(onNavigateToDay).toHaveBeenCalledWith("2026-05-25");
|
|
expect(onOpenAdvancedFilters).toHaveBeenCalled();
|
|
});
|
|
|
|
it("clears the concrete schedule and opens Advanced Filters from the Unscheduled toast", () => {
|
|
const onNavigateToDay = vi.fn();
|
|
const onOpenAdvancedFilters = vi.fn();
|
|
const onPatch = vi.fn();
|
|
|
|
const { result } = renderHook(() =>
|
|
useWoTableRowHandlers({
|
|
tableData: buildTableData(),
|
|
weekMonday: "2026-05-18",
|
|
onNavigateToDay,
|
|
onOpenAdvancedFilters,
|
|
onOpenSlideOver: vi.fn(),
|
|
onOpenMedia: vi.fn(),
|
|
onPatch,
|
|
onScheduleHighlight: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
result.current.onScheduleWeek("wo-1", "");
|
|
|
|
expect(onPatch).toHaveBeenCalledWith("wo-1", applySchedulePatch("", false));
|
|
expect(weekMoveNotify).toHaveBeenCalledWith(
|
|
"",
|
|
expect.objectContaining({ onNavigate: expect.any(Function) }),
|
|
);
|
|
|
|
const { onNavigate } = weekMoveNotify.mock.calls[0][1] as { onNavigate: () => void };
|
|
onNavigate();
|
|
expect(onNavigateToDay).not.toHaveBeenCalled();
|
|
expect(onOpenAdvancedFilters).toHaveBeenCalled();
|
|
});
|
|
});
|