@@ -1,5 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
barcodePrintGuidance,
|
||||
createPrintSizedSvg,
|
||||
createBarcodeZip,
|
||||
parseBatch,
|
||||
renderBarcodeSvg,
|
||||
@@ -9,6 +11,7 @@ import {
|
||||
gtinCheckDigit,
|
||||
validateGtin,
|
||||
} from "../../src/barcode/payloads";
|
||||
import { inspectGs1 } from "../../src/barcode/gs1";
|
||||
|
||||
describe("barcode generation", () => {
|
||||
it("renders inert scalable QR output", () => {
|
||||
@@ -40,6 +43,29 @@ describe("barcode generation", () => {
|
||||
});
|
||||
expect(first).toEqual(second);
|
||||
});
|
||||
|
||||
it("exports physical SVG dimensions and reports honest quiet-zone guidance", () => {
|
||||
const barcode = renderBarcodeSvg({
|
||||
format: "qrcode",
|
||||
text: "print plan",
|
||||
scale: 3,
|
||||
padding: 2,
|
||||
includeText: false,
|
||||
});
|
||||
const plan = barcodePrintGuidance(
|
||||
barcode,
|
||||
{ format: "qrcode", padding: 2 },
|
||||
50,
|
||||
300,
|
||||
);
|
||||
expect(plan.quietZoneAssessment).toBe("manual-measurement-required");
|
||||
expect(plan.suppliedPaddingPoints).toBe(2);
|
||||
expect(plan.minimumQuietZoneModules).toBe(4);
|
||||
expect(plan.rasterWidthPixels).toBe(591);
|
||||
expect(createPrintSizedSvg(barcode, 50)).toMatch(
|
||||
/^<svg width="50mm" height="[\d.]+mm" viewBox=/u,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("structured payloads", () => {
|
||||
@@ -68,3 +94,38 @@ describe("structured payloads", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GS1 element inspection", () => {
|
||||
it("parses parenthesized HRI with checks, dates and variable fields", () => {
|
||||
const result = inspectGs1(
|
||||
"(01)04006381333931(17)271231(10)LOT-42(21)SERIAL-7",
|
||||
);
|
||||
expect(result.errors).toEqual([]);
|
||||
expect(result.elements.map((item) => item.ai)).toEqual([
|
||||
"01",
|
||||
"17",
|
||||
"10",
|
||||
"21",
|
||||
]);
|
||||
expect(result.normalizedElementString).toContain("LOT-42\u001d21");
|
||||
});
|
||||
|
||||
it("parses raw fields using GS separators and reports a bad check digit", () => {
|
||||
const result = inspectGs1("]C10104006381333930\u001d10LOT\u001d21SERIAL");
|
||||
expect(result.symbologyIdentifier).toBe("]C1");
|
||||
expect(result.elements[0]?.valid).toBe(false);
|
||||
expect(result.errors.join(" ")).toMatch(/Check digit should be 1/u);
|
||||
});
|
||||
|
||||
it("interprets decimal indicator AIs without changing the source", () => {
|
||||
const result = inspectGs1("(3102)001234(3932)978001234");
|
||||
expect(result.elements[0]?.interpretation).toBe("12.34");
|
||||
expect(result.elements[1]?.interpretation).toBe("978 12.34");
|
||||
});
|
||||
|
||||
it("stops rather than guessing an unknown raw AI boundary", () => {
|
||||
const result = inspectGs1("8912345");
|
||||
expect(result.elements).toEqual([]);
|
||||
expect(result.errors.join(" ")).toMatch(/Unknown AI/u);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user