Initial release of Barcode Tools 0.1.0

This commit is contained in:
2026-09-01 02:55:06 +02:00
commit 81677e1134
58 changed files with 9200 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
import { describe, expect, it } from "vitest";
import {
createBarcodeZip,
parseBatch,
renderBarcodeSvg,
} from "../../src/barcode/generate";
import {
buildStructuredPayload,
gtinCheckDigit,
validateGtin,
} from "../../src/barcode/payloads";
describe("barcode generation", () => {
it("renders inert scalable QR output", () => {
const result = renderBarcodeSvg({
format: "qrcode",
text: "https://example.com",
scale: 3,
padding: 8,
includeText: false,
});
expect(result.svg).toMatch(/^<svg/u);
expect(result.svg).not.toMatch(/<script|\bon\w+=|href=/iu);
expect(result.width).toBeGreaterThan(0);
});
it("creates deterministic named batch archives", () => {
const rows = parseBatch('first,hello\n"second",world');
const first = createBarcodeZip(rows, {
format: "qrcode",
scale: 2,
padding: 8,
includeText: false,
});
const second = createBarcodeZip(rows, {
format: "qrcode",
scale: 2,
padding: 8,
includeText: false,
});
expect(first).toEqual(second);
});
});
describe("structured payloads", () => {
it("escapes Wi-Fi delimiter characters", () =>
expect(
buildStructuredPayload("wifi", {
primary: "lab;guest",
secondary: "p:a\\ss",
tertiary: "WPA",
hidden: true,
}),
).toBe("WIFI:T:WPA;S:lab\\;guest;P:p\\:a\\\\ss;H:true;;"));
it("rejects injected or unsupported Wi-Fi security fields", () => {
expect(() =>
buildStructuredPayload("wifi", {
primary: "lab",
tertiary: "WPA;S:other",
}),
).toThrow(/WPA, WEP, or nopass/u);
});
it("calculates and validates GTIN check digits", () => {
expect(gtinCheckDigit("400638133393")).toBe(1);
expect(validateGtin("4006381333931")).toEqual({
valid: true,
expected: "1",
});
});
});
+63
View File
@@ -0,0 +1,63 @@
import { expect, test, type Page } from "@playwright/test";
const ORIGIN = "http://127.0.0.1:4173";
async function localOnly(page: Page) {
const external: string[] = [];
await page.route("**/*", async (route) => {
const url = new URL(route.request().url());
if (url.origin !== ORIGIN) {
external.push(url.href);
await route.abort();
} else await route.continue();
});
return external;
}
test("runs from a nested path without external requests", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
page.on("console", (message) => {
if (message.type() === "error") errors.push(message.text());
});
const external = await localOnly(page);
await page.goto("/deep/nested/barcode/");
await expect(
page.getByRole("heading", { name: "Barcode Tools" }),
).toBeVisible();
expect(external).toEqual([]);
expect(errors).toEqual([]);
});
test("generates an inert SVG and validates a GTIN", async ({ page }) => {
const external = await localOnly(page);
await page.goto("/deep/nested/barcode/");
await page
.getByRole("textbox", { name: "Payload", exact: true })
.fill("browser-local barcode gate");
await page.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.getByLabel("Complete GTIN").fill("4006381333931");
await expect(page.getByText("The check digit is valid.")).toBeVisible();
expect(external).toEqual([]);
});
test("serves the release identity and hardened headers", async ({
request,
}) => {
const index = await request.get("/deep/nested/barcode/");
expect(index.ok()).toBe(true);
expect(index.headers()["content-security-policy"]).toContain(
"default-src 'self'",
);
expect(await index.text()).not.toMatch(/\b(?:src|href)=["']\//u);
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",
entry: "./",
});
});
+17
View File
@@ -0,0 +1,17 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { App } from "../../src/App";
describe("Barcode Tools", () => {
it("renders the local workbench and standard shell", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async () => new Response("Not found", { status: 404 })),
);
render(<App />);
expect(
await screen.findByRole("heading", { name: "Barcode Tools" }),
).toBeVisible();
expect(await screen.findByText("No automatic navigation")).toBeVisible();
});
});