fix(SH-357): reconcile Incomplete after clearing Schedule On

This commit is contained in:
Alexandre Brandizzi 2026-10-01 16:27:24 -03:00
parent cbb2edf2a6
commit d1b53105a2
5 changed files with 36 additions and 14 deletions

View file

@ -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 }),

View file

@ -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 {};

View file

@ -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,

View file

@ -162,6 +162,7 @@ describe("mapWizardDraftToBoardCreatePayload", () => {
type: "PM",
siteCode: "BK5",
status: "Scheduled",
scheduledOn: "2026-06-01",
});
expect(payload.lifecycleStatus).toBe(3);

View file

@ -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", () => {