mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 14:42:05 +00:00
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
|
|
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> = {}): 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",
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|