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/time/"); await expect(page.getByRole("heading", { name: "Time Tools" })).toBeVisible(); expect(external).toEqual([]); expect(errors).toEqual([]); }); test("converts a negative nanosecond epoch exactly", async ({ page }) => { const external = await localOnly(page); await page.goto("/deep/nested/time/"); await page.getByLabel("Epoch value").fill("-0.000000001"); await page.getByRole("button", { name: "Convert exactly" }).click(); await expect( page.getByRole("heading", { name: "Exact timestamp conversion" }), ).toBeVisible(); await expect(page.locator(".result > pre")).toContainText( "1969-12-31T23:59:59.999999999Z", ); await expect(page.locator(".result > pre")).toContainText( '"epochNanoseconds": "-1"', ); expect(external).toEqual([]); }); test("inspects imported recurrence and keeps calendar URLs inert", async ({ page, }) => { const external = await localOnly(page); await page.goto("/deep/nested/time/"); await page.getByRole("button", { name: "iCalendar" }).click(); await page .getByLabel("Paste iCalendar source") .fill( [ "BEGIN:VCALENDAR", "VERSION:2.0", "PRODID:-//Browser fixture//EN", "BEGIN:VEVENT", "UID:fixture@example", "DTSTART:20260901T090000Z", "RRULE:FREQ=DAILY;COUNT=2", "SUMMARY:Fixture", "URL:https://example.invalid/never-fetch", "END:VEVENT", "END:VCALENDAR", ].join("\r\n"), ); await page .getByRole("button", { name: "Validate and inspect calendar" }) .click(); await expect( page.getByRole("heading", { name: "iCalendar inspection" }), ).toBeVisible(); await expect(page.locator(".result > pre")).toContainText('"inert": true'); await expect(page.locator(".result > pre")).toContainText('"occurrences": ['); expect(external).toEqual([]); }); test("plans cross-zone meetings and previews an explicit cron dialect", async ({ page, }) => { await page.goto("/deep/nested/time/"); await page.getByRole("button", { name: "Meeting planner" }).click(); await page.getByLabel("Search from instant").fill("2026-09-01T00:00:00Z"); await page .getByRole("button", { name: "Find shared work-hour slots" }) .click(); await expect( page.getByRole("heading", { name: "Meeting candidates" }), ).toBeVisible(); await expect(page.locator(".result > pre")).toContainText("Europe/Berlin"); await expect(page.locator(".result > pre")).toContainText("America/New_York"); await page.getByRole("button", { name: "Cron & RRULE" }).click(); await page.getByLabel("Cron dialect").selectOption("github-actions"); await page.getByLabel("Time zone").fill("UTC"); await page.getByRole("button", { name: "Preview cron" }).click(); await expect(page.locator(".result > pre")).toContainText("github-actions"); await expect(page.locator(".result > pre")).toContainText( "normalizedPattern", ); }); test("serves the release identity and hardened headers", async ({ request, }) => { const index = await request.get("/deep/nested/time/"); 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/time/toolbox-app.json"); await expect(manifest.json()).resolves.toMatchObject({ id: "de.add-ideas.time-tools", version: "0.2.0", entry: "./", }); });