diff --git a/src/domain/work-orders/utils/wo-lifecycle-transitions.ts b/src/domain/work-orders/utils/wo-lifecycle-transitions.ts index 43a746d3..2a2ba7f5 100644 --- a/src/domain/work-orders/utils/wo-lifecycle-transitions.ts +++ b/src/domain/work-orders/utils/wo-lifecycle-transitions.ts @@ -173,7 +173,7 @@ export function withAutoScheduleStatus & ScheduleDateInput, ): Partial { const next = { - status: current.status ?? "", + status: schedulePatch.status ?? current.status ?? "", scheduledOn: schedulePatch.scheduledOn !== undefined ? schedulePatch.scheduledOn : current.scheduledOn, scheduleWeekOnly: @@ -181,6 +181,9 @@ export function withAutoScheduleStatus { }); it("allows selecting a non-Completed status", () => { - const onUpdate = vi.fn(); + const onPatch = vi.fn(); render( , ); @@ -74,6 +74,28 @@ describe("WizardStepVendorTime creation statuses (AAP)", () => { const menu = screen.getByRole("button", { name: /^pending$/i }).closest("div"); expect(menu).not.toBeNull(); fireEvent.click(within(menu!.parentElement!).getByRole("button", { name: /^pending$/i })); - expect(onUpdate).toHaveBeenCalledWith("status", "Pending"); + expect(onPatch).toHaveBeenCalledWith({ status: "Pending" }); + }); + + it("keeps Pending when picked on a dated draft", () => { + const onPatch = vi.fn(); + render( + , + ); + + fireEvent.click(screen.getByRole("button", { name: /scheduled/i })); + fireEvent.click(screen.getByRole("button", { name: /^pending$/i })); + expect(onPatch).toHaveBeenCalledWith({ status: "Pending" }); }); }); diff --git a/src/test/domain/work-orders/utils/wo-lifecycle-transitions.test.ts b/src/test/domain/work-orders/utils/wo-lifecycle-transitions.test.ts index bc2ce2ec..4a31e4e7 100644 --- a/src/test/domain/work-orders/utils/wo-lifecycle-transitions.test.ts +++ b/src/test/domain/work-orders/utils/wo-lifecycle-transitions.test.ts @@ -11,6 +11,7 @@ import { hasConcreteScheduleDate, maybeAutoSchedulePatch, mergeAutoSchedulePatch, + withAutoScheduleStatus, } from "@/domain/work-orders/utils/wo-lifecycle-transitions"; import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row"; @@ -103,6 +104,33 @@ describe("wo-lifecycle-transitions", () => { expect(mergeAutoSchedulePatch(row, { vendorId: "9" })).toEqual({ vendorId: "9" }); }); + it("keeps an explicit wizard status pick on a dated draft", () => { + const draft = { + status: "Scheduled", + scheduledOn: "2026-06-01", + scheduleWeekOnly: false, + }; + expect(withAutoScheduleStatus(draft, { status: "Pending" })).toEqual({ status: "Pending" }); + expect(withAutoScheduleStatus(draft, { status: "Incomplete" })).toEqual({ + status: "Incomplete", + }); + }); + + it("still derives Scheduled when a concrete date is set on a draft", () => { + const draft = { + status: "Pending", + scheduledOn: "", + scheduleWeekOnly: false, + }; + expect( + withAutoScheduleStatus(draft, { scheduledOn: "2026-06-02", scheduleWeekOnly: false }), + ).toEqual({ + scheduledOn: "2026-06-02", + scheduleWeekOnly: false, + status: "Scheduled", + }); + }); + it("keeps explicit status picks on dated rows", () => { const row = { status: "Scheduled",