|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { computePreflight } from "./preflight"; |
| 3 | +import { getEntry } from "../registry"; |
3 | 4 | import type { ObjectBoundsCtx } from "./objectBounds"; |
4 | 5 | import type { LabelObject } from "../types/Group"; |
5 | 6 | import type { LeafObject } from "../registry"; |
@@ -117,3 +118,77 @@ describe("computePreflight (off-label producer)", () => { |
117 | 118 | ]); |
118 | 119 | }); |
119 | 120 | }); |
| 121 | + |
| 122 | +describe("per-type producers (registry preflight capability)", () => { |
| 123 | + const textLeaf = (props: object): LeafObject => |
| 124 | + ({ id: "t", type: "text", x: 0, y: 0, rotation: 0, props } as LabelObject as LeafObject); |
| 125 | + const bar = (moduleWidth: number): LeafObject => |
| 126 | + ({ |
| 127 | + id: "bc", type: "code128", x: 100, y: 100, rotation: 0, |
| 128 | + props: { content: "X", height: 50, moduleWidth, printInterpretation: false, checkDigit: false, rotation: "N" }, |
| 129 | + } as LabelObject as LeafObject); |
| 130 | + |
| 131 | + it("text: a block narrower than one glyph cell flags blockTooNarrow", () => { |
| 132 | + const narrow = getEntry("text")!.preflight!(textLeaf({ content: "X", fontHeight: 30, fontWidth: 0, blockWidth: 2 }), { label }); |
| 133 | + expect(narrow).toEqual([{ kind: "blockTooNarrow" }]); |
| 134 | + }); |
| 135 | + |
| 136 | + it("text: a wide block and a plain (normal) field flag nothing", () => { |
| 137 | + const wide = getEntry("text")!.preflight!(textLeaf({ content: "X", fontHeight: 30, fontWidth: 0, blockWidth: 200 }), { label }); |
| 138 | + const normal = getEntry("text")!.preflight!(textLeaf({ content: "X", fontHeight: 30, fontWidth: 0 }), { label }); |
| 139 | + expect(wide).toEqual([]); |
| 140 | + expect(normal).toEqual([]); |
| 141 | + }); |
| 142 | + |
| 143 | + it("barcode: a module below the min X-dimension flags barcodeTooSmall", () => { |
| 144 | + // moduleWidth 1 @ 8 dpmm = 0.125 mm < 0.25 mm. |
| 145 | + const small = getEntry("code128")!.preflight!(bar(1), { label }); |
| 146 | + expect(small).toEqual([{ kind: "barcodeTooSmall", detail: "0.13 mm (min 0.25 mm)" }]); |
| 147 | + }); |
| 148 | + |
| 149 | + it("barcode: a module at/above the min X-dimension flags nothing", () => { |
| 150 | + // moduleWidth 2 @ 8 dpmm = 0.25 mm. |
| 151 | + expect(getEntry("code128")!.preflight!(bar(2), { label })).toEqual([]); |
| 152 | + }); |
| 153 | + |
| 154 | + it("computePreflight stamps objectId + severity from a producer finding", () => { |
| 155 | + expect(computePreflight([bar(1)], ctx)).toContainEqual({ |
| 156 | + objectId: "bc", kind: "barcodeTooSmall", severity: "warning", detail: "0.13 mm (min 0.25 mm)", |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
| 160 | + it("2D: a QR magnification below the min cell size flags barcodeTooSmall", () => { |
| 161 | + const qr = (magnification: number): LeafObject => |
| 162 | + ({ id: "q", type: "qrcode", x: 0, y: 0, rotation: 0, |
| 163 | + props: { content: "x", magnification, errorCorrection: "Q", model: 2, rotation: "N" } } as LabelObject as LeafObject); |
| 164 | + // magnification 1 @ 8 dpmm = 0.125 mm < 0.25; magnification 2 = 0.25 mm (ok). |
| 165 | + expect(getEntry("qrcode")!.preflight!(qr(1), { label })).toEqual([ |
| 166 | + { kind: "barcodeTooSmall", detail: "0.13 mm (min 0.25 mm)" }, |
| 167 | + ]); |
| 168 | + expect(getEntry("qrcode")!.preflight!(qr(2), { label })).toEqual([]); |
| 169 | + }); |
| 170 | + |
| 171 | + it("text: ^FB content wrapping past the line cap flags textOverset", () => { |
| 172 | + const fb = textLeaf({ content: "AAA BBB CCC", fontHeight: 30, fontWidth: 0, blockWidth: 40, blockLines: 1 }); |
| 173 | + expect(getEntry("text")!.preflight!(fb, { label })).toEqual([{ kind: "textOverset" }]); |
| 174 | + }); |
| 175 | + |
| 176 | + it("text: ^TB content taller than the block height flags textOverset", () => { |
| 177 | + const tb = textLeaf({ content: "AAA", fontHeight: 30, fontWidth: 0, blockWidth: 200, blockHeight: 10, textMode: "tb" }); |
| 178 | + expect(getEntry("text")!.preflight!(tb, { label })).toEqual([{ kind: "textOverset" }]); |
| 179 | + }); |
| 180 | + |
| 181 | + it("text: a block with room to spare flags nothing", () => { |
| 182 | + const ok = textLeaf({ content: "AAA", fontHeight: 30, fontWidth: 0, blockWidth: 400, blockLines: 5 }); |
| 183 | + expect(getEntry("text")!.preflight!(ok, { label })).toEqual([]); |
| 184 | + }); |
| 185 | + |
| 186 | + it("image: no resolvable bytes flags imageMissing; rawGf resolves", () => { |
| 187 | + const img = (props: object): LeafObject => |
| 188 | + ({ id: "i", type: "image", x: 0, y: 0, rotation: 0, props } as LabelObject as LeafObject); |
| 189 | + expect(getEntry("image")!.preflight!(img({ imageId: "nope", widthDots: 200, threshold: 128 }), { label })).toEqual([ |
| 190 | + { kind: "imageMissing" }, |
| 191 | + ]); |
| 192 | + expect(getEntry("image")!.preflight!(img({ imageId: "nope", widthDots: 200, threshold: 128, rawGf: "^GFA,1,1,1,00" }), { label })).toEqual([]); |
| 193 | + }); |
| 194 | +}); |
0 commit comments