From 37a6098ecbf31f5227514107addc3d9dce9988e7 Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Mon, 17 Aug 2026 13:54:05 -0300 Subject: [PATCH] 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",