Files
zemion f1c41e7079
Verify / verify (push) Canceled after 0s
Release Fixture Tools 0.2.0
2026-09-02 13:00:37 +02:00

125 lines
4.6 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
const ORIGIN = "http://127.0.0.1:4194";
async function watchLocalOnly(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 at a nested path and generates deterministic relational data", async ({
page,
}) => {
await page.setViewportSize({ width: 1800, height: 1000 });
const external = await watchLocalOnly(page);
await page.goto("/deep/nested/fixture/");
await expect(
page.getByRole("heading", { name: "Fixture Tools" }),
).toBeVisible();
await page.getByRole("button", { name: "Generate fixtures" }).click();
await expect(
page.getByRole("heading", { name: "Generated records" }),
).toBeVisible();
await page.getByLabel("Data table").selectOption("orders");
await expect(
page.getByRole("columnheader", { name: "user_id" }),
).toBeVisible();
expect(external).toEqual([]);
expect(
await page
.locator(".toolbox-shell__main")
.evaluate((node) => getComputedStyle(node).width),
).toBe("1440px");
});
test("imports CSV headings and exports an inspectable model", async ({
page,
}) => {
await page.goto("/deep/nested/fixture/");
await page.getByLabel("Source kind").selectOption("csv");
await page.getByLabel("Fixture model source").fill("id,email,active\n");
await page.getByRole("button", { name: "Import model" }).click();
await expect(
page.getByRole("heading", { name: "Editable field model" }),
).toBeVisible();
await expect(page.getByLabel("email type")).toHaveValue("email");
const pending = page.waitForEvent("download");
await page.getByRole("button", { name: "Export model" }).click();
expect((await pending).suggestedFilename()).toBe("fixture-model.json");
});
test("imports composite constraints and exposes topological coverage", async ({
page,
}) => {
await page.goto("/deep/nested/fixture/");
await page.getByLabel("Fixture model source").fill(`CREATE TABLE tenants (
region VARCHAR(8), tenant_id INTEGER, PRIMARY KEY (region, tenant_id)
);
CREATE TABLE events (
region VARCHAR(8), tenant_id INTEGER,
FOREIGN KEY (region, tenant_id) REFERENCES tenants(region, tenant_id)
);`);
await page.getByRole("button", { name: "Import model" }).click();
await page.getByRole("button", { name: "Generate fixtures" }).click();
await page.getByRole("button", { name: "Coverage" }).click();
await expect(
page.getByRole("heading", { name: "Constraint coverage matrix" }),
).toBeVisible();
await expect(page.getByText("tenants → events")).toBeVisible();
await expect(page.getByText(/foreignKey\(region,tenant_id\)/u)).toBeVisible();
});
test("retains results after a failed import and downloads output", async ({
page,
}) => {
await page.goto("/deep/nested/fixture/");
await page.getByLabel("Source kind").selectOption("json-schema");
await page.getByLabel("Fixture model source").fill("{");
await page.getByRole("button", { name: "Import model" }).click();
await expect(page.getByRole("alert")).toContainText("retained");
await page.getByRole("button", { name: "Data" }).click();
const pending = page.waitForEvent("download");
await page.getByRole("button", { name: "Download JSON" }).click();
expect((await pending).suggestedFilename()).toBe("fixtures.json");
});
test("integrates help, themes, PWA identity and hardened headers", async ({
page,
request,
}) => {
await page.goto("/deep/nested/fixture/");
await page.getByRole("button", { name: "Help" }).click();
await expect(
page.getByRole("dialog", { name: "About Fixture Tools" }),
).toContainText("synthetic");
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "Personalize" }).click();
await page.getByRole("button", { name: "Dark" }).click();
await expect(page.locator(".toolbox-shell").first()).toHaveAttribute(
"data-toolbox-theme",
"dark",
);
expect(
await page.evaluate(async () =>
Boolean(await navigator.serviceWorker.ready),
),
).toBe(true);
const index = await request.get("/deep/nested/fixture/");
expect(index.headers()["content-security-policy"]).toContain(
"connect-src 'self'",
);
expect(await index.text()).not.toMatch(/\b(?:src|href)=["']\//u);
const manifest = await request.get("/deep/nested/fixture/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.fixture-tools",
version: "0.2.0",
privacy: { processing: "local", telemetry: false },
});
});