import type { FragmentOf } from "@/graphql"; import { InboundShipmentActionsFragment } from "@/pages/procurement/inbound-shipment/[docNumber]/components/inbound-shipment-actions"; type GRStatus = "DRAFT" | "POSTED"; type POReceiptStatus = "NOT_RECEIVED" | "PARTIALLY_RECEIVED" | "RECEIVED"; export interface InboundShipmentFragmentOverrides { id?: string; status: GRStatus; /** * The backing PO, if any. When `null`, the fixture leaves the first line's * `sourceDocumentId` empty so the actions panel treats this as a standalone * GR. When set, the fixture stamps the PO id onto the first line's * `sourceDocumentId` (with `sourceDocumentType: "PURCHASE_ORDER"`); the live * runtime resolves the full PO via a sibling GraphQL query keyed on that id. * * In erp-kit 0.45 a inbound shipment is an InboundShipment and the source * document link lives on the line, so the fixture models it there. * * `receiptStatus` is not part of the fragment — it lives on the resolved * PurchaseOrder row. Tests that need to assert different conditional * branches should patch the urql cache or mock the runtime query * separately. */ backingPO?: { id: string; docNumber: string; receiptStatus: POReceiptStatus; } | null; } /** * Build a fixture matching the InboundShipmentActionsFragment shape on * InboundShipment. The first line carries `sourceDocumentType` / * `sourceDocumentId`; the backing PO row is fetched lazily by the component * via a sibling query and is not part of this fixture. */ export function makeInboundShipmentFragment( overrides: InboundShipmentFragmentOverrides, ): FragmentOf { return { id: overrides.id ?? "gr-test-id", status: overrides.status, lines: { edges: [ { node: { sourceDocumentType: overrides.backingPO ? "PURCHASE_ORDER" : null, sourceDocumentId: overrides.backingPO?.id ?? null, }, }, ], }, } as unknown as FragmentOf; }