Release Barcode Tools 0.2.0
Verify / verify (push) Canceled after 0s

This commit is contained in:
2026-09-02 11:08:20 +02:00
parent 81677e1134
commit d94e03b81a
29 changed files with 1266 additions and 100 deletions
+61
View File
@@ -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);
});
});
+88 -3
View File
@@ -34,17 +34,102 @@ test("generates an inert SVG and validates a GTIN", async ({ page }) => {
await page
.getByRole("textbox", { name: "Payload", exact: true })
.fill("browser-local barcode gate");
await page.getByRole("button", { name: "Generate", exact: true }).click();
await page
.getByRole("region", { name: "Scalable barcode" })
.getByRole("button", { name: "Generate", exact: true })
.click();
await expect(
page.getByRole("img", { name: "Generated barcode preview" }),
).toBeVisible();
await expect(page.getByText(/Vector bounds/u)).toBeVisible();
await page.getByRole("tab", { name: "GS1 helper" }).click();
await page.getByText("Print size and quiet-zone plan").click();
await expect(page.getByText(/Manual measurement required/u)).toBeVisible();
await page.getByRole("button", { name: "GS1 helper" }).click();
await expect(page.getByText("Batch / lot", { exact: true })).toBeVisible();
await expect(page.getByText("Serial", { exact: true })).toBeVisible();
await page.getByLabel("Complete GTIN").fill("4006381333931");
await expect(page.getByText("The check digit is valid.")).toBeVisible();
expect(external).toEqual([]);
});
test("requests camera permission only after the explicit start action", async ({
page,
}) => {
await page.addInitScript(() => {
const state = { requests: 0, stopped: false };
Object.defineProperty(window, "__barcodeCameraState", { value: state });
Object.defineProperty(navigator, "mediaDevices", {
configurable: true,
value: {
getUserMedia: async () => {
state.requests += 1;
const stream = document.createElement("canvas").captureStream(1);
for (const track of stream.getTracks()) {
const stop = track.stop.bind(track);
track.stop = () => {
state.stopped = true;
stop();
};
}
return stream;
},
},
});
Object.defineProperty(window, "BarcodeDetector", {
configurable: true,
value: class {
async detect() {
return [{ rawValue: "camera-local", format: "qr_code" }];
}
},
});
HTMLMediaElement.prototype.play = async () => undefined;
});
const external = await localOnly(page);
await page.goto("/deep/nested/barcode/");
await page.getByRole("button", { name: "Decode" }).click();
await expect
.poll(() =>
page.evaluate(
() =>
(
window as unknown as {
__barcodeCameraState: { requests: number };
}
).__barcodeCameraState.requests,
),
)
.toBe(0);
await page.getByRole("button", { name: "Start camera" }).click();
await expect(page.getByText("camera-local", { exact: true })).toBeVisible();
await expect
.poll(() =>
page.evaluate(
() =>
(
window as unknown as {
__barcodeCameraState: { requests: number };
}
).__barcodeCameraState.requests,
),
)
.toBe(1);
await page.getByRole("button", { name: "Stop camera" }).click();
await expect
.poll(() =>
page.evaluate(
() =>
(
window as unknown as {
__barcodeCameraState: { stopped: boolean };
}
).__barcodeCameraState.stopped,
),
)
.toBe(true);
expect(external).toEqual([]);
});
test("serves the release identity and hardened headers", async ({
request,
}) => {
@@ -57,7 +142,7 @@ test("serves the release identity and hardened headers", async ({
const manifest = await request.get("/deep/nested/barcode/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.barcode-tools",
version: "0.1.0",
version: "0.2.0",
entry: "./",
});
});
+18
View File
@@ -0,0 +1,18 @@
import { expect, test } from "@playwright/test";
test("keeps the primary workspace inside a narrow viewport", async ({
page,
}) => {
await page.goto("/deep/nested/barcode/");
await expect(page.locator("main").first()).toBeVisible();
await expect(
page.locator("main .loading, main .workbench-loading"),
).toHaveCount(0);
const widths = await page.evaluate(() => ({
content: document.documentElement.scrollWidth,
viewport: document.documentElement.clientWidth,
}));
expect(widths.viewport).toBeLessThanOrEqual(430);
expect(widths.content).toBeLessThanOrEqual(widths.viewport + 1);
});