shoc-frontend-new/src/test/app/(protected)/workorders/use-wo-table-row-handlers-duplicate.test.ts
Arthur Bassi 25837171a4
Some checks are pending
CI / ci (push) Waiting to run
CI / governance (push) Waiting to run
CI / vendor-visual-regression (push) Waiting to run
Deploy / deploy (push) Waiting to run
feat(work-orders): duplicate WO number dialog on table and wizard (SH-189) (#90)
* docs(work-orders): add pending BE contract checklist for design parity gaps

* feat(work-orders): confirm dialog when duplicate wo number detected

* fix(work-orders): show duplicate wo number dialog on wizard create

* docs(work-orders): align pr description with jira and qa residuals

* style(work-orders): prettier wizard duplicate dialog files

* refactor(workorders): extract wizard state hook and list overlays

* fix(work-orders): check duplicate numbers globally

* fix(work-orders): exhaust fuzzy pages for exact WO number lookup

Prevent accepting duplicates that fall outside the first fuzzy search page.

* style(work-orders): format editable WO number cell for Prettier gate

* fix(work-orders): 0-based WO search page and stale duplicate guard

* fix(work-orders): sync draft WO# ref in effect for duplicate guard [SH-189]

* fix(work-orders): extract WO number editor under max-lines gate

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(work-orders): harden duplicate WO number checks [SH-189]

* fix(work-orders): sync wizard refs in effects and exhaust duplicate WO lookup

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(work-orders): extract hooks to satisfy max-lines governance gate

Co-authored-by: Cursor <cursoragent@cursor.com>

* style(work-orders): format wizard state hook for Prettier gate

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(work-orders): search one-character WO numbers for duplicates

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 11:04:48 -03:00

43 lines
1.4 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(),
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",
onWeekChange: 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();
});
});