64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
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: "./",
|
|
});
|
|
});
|