From f5414e4b1454899715c7bdc6cd4912b5fd4c42d8 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Mon, 3 Aug 2026 09:51:32 -0300 Subject: [PATCH 01/12] feat(work-orders): block completed when uplift is pending --- .../list/table/cells/status-cell.tsx | 52 +++++++---- .../mappers/work-order-table-row-mapper.ts | 46 ++++++++++ .../work-orders/types/work-order-table-row.ts | 8 ++ .../work-orders/utils/wo-closability.ts | 42 +++++++++ .../status-cell-pending-uplift.test.tsx | 90 +++++++++++++++++++ .../mappers/work-order-mapper.test.ts | 28 ++++++ .../work-orders/utils/wo-closability.test.ts | 74 +++++++++++++++ .../pr4-uplift-pending-close-gate.md | 30 +++++++ 8 files changed, 354 insertions(+), 16 deletions(-) create mode 100644 src/domain/work-orders/utils/wo-closability.ts create mode 100644 src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx create mode 100644 src/test/domain/work-orders/utils/wo-closability.test.ts create mode 100644 tmp/pr-descriptions/pr4-uplift-pending-close-gate.md diff --git a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx index d2e4c78a..7f4866bf 100644 --- a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx +++ b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx @@ -11,6 +11,10 @@ import { } from "@/domain/work-orders/types/work-order-wizard"; import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row"; +import { + formatClosabilityMissingTitle, + getClosabilityGaps, +} from "@/domain/work-orders/utils/wo-closability"; import { HoverChevron } from "./hover-chevron"; @@ -36,6 +40,7 @@ export function StatusCell({ onPastDueAttempt, }: StatusCellProps) { const [anchorEl, setAnchorEl] = useState(null); + const closabilityGaps = getClosabilityGaps(wo); if (wo.isPastDue) { return ( @@ -134,24 +139,39 @@ export function StatusCell({ onClick={(e) => e.stopPropagation()} slotProps={{ paper: { className: "min-w-[168px] rounded-lg border border-border p-1" } }} > - {ALL_WIZARD_STATUSES.map((status) => ( - - ))} + {wo.status === status && ( + + )} + + ); + })} ); diff --git a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts index a12162c2..cd411b3e 100644 --- a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts +++ b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts @@ -7,6 +7,7 @@ import { import type { CompletionDocStatus, WorkOrderTableRow, + WorkOrderUpliftSummary, } from "@/domain/work-orders/types/work-order-table-row"; import type { WOType } from "@/domain/work-orders/types/work-order-wizard"; import { deriveDayFields } from "@/domain/work-orders/utils/table-day-utils"; @@ -174,6 +175,47 @@ function readFlagColor(record: Record): string | null { return null; } +function readUpliftSummary(item: Record): WorkOrderUpliftSummary | undefined { + const nested = asRecord(item.upliftSummary ?? item.UpliftSummary); + const source = Object.keys(nested).length > 0 ? nested : item; + + const pendingCount = + readNumber(source, "pendingCount", "PendingCount") ?? + readNumber(item, "pendingUpliftCount", "PendingUpliftCount") ?? + 0; + const hasUplift = + readBool(source, "hasUplift", "HasUplift") || + readBool(item, "hasUplift", "HasUplift") || + pendingCount > 0; + + if (!hasUplift && pendingCount === 0) { + return undefined; + } + + const summary: WorkOrderUpliftSummary = { + hasUplift, + pendingCount, + }; + const primaryStatus = readString(source, "primaryStatus", "PrimaryStatus", "status", "Status"); + if (primaryStatus) { + summary.primaryStatus = primaryStatus; + } + return summary; +} + +function readHasPendingUplift( + item: Record, + upliftSummary: WorkOrderUpliftSummary | undefined, +): boolean | undefined { + if (readBool(item, "hasPendingUplift", "HasPendingUplift")) { + return true; + } + if ((upliftSummary?.pendingCount ?? 0) > 0) { + return true; + } + return undefined; +} + export function mapWorkOrderTableRow(raw: unknown): WorkOrderTableRow { const item = asRecord(raw); const scheduledOn = toDateInputValue( @@ -228,6 +270,8 @@ export function mapWorkOrderTableRow(raw: unknown): WorkOrderTableRow { const locationIdRaw = item.locationId ?? item.LocationId; const vendorIdNum = readNumber(item, "vendorId", "VendorId"); const primaryDispatchId = readNumber(item, "primaryDispatchId", "PrimaryDispatchId"); + const upliftSummary = readUpliftSummary(item); + const hasPendingUplift = readHasPendingUplift(item, upliftSummary); const row: WorkOrderTableRow = { id: readId(item), @@ -272,6 +316,8 @@ export function mapWorkOrderTableRow(raw: unknown): WorkOrderTableRow { rowVersion: readRowVersion(item, "rowVersion", "RowVersion"), dispatchRowVersion: readRowVersion(item, "dispatchRowVersion", "DispatchRowVersion"), flagColor: readFlagColor(item), + upliftSummary, + hasPendingUplift, }; return row; diff --git a/src/domain/work-orders/types/work-order-table-row.ts b/src/domain/work-orders/types/work-order-table-row.ts index 4bcb4b60..7e533a6b 100644 --- a/src/domain/work-orders/types/work-order-table-row.ts +++ b/src/domain/work-orders/types/work-order-table-row.ts @@ -4,6 +4,12 @@ export type CompletionDocStatus = "Yes" | "No" | "NN" | ""; export const WORK_ORDERS_TABLE_PAGE_SIZE = 100; +export type WorkOrderUpliftSummary = { + hasUplift: boolean; + pendingCount: number; + primaryStatus?: string; +}; + export interface WorkOrderTableRow { id: string | number; woNumber: string; @@ -49,6 +55,8 @@ export interface WorkOrderTableRow { dispatchRowVersion: string; /** Board flag color (#RRGGBB). Null/empty = no flag. Distinct from dispatcher avatar `color`. */ flagColor: string | null; + upliftSummary?: WorkOrderUpliftSummary | null; + hasPendingUplift?: boolean; } export interface WorkOrderTableDraft { diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts new file mode 100644 index 00000000..31c7d180 --- /dev/null +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -0,0 +1,42 @@ +import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row"; + +const PENDING_UPLIFT_GAP = "Pending uplift approval"; + +/** Fields required to evaluate whether a WO may be marked Completed or generate a comp doc. */ +export type WoClosabilityInput = Pick; + +export function hasPendingUplift(row: WoClosabilityInput): boolean { + if (row.hasPendingUplift === true) { + return true; + } + return (row.upliftSummary?.pendingCount ?? 0) > 0; +} + +/** + * Returns human-readable labels for requirements still missing before Completed is allowed. + * Empty array means the WO may be marked Completed (for closability gates implemented here). + */ +export function getClosabilityGaps(row: WoClosabilityInput): string[] { + if (hasPendingUplift(row)) { + return [PENDING_UPLIFT_GAP]; + } + return []; +} + +export function formatClosabilityMissingTitle(gaps: string[]): string { + return `Missing: ${gaps.join(", ")}`; +} + +export type CompDocGateResult = { allowed: true } | { allowed: false; reason: string }; + +/** + * Gate for completion-document generation. CompDocDialog (not yet on `dev`) should call this + * before opening generate flow and surface `reason` when blocked. + */ +export function canGenerateCompDoc(row: WoClosabilityInput): CompDocGateResult { + const gaps = getClosabilityGaps(row); + if (gaps.length > 0) { + return { allowed: false, reason: formatClosabilityMissingTitle(gaps) }; + } + return { allowed: true }; +} diff --git a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx new file mode 100644 index 00000000..11659ae9 --- /dev/null +++ b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx @@ -0,0 +1,90 @@ +import { fireEvent, screen } from "@testing-library/react"; +import { describe, expect, it, vi } from "vitest"; +import { StatusCell } from "@/app/(protected)/workorders/_components/list/table/cells/status-cell"; +import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row"; +import { renderWithProviders } from "@/test/test-utils"; + +function makeRow(overrides: Partial = {}): WorkOrderTableRow { + return { + id: 1, + woNumber: "1001", + site: "BK5", + type: "PM", + dispatcherId: "u1", + dispatcherName: "Alex", + scheduledOn: "2026-07-15", + targetWeek: "2026-07-15", + dayGroup: "07/15", + dayLabel: "Tue", + location: "Lobby", + locationId: "loc-1", + pm: "HVAC", + serviceNotes: "", + extraServices: [], + vendorId: "7", + company: "Acme", + tech: "Sam", + techPhone: "", + apptStart: "", + apptEnd: "", + apptTime: "", + status: "In Progress", + docStatus: "No", + pocName: "", + pocPhone: "", + pocNotes: "", + dueDate: "", + rescheduleCount: 0, + carriedOver: 0, + originalWeek: "", + originalDate: "", + isPastDue: false, + scheduleWeekOnly: false, + mediaCount: 0, + title: "", + priority: "", + primaryDispatchId: null, + rowVersion: "", + dispatchRowVersion: "", + flagColor: null, + ...overrides, + }; +} + +describe("StatusCell pending uplift closability", () => { + it("disables Completed with tooltip when uplift is pending", () => { + const onChangeStatus = vi.fn(); + + renderWithProviders( + , + { withAuth: false }, + ); + + fireEvent.click(screen.getByRole("button", { name: /in progress/i })); + + const completed = screen.getByRole("button", { name: /completed/i }); + expect(completed).toBeDisabled(); + expect(completed).toHaveAttribute("title", "Missing: Pending uplift approval"); + + fireEvent.click(completed); + expect(onChangeStatus).not.toHaveBeenCalled(); + }); + + it("allows Completed when no pending uplift", () => { + const onChangeStatus = vi.fn(); + + renderWithProviders( + , + { withAuth: false }, + ); + + fireEvent.click(screen.getByRole("button", { name: /in progress/i })); + fireEvent.click(screen.getByRole("button", { name: /completed/i })); + + expect(onChangeStatus).toHaveBeenCalledWith("Completed"); + }); +}); diff --git a/src/test/domain/work-orders/mappers/work-order-mapper.test.ts b/src/test/domain/work-orders/mappers/work-order-mapper.test.ts index 63a92912..1b3baa4e 100644 --- a/src/test/domain/work-orders/mappers/work-order-mapper.test.ts +++ b/src/test/domain/work-orders/mappers/work-order-mapper.test.ts @@ -135,4 +135,32 @@ describe("mapWorkOrderTableRow (board DTO)", () => { expect(mapWorkOrderTableRow({ id: 1, flagColor: "" }).flagColor).toBeNull(); expect(mapWorkOrderTableRow({ id: 1, FlagColor: "#3B82F6" }).flagColor).toBe("#3B82F6"); }); + + it("maps uplift summary and pending flag from API payload", () => { + const row = mapWorkOrderTableRow({ + id: 303, + upliftSummary: { + hasUplift: true, + pendingCount: 2, + primaryStatus: "pending", + }, + }); + + expect(row.upliftSummary).toEqual({ + hasUplift: true, + pendingCount: 2, + primaryStatus: "pending", + }); + expect(row.hasPendingUplift).toBe(true); + }); + + it("maps hasPendingUplift from top-level API flag", () => { + const row = mapWorkOrderTableRow({ + id: 304, + hasPendingUplift: true, + }); + + expect(row.hasPendingUplift).toBe(true); + expect(row.upliftSummary).toBeUndefined(); + }); }); diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts new file mode 100644 index 00000000..f3a3a353 --- /dev/null +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -0,0 +1,74 @@ +import { describe, expect, it } from "vitest"; +import type { WoClosabilityInput } from "@/domain/work-orders/utils/wo-closability"; +import { + canGenerateCompDoc, + formatClosabilityMissingTitle, + getClosabilityGaps, + hasPendingUplift, +} from "@/domain/work-orders/utils/wo-closability"; + +function makeInput(overrides: Partial = {}): WoClosabilityInput { + return { + upliftSummary: undefined, + hasPendingUplift: undefined, + ...overrides, + }; +} + +describe("hasPendingUplift", () => { + it("is true when hasPendingUplift flag is set", () => { + expect(hasPendingUplift(makeInput({ hasPendingUplift: true }))).toBe(true); + }); + + it("is true when upliftSummary.pendingCount is positive", () => { + expect( + hasPendingUplift(makeInput({ upliftSummary: { hasUplift: true, pendingCount: 2 } })), + ).toBe(true); + }); + + it("is false when no uplift signals are present", () => { + expect(hasPendingUplift(makeInput())).toBe(false); + expect( + hasPendingUplift(makeInput({ upliftSummary: { hasUplift: false, pendingCount: 0 } })), + ).toBe(false); + }); +}); + +describe("getClosabilityGaps", () => { + it("returns empty when no pending uplift", () => { + expect(getClosabilityGaps(makeInput())).toEqual([]); + }); + + it("blocks Completed when uplift is pending via summary", () => { + expect( + getClosabilityGaps(makeInput({ upliftSummary: { hasUplift: true, pendingCount: 1 } })), + ).toEqual(["Pending uplift approval"]); + }); + + it("blocks Completed when hasPendingUplift is true", () => { + expect(getClosabilityGaps(makeInput({ hasPendingUplift: true }))).toEqual([ + "Pending uplift approval", + ]); + }); +}); + +describe("formatClosabilityMissingTitle", () => { + it("joins gaps for tooltip copy", () => { + expect(formatClosabilityMissingTitle(["Pending uplift approval"])).toBe( + "Missing: Pending uplift approval", + ); + }); +}); + +describe("canGenerateCompDoc", () => { + it("allows generation when no closability gaps", () => { + expect(canGenerateCompDoc(makeInput())).toEqual({ allowed: true }); + }); + + it("blocks generation with reason when pending uplift exists", () => { + expect(canGenerateCompDoc(makeInput({ hasPendingUplift: true }))).toEqual({ + allowed: false, + reason: "Missing: Pending uplift approval", + }); + }); +}); diff --git a/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md b/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md new file mode 100644 index 00000000..d9bf1215 --- /dev/null +++ b/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md @@ -0,0 +1,30 @@ +# PR4 — Pending uplift close gate + +## Summary + +Blocks marking a work order **Completed** (and future completion-document generation) while an uplift request is still pending approval. + +- Adds optional `upliftSummary` / `hasPendingUplift` on `WorkOrderTableRow`, mapped from the board API when present. +- Introduces `getClosabilityGaps`, `formatClosabilityMissingTitle`, and `canGenerateCompDoc` in `wo-closability.ts` (pending-uplift scope only on this base). +- Wires the board **Status** popover to disable **Completed** with tooltip `Missing: Pending uplift approval` when a gap exists. + +## Comp Doc Generate + +`CompDocDialog` is **not** mounted on `dev` yet. This PR exports `canGenerateCompDoc(row)` so the completion-doc slice can block generate/open with the same reason string. No UI wiring in this PR. + +## Out of scope + +- Full uplift CRUD (PR3) +- Advanced filter facets for uplift +- Full closability matrix (dispatcher, comp doc, photos, etc.) — separate gate work + +## Test plan + +- [ ] Row with `hasPendingUplift: true` — Status menu shows Completed disabled; tooltip explains missing pending uplift approval. +- [ ] Row without pending uplift — Completed remains selectable. +- [ ] `canGenerateCompDoc` returns `{ allowed: false, reason: "Missing: Pending uplift approval" }` when pending uplift is present. +- [ ] Board API payload with `upliftSummary.pendingCount > 0` maps through to closability gate. + +## Base + +Branch `feature/wo-uplift-pending-close-gate` from local `dev`. Does not depend on PR3 branch git-wise; uplift fields are optional stubs until BE/PR3 land. From 6b415f732c7d6660d385b6a98e120e0e68a19d51 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Mon, 3 Aug 2026 13:43:35 -0300 Subject: [PATCH 02/12] fix(work-orders): unify closability with sh-114 and pending uplift --- .../list/table/cells/status-cell.tsx | 14 ++- .../mappers/work-order-table-row-mapper.ts | 3 + .../work-orders/types/work-order-table-row.ts | 2 + .../work-orders/utils/wo-closability.ts | 115 ++++++++++++++++-- .../status-cell-pending-uplift.test.tsx | 10 +- .../work-orders/utils/wo-closability.test.ts | 77 ++++++++++-- .../pr4-uplift-pending-close-gate.md | 31 +++-- 7 files changed, 217 insertions(+), 35 deletions(-) diff --git a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx index 7f4866bf..28049593 100644 --- a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx +++ b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx @@ -40,7 +40,19 @@ export function StatusCell({ onPastDueAttempt, }: StatusCellProps) { const [anchorEl, setAnchorEl] = useState(null); - const closabilityGaps = getClosabilityGaps(wo); + const closabilityGaps = getClosabilityGaps({ + dispatcherId: wo.dispatcherId, + dispatcherName: wo.dispatcherName, + tech: wo.tech, + completedDate: wo.completedDate ?? "", + woNumber: wo.woNumber, + pm: wo.pm, + docStatus: wo.docStatus, + mediaCount: wo.mediaCount, + type: wo.type, + upliftSummary: wo.upliftSummary, + hasPendingUplift: wo.hasPendingUplift, + }); if (wo.isPastDue) { return ( diff --git a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts index cd411b3e..3b9fc66b 100644 --- a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts +++ b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts @@ -281,6 +281,9 @@ export function mapWorkOrderTableRow(raw: unknown): WorkOrderTableRow { dispatcherId, dispatcherName, scheduledOn, + completedDate: toDateInputValue( + readString(item, "completedDate", "CompletedDate", "completedOn", "CompletedOn"), + ), targetWeek: toDateInputValue(readString(item, "targetWeek", "TargetWeek")), dayGroup, dayLabel, diff --git a/src/domain/work-orders/types/work-order-table-row.ts b/src/domain/work-orders/types/work-order-table-row.ts index 7e533a6b..ff18a232 100644 --- a/src/domain/work-orders/types/work-order-table-row.ts +++ b/src/domain/work-orders/types/work-order-table-row.ts @@ -18,6 +18,8 @@ export interface WorkOrderTableRow { dispatcherId: string; dispatcherName: string; scheduledOn: string; + /** Work completed date (API CompletedDate); used by closability / COMPLETED DATE column. */ + completedDate?: string; targetWeek: string; dayGroup: string; dayLabel: string; diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 31c7d180..5f1c67c6 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -1,29 +1,109 @@ -import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row"; +import type { + CompletionDocStatus, + WorkOrderUpliftSummary, +} from "@/domain/work-orders/types/work-order-table-row"; +import type { WOType, WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard"; -const PENDING_UPLIFT_GAP = "Pending uplift approval"; +/** Fields required to evaluate whether a WO may be marked Completed (SH-114 ∪ pending uplift). */ +export type WoClosabilityInput = { + dispatcherId: string; + dispatcherName: string; + /** Vendor / technician assignment on the board row. */ + tech: string; + /** Work completed date (API CompletedDate). Empty until set. */ + completedDate: string; + woNumber: string; + pm: string; + docStatus: CompletionDocStatus; + mediaCount: number; + type: WOType | ""; + upliftSummary?: WorkOrderUpliftSummary | null; + hasPendingUplift?: boolean; +}; -/** Fields required to evaluate whether a WO may be marked Completed or generate a comp doc. */ -export type WoClosabilityInput = Pick; +export const PENDING_UPLIFT_GAP = "Pending uplift approval"; -export function hasPendingUplift(row: WoClosabilityInput): boolean { +/** Design copy when Completed is blocked solely by a pending uplift. */ +export const UPLIFT_PENDING_COMPLETED_TITLE = + "This work order cannot be completed while an uplift is pending approval."; + +/** Real (non-placeholder) WO number — non-empty and not an SH-prefixed draft id. */ +export function isRealWoNumber(woNumber: string): boolean { + const trimmed = woNumber.trim(); + if (!trimmed) { + return false; + } + return !/^SH/i.test(trimmed); +} + +export function hasPendingUplift( + row: Pick, +): boolean { if (row.hasPendingUplift === true) { return true; } return (row.upliftSummary?.pendingCount ?? 0) > 0; } +function hasDispatcher(row: Pick): boolean { + return Boolean(row.dispatcherId.trim() || row.dispatcherName.trim()); +} + +function hasService(pm: string): boolean { + return Boolean(pm.trim()); +} + +function hasCompletionDocument(docStatus: CompletionDocStatus): boolean { + return docStatus === "Yes" || docStatus === "NN"; +} + /** - * Returns human-readable labels for requirements still missing before Completed is allowed. - * Empty array means the WO may be marked Completed (for closability gates implemented here). + * Gaps that block Completed, in design hierarchy: + * fields → uplift pending → completion document / photos. + * (Scheduled-date gate is a separate design P1 — not in this module yet.) */ export function getClosabilityGaps(row: WoClosabilityInput): string[] { - if (hasPendingUplift(row)) { - return [PENDING_UPLIFT_GAP]; + const gaps: string[] = []; + + if (!hasDispatcher(row)) { + gaps.push("Dispatcher"); } - return []; + if (!row.tech.trim()) { + gaps.push("Technician"); + } + if (!row.completedDate.trim()) { + gaps.push("Completed Date"); + } + if (!isRealWoNumber(row.woNumber)) { + gaps.push("WO number"); + } + if (!hasService(row.pm)) { + gaps.push("Service"); + } + + if (hasPendingUplift(row)) { + gaps.push(PENDING_UPLIFT_GAP); + } + + if (row.type === "PM" || row.type === "Overdue") { + if (!hasCompletionDocument(row.docStatus)) { + gaps.push("Completion document"); + } + } + + if (row.type === "Emergency" || row.type === "Reactive") { + if (row.mediaCount < 1) { + gaps.push("At least 1 photo"); + } + } + + return gaps; } export function formatClosabilityMissingTitle(gaps: string[]): string { + if (gaps.length === 1 && gaps[0] === PENDING_UPLIFT_GAP) { + return UPLIFT_PENDING_COMPLETED_TITLE; + } return `Missing: ${gaps.join(", ")}`; } @@ -40,3 +120,18 @@ export function canGenerateCompDoc(row: WoClosabilityInput): CompDocGateResult { } return { allowed: true }; } + +/** Map create-wizard draft onto the shared closability contract. */ +export function wizardDraftToClosabilityInput(draft: WorkOrderWizardDraft): WoClosabilityInput { + return { + dispatcherId: draft.assigneeId, + dispatcherName: draft.assigneeName, + tech: draft.vendorName, + completedDate: "", + woNumber: draft.woNumber, + pm: draft.pm, + docStatus: "", + mediaCount: 0, + type: draft.type, + }; +} diff --git a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx index 11659ae9..998b2680 100644 --- a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx +++ b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx @@ -13,6 +13,7 @@ function makeRow(overrides: Partial = {}): WorkOrderTableRow dispatcherId: "u1", dispatcherName: "Alex", scheduledOn: "2026-07-15", + completedDate: "2026-07-20", targetWeek: "2026-07-15", dayGroup: "07/15", dayLabel: "Tue", @@ -29,7 +30,7 @@ function makeRow(overrides: Partial = {}): WorkOrderTableRow apptEnd: "", apptTime: "", status: "In Progress", - docStatus: "No", + docStatus: "Yes", pocName: "", pocPhone: "", pocNotes: "", @@ -40,7 +41,7 @@ function makeRow(overrides: Partial = {}): WorkOrderTableRow originalDate: "", isPastDue: false, scheduleWeekOnly: false, - mediaCount: 0, + mediaCount: 1, title: "", priority: "", primaryDispatchId: null, @@ -68,7 +69,10 @@ describe("StatusCell pending uplift closability", () => { const completed = screen.getByRole("button", { name: /completed/i }); expect(completed).toBeDisabled(); - expect(completed).toHaveAttribute("title", "Missing: Pending uplift approval"); + expect(completed).toHaveAttribute( + "title", + "This work order cannot be completed while an uplift is pending approval.", + ); fireEvent.click(completed); expect(onChangeStatus).not.toHaveBeenCalled(); diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index f3a3a353..c0b24abb 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -1,20 +1,41 @@ import { describe, expect, it } from "vitest"; import type { WoClosabilityInput } from "@/domain/work-orders/utils/wo-closability"; import { + PENDING_UPLIFT_GAP, + UPLIFT_PENDING_COMPLETED_TITLE, canGenerateCompDoc, formatClosabilityMissingTitle, getClosabilityGaps, hasPendingUplift, + isRealWoNumber, } from "@/domain/work-orders/utils/wo-closability"; function makeInput(overrides: Partial = {}): WoClosabilityInput { return { + dispatcherId: "u1", + dispatcherName: "Alex", + tech: "Sam", + completedDate: "2026-07-01", + woNumber: "1001", + pm: "HVAC", + docStatus: "Yes", + mediaCount: 1, + type: "PM", upliftSummary: undefined, hasPendingUplift: undefined, ...overrides, }; } +describe("isRealWoNumber", () => { + it("rejects empty and SH-prefixed provisional numbers", () => { + expect(isRealWoNumber("")).toBe(false); + expect(isRealWoNumber("SH-9")).toBe(false); + expect(isRealWoNumber("sh123")).toBe(false); + expect(isRealWoNumber("98765")).toBe(true); + }); +}); + describe("hasPendingUplift", () => { it("is true when hasPendingUplift flag is set", () => { expect(hasPendingUplift(makeInput({ hasPendingUplift: true }))).toBe(true); @@ -35,27 +56,63 @@ describe("hasPendingUplift", () => { }); describe("getClosabilityGaps", () => { - it("returns empty when no pending uplift", () => { + it("returns empty when all gates are satisfied", () => { expect(getClosabilityGaps(makeInput())).toEqual([]); }); + it("lists field gaps before uplift and document gaps", () => { + expect( + getClosabilityGaps( + makeInput({ + dispatcherId: "", + dispatcherName: "", + tech: " ", + completedDate: "", + woNumber: "SH-1", + pm: "", + hasPendingUplift: true, + docStatus: "No", + type: "PM", + }), + ), + ).toEqual([ + "Dispatcher", + "Technician", + "Completed Date", + "WO number", + "Service", + PENDING_UPLIFT_GAP, + "Completion document", + ]); + }); + it("blocks Completed when uplift is pending via summary", () => { expect( getClosabilityGaps(makeInput({ upliftSummary: { hasUplift: true, pendingCount: 1 } })), - ).toEqual(["Pending uplift approval"]); + ).toEqual([PENDING_UPLIFT_GAP]); }); it("blocks Completed when hasPendingUplift is true", () => { - expect(getClosabilityGaps(makeInput({ hasPendingUplift: true }))).toEqual([ - "Pending uplift approval", - ]); + expect(getClosabilityGaps(makeInput({ hasPendingUplift: true }))).toEqual([PENDING_UPLIFT_GAP]); + }); + + it("requires a photo for Emergency / Reactive", () => { + expect( + getClosabilityGaps(makeInput({ type: "Emergency", mediaCount: 0, docStatus: "No" })), + ).toEqual(["At least 1 photo"]); }); }); describe("formatClosabilityMissingTitle", () => { - it("joins gaps for tooltip copy", () => { - expect(formatClosabilityMissingTitle(["Pending uplift approval"])).toBe( - "Missing: Pending uplift approval", + it("uses design Completed title when only uplift is missing", () => { + expect(formatClosabilityMissingTitle([PENDING_UPLIFT_GAP])).toBe( + UPLIFT_PENDING_COMPLETED_TITLE, + ); + }); + + it("joins multiple gaps with Missing prefix", () => { + expect(formatClosabilityMissingTitle(["Dispatcher", PENDING_UPLIFT_GAP])).toBe( + `Missing: Dispatcher, ${PENDING_UPLIFT_GAP}`, ); }); }); @@ -65,10 +122,10 @@ describe("canGenerateCompDoc", () => { expect(canGenerateCompDoc(makeInput())).toEqual({ allowed: true }); }); - it("blocks generation with reason when pending uplift exists", () => { + it("blocks generation with design reason when only pending uplift exists", () => { expect(canGenerateCompDoc(makeInput({ hasPendingUplift: true }))).toEqual({ allowed: false, - reason: "Missing: Pending uplift approval", + reason: UPLIFT_PENDING_COMPLETED_TITLE, }); }); }); diff --git a/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md b/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md index d9bf1215..13a8b08c 100644 --- a/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md +++ b/tmp/pr-descriptions/pr4-uplift-pending-close-gate.md @@ -1,12 +1,19 @@ -# PR4 — Pending uplift close gate +# PR4 — Pending uplift close gate (+ SH-114 closability union) ## Summary -Blocks marking a work order **Completed** (and future completion-document generation) while an uplift request is still pending approval. +Blocks marking a work order **Completed** (and future completion-document generation) when closability gaps remain — **SH-114 field gates ∪ pending uplift** (SH-188). -- Adds optional `upliftSummary` / `hasPendingUplift` on `WorkOrderTableRow`, mapped from the board API when present. -- Introduces `getClosabilityGaps`, `formatClosabilityMissingTitle`, and `canGenerateCompDoc` in `wo-closability.ts` (pending-uplift scope only on this base). -- Wires the board **Status** popover to disable **Completed** with tooltip `Missing: Pending uplift approval` when a gap exists. +- Unifies `wo-closability.ts` / `getClosabilityGaps` with hierarchy: **fields → uplift pending → completion document / photos**. +- Field gates: dispatcher, technician, completed date, real WO# (non-SH), service; then PM/Overdue completion doc; Emergency/Reactive ≥1 photo. +- Pending uplift via `hasPendingUplift` or `upliftSummary.pendingCount`. +- Completed tooltip uses design copy when the **only** gap is pending uplift. +- Maps optional `completedDate` on board rows for the Completed Date gate. + +## Jira + +- [SH-188](https://luby-us.atlassian.net/browse/SH-188) — pending uplift close gate +- Related: [SH-114](https://luby-us.atlassian.net/browse/SH-114) — closability field matrix (pulled into this branch so sister merges do not wipe gates) ## Comp Doc Generate @@ -16,15 +23,17 @@ Blocks marking a work order **Completed** (and future completion-document genera - Full uplift CRUD (PR3) - Advanced filter facets for uplift -- Full closability matrix (dispatcher, comp doc, photos, etc.) — separate gate work +- Scheduled-requires-date gate (design P1) +- COL_HELP tooltips (P1) ## Test plan -- [ ] Row with `hasPendingUplift: true` — Status menu shows Completed disabled; tooltip explains missing pending uplift approval. -- [ ] Row without pending uplift — Completed remains selectable. -- [ ] `canGenerateCompDoc` returns `{ allowed: false, reason: "Missing: Pending uplift approval" }` when pending uplift is present. -- [ ] Board API payload with `upliftSummary.pendingCount > 0` maps through to closability gate. +- [ ] Row with all fields ok + `hasPendingUplift: true` — Completed disabled; design tooltip about pending uplift. +- [ ] Row missing dispatcher / completed date — Completed disabled; `Missing: …` tooltip. +- [ ] Row fully closable — Completed selectable. +- [ ] `canGenerateCompDoc` blocked when gaps exist. +- [ ] Board API `completedDate` / `upliftSummary.pendingCount` map through to the gate. ## Base -Branch `feature/wo-uplift-pending-close-gate` from local `dev`. Does not depend on PR3 branch git-wise; uplift fields are optional stubs until BE/PR3 land. +Branch `feature/wo-uplift-pending-close-gate` from local `dev`. Merge **before** or instead of stacking raw SH-114 alone with an uplift-only closability overwrite. From ccfb3d9e6d0662f136e24eab359e33787ab80014 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Mon, 3 Aug 2026 14:13:51 -0300 Subject: [PATCH 03/12] fix(work-orders): split status cell to satisfy max-lines-per-function --- .../list/table/cells/status-cell.tsx | 173 +++++++++--------- 1 file changed, 85 insertions(+), 88 deletions(-) diff --git a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx index 28049593..67d826ee 100644 --- a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx +++ b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx @@ -1,46 +1,28 @@ import { useState } from "react"; - import { AlertTriangle, Check } from "lucide-react"; - import { Popover } from "@mui/material"; import { Text } from "@/components/ui/text"; - import { ALL_WIZARD_STATUSES, type WizardWOStatus, } from "@/domain/work-orders/types/work-order-wizard"; - import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row"; import { formatClosabilityMissingTitle, getClosabilityGaps, } from "@/domain/work-orders/utils/wo-closability"; - import { HoverChevron } from "./hover-chevron"; - import { WoTableStatusLabel } from "./wo-table-status-label"; type StatusCellProps = { wo: WorkOrderTableRow; - onChangeStatus: (status: WizardWOStatus) => void; - onOpenSlideOver: () => void; - onPastDueAttempt?: () => void; }; -export function StatusCell({ - wo, - - onChangeStatus, - - onOpenSlideOver, - - onPastDueAttempt, -}: StatusCellProps) { - const [anchorEl, setAnchorEl] = useState(null); - const closabilityGaps = getClosabilityGaps({ +function rowClosabilityGaps(wo: WorkOrderTableRow) { + return getClosabilityGaps({ dispatcherId: wo.dispatcherId, dispatcherName: wo.dispatcherName, tech: wo.tech, @@ -53,73 +35,91 @@ export function StatusCell({ upliftSummary: wo.upliftSummary, hasPendingUplift: wo.hasPendingUplift, }); +} + +function PastDueStatusCell({ + onOpenSlideOver, + onPastDueAttempt, +}: { + onOpenSlideOver: () => void; + onPastDueAttempt?: () => void; +}) { + const [anchorEl, setAnchorEl] = useState(null); + + return ( + <> + + + setAnchorEl(null)} + anchorOrigin={{ vertical: "bottom", horizontal: "left" }} + onClick={(e) => e.stopPropagation()} + slotProps={{ + paper: { className: "w-[264px] overflow-hidden rounded-lg border border-border p-0" }, + }} + > +
+ +
+ + This work order is past due. Update the Due Date before the status can be updated. + + +
+
+
+ + ); +} + +export function StatusCell({ + wo, + onChangeStatus, + onOpenSlideOver, + onPastDueAttempt, +}: StatusCellProps) { + const [anchorEl, setAnchorEl] = useState(null); + const closabilityGaps = rowClosabilityGaps(wo); if (wo.isPastDue) { return ( - <> - - - setAnchorEl(null)} - anchorOrigin={{ vertical: "bottom", horizontal: "left" }} - onClick={(e) => e.stopPropagation()} - slotProps={{ - paper: { className: "w-[264px] overflow-hidden rounded-lg border border-border p-0" }, - }} - > -
- - -
- - This work order is past due. Update the Due Date before the status can be updated. - - - -
-
-
- + ); } @@ -129,7 +129,6 @@ export function StatusCell({ type="button" onClick={(e) => { e.stopPropagation(); - setAnchorEl(e.currentTarget); }} className="group/cell flex w-full items-center gap-1 transition-opacity hover:opacity-80" @@ -139,7 +138,6 @@ export function StatusCell({ ) : ( — )} - @@ -177,8 +175,7 @@ export function StatusCell({ } > - - {wo.status === status && ( + {Boolean(wo.status === status) && ( )} From a3e9a20477283f98a4bfe2af34332c6e9a9e0a8b Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Tue, 4 Aug 2026 11:42:44 -0300 Subject: [PATCH 04/12] fix(work-orders): fail closed on unknown uplift status --- .../list/table/cells/status-cell.tsx | 1 + .../work-orders/utils/wo-closability.ts | 20 ++++++++++++---- .../work-orders/utils/wo-closability.test.ts | 24 +++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx index 67d826ee..ddcdbc5e 100644 --- a/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx +++ b/src/app/(protected)/workorders/_components/list/table/cells/status-cell.tsx @@ -25,6 +25,7 @@ function rowClosabilityGaps(wo: WorkOrderTableRow) { return getClosabilityGaps({ dispatcherId: wo.dispatcherId, dispatcherName: wo.dispatcherName, + company: wo.company, tech: wo.tech, completedDate: wo.completedDate ?? "", woNumber: wo.woNumber, diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 5f1c67c6..606f9369 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -8,7 +8,9 @@ import type { WOType, WorkOrderWizardDraft } from "@/domain/work-orders/types/wo export type WoClosabilityInput = { dispatcherId: string; dispatcherName: string; - /** Vendor / technician assignment on the board row. */ + /** Vendor/company assignment on the board row. */ + company: string; + /** Technician name is informational and does not satisfy the vendor requirement. */ tech: string; /** Work completed date (API CompletedDate). Empty until set. */ completedDate: string; @@ -22,6 +24,7 @@ export type WoClosabilityInput = { }; export const PENDING_UPLIFT_GAP = "Pending uplift approval"; +export const UPLIFT_STATUS_UNAVAILABLE_GAP = "Uplift status unavailable"; /** Design copy when Completed is blocked solely by a pending uplift. */ export const UPLIFT_PENDING_COMPLETED_TITLE = @@ -45,6 +48,12 @@ export function hasPendingUplift( return (row.upliftSummary?.pendingCount ?? 0) > 0; } +function hasKnownUpliftStatus( + row: Pick, +): boolean { + return typeof row.hasPendingUplift === "boolean" || row.upliftSummary != null; +} + function hasDispatcher(row: Pick): boolean { return Boolean(row.dispatcherId.trim() || row.dispatcherName.trim()); } @@ -68,8 +77,8 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { if (!hasDispatcher(row)) { gaps.push("Dispatcher"); } - if (!row.tech.trim()) { - gaps.push("Technician"); + if (!row.company.trim()) { + gaps.push("Company / vendor"); } if (!row.completedDate.trim()) { gaps.push("Completed Date"); @@ -81,7 +90,9 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { gaps.push("Service"); } - if (hasPendingUplift(row)) { + if (!hasKnownUpliftStatus(row)) { + gaps.push(UPLIFT_STATUS_UNAVAILABLE_GAP); + } else if (hasPendingUplift(row)) { gaps.push(PENDING_UPLIFT_GAP); } @@ -126,6 +137,7 @@ export function wizardDraftToClosabilityInput(draft: WorkOrderWizardDraft): WoCl return { dispatcherId: draft.assigneeId, dispatcherName: draft.assigneeName, + company: draft.vendorName, tech: draft.vendorName, completedDate: "", woNumber: draft.woNumber, diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index c0b24abb..079ac992 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"; import type { WoClosabilityInput } from "@/domain/work-orders/utils/wo-closability"; import { PENDING_UPLIFT_GAP, + UPLIFT_STATUS_UNAVAILABLE_GAP, UPLIFT_PENDING_COMPLETED_TITLE, canGenerateCompDoc, formatClosabilityMissingTitle, @@ -14,6 +15,7 @@ function makeInput(overrides: Partial = {}): WoClosabilityIn return { dispatcherId: "u1", dispatcherName: "Alex", + company: "Acme HVAC", tech: "Sam", completedDate: "2026-07-01", woNumber: "1001", @@ -21,8 +23,7 @@ function makeInput(overrides: Partial = {}): WoClosabilityIn docStatus: "Yes", mediaCount: 1, type: "PM", - upliftSummary: undefined, - hasPendingUplift: undefined, + hasPendingUplift: false, ...overrides, }; } @@ -47,7 +48,7 @@ describe("hasPendingUplift", () => { ).toBe(true); }); - it("is false when no uplift signals are present", () => { + it("is false when uplift is explicitly not pending", () => { expect(hasPendingUplift(makeInput())).toBe(false); expect( hasPendingUplift(makeInput({ upliftSummary: { hasUplift: false, pendingCount: 0 } })), @@ -60,12 +61,21 @@ describe("getClosabilityGaps", () => { expect(getClosabilityGaps(makeInput())).toEqual([]); }); + it("accepts a company without a technician", () => { + expect(getClosabilityGaps(makeInput({ tech: "" }))).toEqual([]); + }); + + it("does not let a technician satisfy a missing company requirement", () => { + expect(getClosabilityGaps(makeInput({ company: "" }))).toEqual(["Company / vendor"]); + }); + it("lists field gaps before uplift and document gaps", () => { expect( getClosabilityGaps( makeInput({ dispatcherId: "", dispatcherName: "", + company: " ", tech: " ", completedDate: "", woNumber: "SH-1", @@ -77,7 +87,7 @@ describe("getClosabilityGaps", () => { ), ).toEqual([ "Dispatcher", - "Technician", + "Company / vendor", "Completed Date", "WO number", "Service", @@ -96,6 +106,12 @@ describe("getClosabilityGaps", () => { expect(getClosabilityGaps(makeInput({ hasPendingUplift: true }))).toEqual([PENDING_UPLIFT_GAP]); }); + it("blocks Completed when the backend does not provide uplift status", () => { + expect( + getClosabilityGaps(makeInput({ hasPendingUplift: undefined, upliftSummary: undefined })), + ).toEqual([UPLIFT_STATUS_UNAVAILABLE_GAP]); + }); + it("requires a photo for Emergency / Reactive", () => { expect( getClosabilityGaps(makeInput({ type: "Emergency", mediaCount: 0, docStatus: "No" })), From 67c4ee81190b187e81a9d0e888995eb6487819c2 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Tue, 4 Aug 2026 14:49:16 -0300 Subject: [PATCH 05/12] fix(work-orders): only block Completed on evidenced pending uplift Absence of optional uplift fields means no pending, per SH-188. --- src/domain/work-orders/utils/wo-closability.ts | 12 ++---------- .../domain/work-orders/utils/wo-closability.test.ts | 5 ++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 606f9369..24617591 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -24,7 +24,6 @@ export type WoClosabilityInput = { }; export const PENDING_UPLIFT_GAP = "Pending uplift approval"; -export const UPLIFT_STATUS_UNAVAILABLE_GAP = "Uplift status unavailable"; /** Design copy when Completed is blocked solely by a pending uplift. */ export const UPLIFT_PENDING_COMPLETED_TITLE = @@ -48,12 +47,6 @@ export function hasPendingUplift( return (row.upliftSummary?.pendingCount ?? 0) > 0; } -function hasKnownUpliftStatus( - row: Pick, -): boolean { - return typeof row.hasPendingUplift === "boolean" || row.upliftSummary != null; -} - function hasDispatcher(row: Pick): boolean { return Boolean(row.dispatcherId.trim() || row.dispatcherName.trim()); } @@ -90,9 +83,8 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { gaps.push("Service"); } - if (!hasKnownUpliftStatus(row)) { - gaps.push(UPLIFT_STATUS_UNAVAILABLE_GAP); - } else if (hasPendingUplift(row)) { + // Only an actually pending uplift blocks completion; missing uplift fields mean no pending evidence. + if (hasPendingUplift(row)) { gaps.push(PENDING_UPLIFT_GAP); } diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index 079ac992..a55938e7 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest"; import type { WoClosabilityInput } from "@/domain/work-orders/utils/wo-closability"; import { PENDING_UPLIFT_GAP, - UPLIFT_STATUS_UNAVAILABLE_GAP, UPLIFT_PENDING_COMPLETED_TITLE, canGenerateCompDoc, formatClosabilityMissingTitle, @@ -106,10 +105,10 @@ describe("getClosabilityGaps", () => { expect(getClosabilityGaps(makeInput({ hasPendingUplift: true }))).toEqual([PENDING_UPLIFT_GAP]); }); - it("blocks Completed when the backend does not provide uplift status", () => { + it("allows Completed when uplift status fields are absent (no pending evidence)", () => { expect( getClosabilityGaps(makeInput({ hasPendingUplift: undefined, upliftSummary: undefined })), - ).toEqual([UPLIFT_STATUS_UNAVAILABLE_GAP]); + ).toEqual([]); }); it("requires a photo for Emergency / Reactive", () => { From dd60b1d72e24de8bfce296f96518ead7158713d8 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Mon, 10 Aug 2026 13:46:33 -0300 Subject: [PATCH 06/12] fix(work-orders): allow comp-doc generate without existing completion document canGenerateCompDoc now ignores the completion-document closability gap so PM/Overdue drafts can enter generation. Co-authored-by: Cursor --- src/domain/work-orders/utils/wo-closability.ts | 4 +++- src/test/domain/work-orders/utils/wo-closability.test.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 24617591..7259cbf5 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -115,9 +115,11 @@ export type CompDocGateResult = { allowed: true } | { allowed: false; reason: st /** * Gate for completion-document generation. CompDocDialog (not yet on `dev`) should call this * before opening generate flow and surface `reason` when blocked. + * + * Intentionally omits the "Completion document" closability gap — generate is how that gap is filled. */ export function canGenerateCompDoc(row: WoClosabilityInput): CompDocGateResult { - const gaps = getClosabilityGaps(row); + const gaps = getClosabilityGaps(row).filter((gap) => gap !== "Completion document"); if (gaps.length > 0) { return { allowed: false, reason: formatClosabilityMissingTitle(gaps) }; } diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index a55938e7..ea06ad4d 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -137,6 +137,10 @@ describe("canGenerateCompDoc", () => { expect(canGenerateCompDoc(makeInput())).toEqual({ allowed: true }); }); + it("allows generation when only the completion document is missing", () => { + expect(canGenerateCompDoc(makeInput({ docStatus: "No" }))).toEqual({ allowed: true }); + }); + it("blocks generation with design reason when only pending uplift exists", () => { expect(canGenerateCompDoc(makeInput({ hasPendingUplift: true }))).toEqual({ allowed: false, From 8a221c8819e449919e7ceac2194c66bbdeef9b1a Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Wed, 12 Aug 2026 09:55:34 -0300 Subject: [PATCH 07/12] fix(work-orders): consume board pendingUpliftCount for SH-188 gate Map the authoritative board/search/detail pendingUpliftCount into the Completed closability gate and align the pending-uplift tooltip with SH-188. --- .../mappers/work-order-table-row-mapper.ts | 28 +++++++++++-------- .../work-orders/types/work-order-board.ts | 7 +++++ .../work-orders/utils/wo-closability.ts | 7 +++-- .../status-cell-pending-uplift.test.tsx | 27 +++++++++++++++++- .../mappers/work-order-mapper.test.ts | 22 +++++++++++++++ 5 files changed, 76 insertions(+), 15 deletions(-) diff --git a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts index 3b9fc66b..ab226518 100644 --- a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts +++ b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts @@ -177,23 +177,25 @@ function readFlagColor(record: Record): string | null { function readUpliftSummary(item: Record): WorkOrderUpliftSummary | undefined { const nested = asRecord(item.upliftSummary ?? item.UpliftSummary); - const source = Object.keys(nested).length > 0 ? nested : item; + const hasNested = Object.keys(nested).length > 0; + const source = hasNested ? nested : item; - const pendingCount = - readNumber(source, "pendingCount", "PendingCount") ?? - readNumber(item, "pendingUpliftCount", "PendingUpliftCount") ?? - 0; + // Board/search/detail contract (SH-188): pendingUpliftCount is authoritative when present. + const boardCount = readNumber(item, "pendingUpliftCount", "PendingUpliftCount"); + const nestedCount = readNumber(source, "pendingCount", "PendingCount"); + const pendingCount = nestedCount ?? boardCount ?? 0; const hasUplift = readBool(source, "hasUplift", "HasUplift") || readBool(item, "hasUplift", "HasUplift") || pendingCount > 0; - if (!hasUplift && pendingCount === 0) { + // No nested summary and no board count → omit (legacy payloads without the contract field). + if (!hasNested && boardCount == null && !hasUplift) { return undefined; } const summary: WorkOrderUpliftSummary = { - hasUplift, + hasUplift: hasUplift || pendingCount > 0, pendingCount, }; const primaryStatus = readString(source, "primaryStatus", "PrimaryStatus", "status", "Status"); @@ -207,11 +209,15 @@ function readHasPendingUplift( item: Record, upliftSummary: WorkOrderUpliftSummary | undefined, ): boolean | undefined { - if (readBool(item, "hasPendingUplift", "HasPendingUplift")) { - return true; + if ("hasPendingUplift" in item || "HasPendingUplift" in item) { + return Boolean(item.hasPendingUplift ?? item.HasPendingUplift); } - if ((upliftSummary?.pendingCount ?? 0) > 0) { - return true; + const boardCount = readNumber(item, "pendingUpliftCount", "PendingUpliftCount"); + if (boardCount != null) { + return boardCount > 0; + } + if (upliftSummary != null) { + return upliftSummary.pendingCount > 0; } return undefined; } diff --git a/src/domain/work-orders/types/work-order-board.ts b/src/domain/work-orders/types/work-order-board.ts index 021fe1c0..fec033b8 100644 --- a/src/domain/work-orders/types/work-order-board.ts +++ b/src/domain/work-orders/types/work-order-board.ts @@ -159,9 +159,16 @@ export interface WorkOrderBoardRowApi { serviceNotes?: string | null; extraServices?: string[] | null; docStatus?: number | null; + /** Work completed date from board/detail contract. */ + completedDate?: string | null; primaryDispatchId?: number | null; rowVersion?: string | null; dispatchRowVersion?: string | null; + /** + * Authoritative pending-uplift count across all dispatches for this WO (SH-188 / BE board contract). + * Drives the Completed closability gate. + */ + pendingUpliftCount?: number; } export interface WorkOrderBoardCountsApi { diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 7259cbf5..388d0e02 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -25,9 +25,9 @@ export type WoClosabilityInput = { export const PENDING_UPLIFT_GAP = "Pending uplift approval"; -/** Design copy when Completed is blocked solely by a pending uplift. */ +/** SH-188 tooltip when Completed is blocked solely by a pending uplift. */ export const UPLIFT_PENDING_COMPLETED_TITLE = - "This work order cannot be completed while an uplift is pending approval."; + "This work order has an uplift pending approval and cannot be completed."; /** Real (non-placeholder) WO number — non-empty and not an SH-prefixed draft id. */ export function isRealWoNumber(woNumber: string): boolean { @@ -83,7 +83,8 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { gaps.push("Service"); } - // Only an actually pending uplift blocks completion; missing uplift fields mean no pending evidence. + // Authoritative pending uplift (board pendingUpliftCount / hasPendingUplift) blocks completion. + // Missing uplift fields mean no pending evidence until the board contract supplies the count. if (hasPendingUplift(row)) { gaps.push(PENDING_UPLIFT_GAP); } diff --git a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx index 998b2680..5d610390 100644 --- a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx +++ b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx @@ -71,13 +71,38 @@ describe("StatusCell pending uplift closability", () => { expect(completed).toBeDisabled(); expect(completed).toHaveAttribute( "title", - "This work order cannot be completed while an uplift is pending approval.", + "This work order has an uplift pending approval and cannot be completed.", ); fireEvent.click(completed); expect(onChangeStatus).not.toHaveBeenCalled(); }); + it("disables Completed with tooltip when board pendingUpliftCount maps to pending", () => { + const onChangeStatus = vi.fn(); + + renderWithProviders( + , + { withAuth: false }, + ); + + fireEvent.click(screen.getByRole("button", { name: /in progress/i })); + + const completed = screen.getByRole("button", { name: /completed/i }); + expect(completed).toBeDisabled(); + expect(completed).toHaveAttribute( + "title", + "This work order has an uplift pending approval and cannot be completed.", + ); + }); + it("allows Completed when no pending uplift", () => { const onChangeStatus = vi.fn(); diff --git a/src/test/domain/work-orders/mappers/work-order-mapper.test.ts b/src/test/domain/work-orders/mappers/work-order-mapper.test.ts index 1b3baa4e..2a33a51c 100644 --- a/src/test/domain/work-orders/mappers/work-order-mapper.test.ts +++ b/src/test/domain/work-orders/mappers/work-order-mapper.test.ts @@ -154,6 +154,28 @@ describe("mapWorkOrderTableRow (board DTO)", () => { expect(row.hasPendingUplift).toBe(true); }); + it("maps board pendingUpliftCount into hasPendingUplift (SH-188 contract)", () => { + const pending = mapWorkOrderTableRow({ + id: 305, + pendingUpliftCount: 1, + }); + expect(pending.hasPendingUplift).toBe(true); + expect(pending.upliftSummary).toEqual({ hasUplift: true, pendingCount: 1 }); + + const clear = mapWorkOrderTableRow({ + id: 306, + PendingUpliftCount: 0, + }); + expect(clear.hasPendingUplift).toBe(false); + expect(clear.upliftSummary).toEqual({ hasUplift: false, pendingCount: 0 }); + }); + + it("leaves hasPendingUplift undefined when board count is absent", () => { + const row = mapWorkOrderTableRow({ id: 307 }); + expect(row.hasPendingUplift).toBeUndefined(); + expect(row.upliftSummary).toBeUndefined(); + }); + it("maps hasPendingUplift from top-level API flag", () => { const row = mapWorkOrderTableRow({ id: 304, From 1835a5939a01847e7d721f5cb399f1b08c92f694 Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Thu, 13 Aug 2026 15:21:16 -0300 Subject: [PATCH 08/12] fix(work-orders): dedupe completedDate and gate Completed on technician (SH-188) Refresh onto current dev and resolve exact-head review blockers: - Remove duplicate WorkOrderBoardRowApi.completedDate after merge with dev - Add SH-114 Technician closability gate alongside company/vendor check - Update wo-closability regressions for missing technician --- src/domain/work-orders/types/work-order-board.ts | 2 -- src/domain/work-orders/utils/wo-closability.ts | 5 ++++- src/test/domain/work-orders/utils/wo-closability.test.ts | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/domain/work-orders/types/work-order-board.ts b/src/domain/work-orders/types/work-order-board.ts index b9ad2110..9f86b153 100644 --- a/src/domain/work-orders/types/work-order-board.ts +++ b/src/domain/work-orders/types/work-order-board.ts @@ -162,8 +162,6 @@ export interface WorkOrderBoardRowApi { serviceNotes?: string | null; extraServices?: string[] | null; docStatus?: number | null; - /** Work completed date from board/detail contract. */ - completedDate?: string | null; primaryDispatchId?: number | null; rowVersion?: string | null; dispatchRowVersion?: string | null; diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 388d0e02..f8ed2972 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -10,7 +10,7 @@ export type WoClosabilityInput = { dispatcherName: string; /** Vendor/company assignment on the board row. */ company: string; - /** Technician name is informational and does not satisfy the vendor requirement. */ + /** Technician assigned to the work order. */ tech: string; /** Work completed date (API CompletedDate). Empty until set. */ completedDate: string; @@ -70,6 +70,9 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { if (!hasDispatcher(row)) { gaps.push("Dispatcher"); } + if (!row.tech.trim()) { + gaps.push("Technician"); + } if (!row.company.trim()) { gaps.push("Company / vendor"); } diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index ea06ad4d..228f3dbe 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -60,8 +60,8 @@ describe("getClosabilityGaps", () => { expect(getClosabilityGaps(makeInput())).toEqual([]); }); - it("accepts a company without a technician", () => { - expect(getClosabilityGaps(makeInput({ tech: "" }))).toEqual([]); + it("blocks Completed when technician is missing", () => { + expect(getClosabilityGaps(makeInput({ tech: "" }))).toEqual(["Technician"]); }); it("does not let a technician satisfy a missing company requirement", () => { @@ -86,6 +86,7 @@ describe("getClosabilityGaps", () => { ), ).toEqual([ "Dispatcher", + "Technician", "Company / vendor", "Completed Date", "WO number", From 5d7ac297e452a0060557fa5f98bef80686367683 Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Fri, 14 Aug 2026 10:55:06 -0300 Subject: [PATCH 09/12] fix(work-orders): drop vendor string from Completed closability (SH-114) --- src/domain/work-orders/utils/wo-closability.ts | 3 --- src/test/domain/work-orders/utils/wo-closability.test.ts | 5 ++--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index f8ed2972..3117f600 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -73,9 +73,6 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { if (!row.tech.trim()) { gaps.push("Technician"); } - if (!row.company.trim()) { - gaps.push("Company / vendor"); - } if (!row.completedDate.trim()) { gaps.push("Completed Date"); } diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index 228f3dbe..29f82f24 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -64,8 +64,8 @@ describe("getClosabilityGaps", () => { expect(getClosabilityGaps(makeInput({ tech: "" }))).toEqual(["Technician"]); }); - it("does not let a technician satisfy a missing company requirement", () => { - expect(getClosabilityGaps(makeInput({ company: "" }))).toEqual(["Company / vendor"]); + it("does not block Completed when vendor/company is empty if technician is assigned", () => { + expect(getClosabilityGaps(makeInput({ company: "" }))).toEqual([]); }); it("lists field gaps before uplift and document gaps", () => { @@ -87,7 +87,6 @@ describe("getClosabilityGaps", () => { ).toEqual([ "Dispatcher", "Technician", - "Company / vendor", "Completed Date", "WO number", "Service", From 37a6098ecbf31f5227514107addc3d9dce9988e7 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Mon, 17 Aug 2026 13:54:05 -0300 Subject: [PATCH 10/12] fix(work-orders): require company not technician for Completed (SH-183) --- .../work-orders/utils/wo-closability.ts | 16 +++++--- .../status-cell-pending-uplift.test.tsx | 40 +++++++++++++++++++ .../work-orders/utils/wo-closability.test.ts | 13 +++--- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 3117f600..024a1ca5 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -4,13 +4,13 @@ import type { } from "@/domain/work-orders/types/work-order-table-row"; import type { WOType, WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard"; -/** Fields required to evaluate whether a WO may be marked Completed (SH-114 ∪ pending uplift). */ +/** Fields required to evaluate whether a WO may be marked Completed (SH-183 ∪ pending uplift). */ export type WoClosabilityInput = { dispatcherId: string; dispatcherName: string; - /** Vendor/company assignment on the board row. */ + /** Company / vendor assignment — required for Completed (SH-183). */ company: string; - /** Technician assigned to the work order. */ + /** Technician is optional for closability; modeled separately from company. */ tech: string; /** Work completed date (API CompletedDate). Empty until set. */ completedDate: string; @@ -51,6 +51,10 @@ function hasDispatcher(row: Pick = {}): WorkOrderTableRow woNumber: "1001", site: "BK5", type: "PM", + severity: null, dispatcherId: "u1", dispatcherName: "Alex", scheduledOn: "2026-07-15", @@ -116,4 +117,43 @@ describe("StatusCell pending uplift closability", () => { expect(onChangeStatus).toHaveBeenCalledWith("Completed"); }); + + it("disables Completed when company is missing (SH-183)", () => { + const onChangeStatus = vi.fn(); + + renderWithProviders( + , + { withAuth: false }, + ); + + fireEvent.click(screen.getByRole("button", { name: /in progress/i })); + + const completed = screen.getByRole("button", { name: /completed/i }); + expect(completed).toBeDisabled(); + expect(completed).toHaveAttribute("title", "Missing: Company"); + fireEvent.click(completed); + expect(onChangeStatus).not.toHaveBeenCalled(); + }); + + it("allows Completed when technician is empty if company is set (SH-183)", () => { + const onChangeStatus = vi.fn(); + + renderWithProviders( + , + { withAuth: false }, + ); + + fireEvent.click(screen.getByRole("button", { name: /in progress/i })); + fireEvent.click(screen.getByRole("button", { name: /completed/i })); + + expect(onChangeStatus).toHaveBeenCalledWith("Completed"); + }); }); diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index 29f82f24..7c761560 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -60,12 +60,15 @@ describe("getClosabilityGaps", () => { expect(getClosabilityGaps(makeInput())).toEqual([]); }); - it("blocks Completed when technician is missing", () => { - expect(getClosabilityGaps(makeInput({ tech: "" }))).toEqual(["Technician"]); + it("allows company without technician (SH-183)", () => { + const gaps = getClosabilityGaps(makeInput({ tech: "" })); + expect(gaps).toEqual([]); + expect(gaps).not.toContain("Technician"); }); - it("does not block Completed when vendor/company is empty if technician is assigned", () => { - expect(getClosabilityGaps(makeInput({ company: "" }))).toEqual([]); + it("blocks Completed when company is missing even if technician is assigned", () => { + expect(getClosabilityGaps(makeInput({ company: "", tech: "Sam" }))).toEqual(["Company"]); + expect(getClosabilityGaps(makeInput({ company: " ", tech: "Sam" }))).toEqual(["Company"]); }); it("lists field gaps before uplift and document gaps", () => { @@ -86,7 +89,7 @@ describe("getClosabilityGaps", () => { ), ).toEqual([ "Dispatcher", - "Technician", + "Company", "Completed Date", "WO number", "Service", From 32177e831b9eceaeb1fb21539839abcf4255d5e8 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Tue, 18 Aug 2026 12:04:55 -0300 Subject: [PATCH 11/12] fix(work-orders): set isAddOn on pending-uplift StatusCell fixture Keep the SH-188 fixture assignable to WorkOrderTableRow after the SH-184 merge. --- .../(protected)/workorders/status-cell-pending-uplift.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx index 6bc04e34..d886232a 100644 --- a/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx +++ b/src/test/app/(protected)/workorders/status-cell-pending-uplift.test.tsx @@ -42,6 +42,7 @@ function makeRow(overrides: Partial = {}): WorkOrderTableRow originalDate: "", isPastDue: false, scheduleWeekOnly: false, + isAddOn: false, mediaCount: 1, title: "", priority: "", From a109a68f40524b95be20d487ade76d140bcaa13d Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Tue, 18 Aug 2026 17:28:14 -0300 Subject: [PATCH 12/12] fix(work-orders): keep SH-188 tooltip when mixed with other gaps Stop copying WO lifecycle status into uplift primaryStatus on flat board rows. --- .../work-orders/mappers/work-order-table-row-mapper.ts | 4 +++- src/domain/work-orders/utils/wo-closability.ts | 2 +- .../work-orders/mappers/work-order-mapper.test.ts | 10 ++++++++++ .../domain/work-orders/utils/wo-closability.test.ts | 10 ++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts index 0442d420..41ee9924 100644 --- a/src/domain/work-orders/mappers/work-order-table-row-mapper.ts +++ b/src/domain/work-orders/mappers/work-order-table-row-mapper.ts @@ -239,7 +239,9 @@ function readUpliftSummary(item: Record): WorkOrderUpliftSummar hasUplift: hasUplift || pendingCount > 0, pendingCount, }; - const primaryStatus = readString(source, "primaryStatus", "PrimaryStatus", "status", "Status"); + const primaryStatus = + readString(nested, "primaryStatus", "PrimaryStatus") || + readString(item, "primaryStatus", "PrimaryStatus"); if (primaryStatus) { summary.primaryStatus = primaryStatus; } diff --git a/src/domain/work-orders/utils/wo-closability.ts b/src/domain/work-orders/utils/wo-closability.ts index 024a1ca5..be377091 100644 --- a/src/domain/work-orders/utils/wo-closability.ts +++ b/src/domain/work-orders/utils/wo-closability.ts @@ -109,7 +109,7 @@ export function getClosabilityGaps(row: WoClosabilityInput): string[] { } export function formatClosabilityMissingTitle(gaps: string[]): string { - if (gaps.length === 1 && gaps[0] === PENDING_UPLIFT_GAP) { + if (gaps.includes(PENDING_UPLIFT_GAP)) { return UPLIFT_PENDING_COMPLETED_TITLE; } return `Missing: ${gaps.join(", ")}`; diff --git a/src/test/domain/work-orders/mappers/work-order-mapper.test.ts b/src/test/domain/work-orders/mappers/work-order-mapper.test.ts index 76d4af5c..107d63f0 100644 --- a/src/test/domain/work-orders/mappers/work-order-mapper.test.ts +++ b/src/test/domain/work-orders/mappers/work-order-mapper.test.ts @@ -209,6 +209,16 @@ describe("mapWorkOrderTableRow (board DTO)", () => { expect(clear.upliftSummary).toEqual({ hasUplift: false, pendingCount: 0 }); }); + it("does not copy work-order status into uplift primaryStatus on flat board rows", () => { + const row = mapWorkOrderTableRow({ + id: 308, + pendingUpliftCount: 1, + status: "In Progress", + Status: "In Progress", + }); + expect(row.upliftSummary?.primaryStatus).toBeUndefined(); + }); + it("leaves hasPendingUplift undefined when board count is absent", () => { const row = mapWorkOrderTableRow({ id: 307 }); expect(row.hasPendingUplift).toBeUndefined(); diff --git a/src/test/domain/work-orders/utils/wo-closability.test.ts b/src/test/domain/work-orders/utils/wo-closability.test.ts index 7c761560..8af2724e 100644 --- a/src/test/domain/work-orders/utils/wo-closability.test.ts +++ b/src/test/domain/work-orders/utils/wo-closability.test.ts @@ -128,9 +128,15 @@ describe("formatClosabilityMissingTitle", () => { ); }); - it("joins multiple gaps with Missing prefix", () => { + it("uses design Completed title when pending uplift is among mixed gaps", () => { expect(formatClosabilityMissingTitle(["Dispatcher", PENDING_UPLIFT_GAP])).toBe( - `Missing: Dispatcher, ${PENDING_UPLIFT_GAP}`, + UPLIFT_PENDING_COMPLETED_TITLE, + ); + }); + + it("joins multiple non-uplift gaps with Missing prefix", () => { + expect(formatClosabilityMissingTitle(["Dispatcher", "Company"])).toBe( + "Missing: Dispatcher, Company", ); }); });