diff --git a/e2e/work-orders/pending-status-menu.spec.ts b/e2e/work-orders/pending-status-menu.spec.ts index 43c86efa..c5b4d7f7 100644 --- a/e2e/work-orders/pending-status-menu.spec.ts +++ b/e2e/work-orders/pending-status-menu.spec.ts @@ -181,8 +181,9 @@ test.describe("existing work order status menu", () => { .click(); await page.getByRole("button", { name: "Continue" }).click(); - await page.getByRole("button", { name: "Incomplete", exact: true }).last().click(); + await page.getByRole("button", { name: "Pending", exact: true }).last().click(); const menu = page.locator(".MuiPopover-paper").last(); + await expect(menu.getByRole("button", { name: "Incomplete", exact: true })).toBeDisabled(); await expect(menu.getByRole("button", { name: "Pending", exact: true })).toBeEnabled(); await menu.getByRole("button", { name: "Pending", exact: true }).click(); await expect( @@ -228,8 +229,9 @@ test.describe("existing work order status menu", () => { .click(); await page.getByRole("button", { name: "Continue" }).click(); - await page.getByRole("button", { name: "Incomplete", exact: true }).last().click(); + await page.getByRole("button", { name: "Pending", exact: true }).last().click(); const menu = page.locator(".MuiPopover-paper").last(); + await expect(menu.getByRole("button", { name: "Incomplete", exact: true })).toBeDisabled(); await menu.getByRole("button", { name: "Pending", exact: true }).click(); await expect( page.getByRole("dialog").getByRole("button", { name: "Pending", exact: true }), diff --git a/src/domain/work-orders/utils/wo-lifecycle-transitions.ts b/src/domain/work-orders/utils/wo-lifecycle-transitions.ts index 0a5a0064..88a15ac6 100644 --- a/src/domain/work-orders/utils/wo-lifecycle-transitions.ts +++ b/src/domain/work-orders/utils/wo-lifecycle-transitions.ts @@ -162,7 +162,7 @@ export function maybeAutoSchedulePatch( if (hasDate && isPreScheduleStatus(row.status ?? "")) { return { status: "Scheduled" }; } - if (!hasDate && row.status === "Scheduled") { + if (!hasDate && (row.status === "Scheduled" || row.status === "Incomplete")) { return { status: "Pending" }; } return {}; diff --git a/src/test/domain/work-orders/api/work-orders-api.test.ts b/src/test/domain/work-orders/api/work-orders-api.test.ts index d6766be8..e8b97d15 100644 --- a/src/test/domain/work-orders/api/work-orders-api.test.ts +++ b/src/test/domain/work-orders/api/work-orders-api.test.ts @@ -134,7 +134,7 @@ describe("workOrdersApi.createFromBoard", () => { expect(apiPost).toHaveBeenCalledWith(API_PATHS.workOrder.boardCreate, { workOrderType: 2, siteCode: "BK5", - lifecycleStatus: 1, + lifecycleStatus: 2, woNumber: "12345", isAddOn: false, locationId: 9, diff --git a/src/test/domain/work-orders/mappers/work-order-board-mapper.test.ts b/src/test/domain/work-orders/mappers/work-order-board-mapper.test.ts index a9d41ed6..2ed6ba7a 100644 --- a/src/test/domain/work-orders/mappers/work-order-board-mapper.test.ts +++ b/src/test/domain/work-orders/mappers/work-order-board-mapper.test.ts @@ -162,6 +162,7 @@ describe("mapWizardDraftToBoardCreatePayload", () => { type: "PM", siteCode: "BK5", status: "Scheduled", + scheduledOn: "2026-06-01", }); expect(payload.lifecycleStatus).toBe(3); 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 5d0b4d77..0bed9384 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 @@ -6,6 +6,7 @@ import { COMPLETED_DOC_BLOCK_MSG, COMPLETED_MEDIA_BLOCK_MSG, CREATION_INLINE_STATUSES, + INCOMPLETE_NEEDS_DATE_MSG, PENDING_NEEDS_NO_DATE_MSG, SCHEDULED_NEEDS_DATE_MSG, formatAapCompletedBlockTitle, @@ -59,7 +60,17 @@ describe("wo-lifecycle-transitions", () => { expect(hasConcreteScheduleDate({ scheduledOn: "2026-06-01" })).toBe(true); }); - it("disables Scheduled without a concrete date", () => { + it("disables Incomplete and Scheduled without a concrete date", () => { + expect(getStatusOptionState({ scheduledOn: "" }, "Incomplete", [])).toEqual({ + disabled: true, + title: INCOMPLETE_NEEDS_DATE_MSG, + }); + expect( + getStatusOptionState({ scheduledOn: "2026-06-01", scheduleWeekOnly: true }, "Incomplete", []), + ).toEqual({ disabled: true, title: INCOMPLETE_NEEDS_DATE_MSG }); + expect(getStatusOptionState({ scheduledOn: "2026-06-01" }, "Incomplete", [])).toEqual({ + disabled: false, + }); expect(getStatusOptionState({ scheduledOn: "" }, "Scheduled", [])).toEqual({ disabled: true, title: SCHEDULED_NEEDS_DATE_MSG, @@ -102,14 +113,15 @@ describe("wo-lifecycle-transitions", () => { ).toEqual({ status: "Scheduled" }); }); - it("reverts Scheduled without a concrete date to Pending", () => { - expect( - maybeAutoSchedulePatch({ - status: "Scheduled", - scheduledOn: "", - scheduleWeekOnly: false, - }), - ).toEqual({ status: "Pending" }); + it("reverts Scheduled or Incomplete without a concrete date to Pending", () => { + for (const status of ["Scheduled", "Incomplete"]) { + expect(maybeAutoSchedulePatch({ status, scheduledOn: "", scheduleWeekOnly: false })).toEqual({ + status: "Pending", + }); + expect( + maybeAutoSchedulePatch({ status, scheduledOn: "2026-06-01", scheduleWeekOnly: true }), + ).toEqual({ status: "Pending" }); + } }); it("does not auto-change In Progress when a date exists", () => { @@ -180,7 +192,7 @@ describe("wo-lifecycle-transitions", () => { }); }); - it("still demotes Scheduled when the schedule is cleared", () => { + it("demotes Scheduled or Incomplete when the schedule is cleared", () => { const row = { status: "Scheduled", scheduledOn: "2026-06-01", @@ -191,6 +203,13 @@ describe("wo-lifecycle-transitions", () => { scheduleWeekOnly: false, status: "Pending", }); + expect(withAutoScheduleStatus({ ...row, status: "Incomplete" }, { scheduledOn: "" })).toEqual({ + scheduledOn: "", + status: "Pending", + }); + expect( + withAutoScheduleStatus({ ...row, status: "Incomplete" }, { scheduleWeekOnly: true }), + ).toEqual({ scheduleWeekOnly: true, status: "Pending" }); }); it("promotes a Pending create pick to Scheduled when the draft is dated", () => {