121 lines
4.4 KiB
TypeScript
121 lines
4.4 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/unicode/");
|
|
await expect(
|
|
page.getByRole("heading", { name: "Unicode Tools" }),
|
|
).toBeVisible();
|
|
expect(external).toEqual([]);
|
|
expect(errors).toEqual([]);
|
|
});
|
|
|
|
test("serves the release identity and hardened headers", async ({
|
|
request,
|
|
}) => {
|
|
const index = await request.get("/deep/nested/unicode/");
|
|
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/unicode/toolbox-app.json");
|
|
await expect(manifest.json()).resolves.toMatchObject({
|
|
id: "de.add-ideas.unicode-tools",
|
|
version: "0.2.0",
|
|
entry: "./",
|
|
});
|
|
});
|
|
|
|
test("searches the pinned catalog in a worker and shows character properties", async ({
|
|
page,
|
|
}) => {
|
|
const external = await localOnly(page);
|
|
await page.goto("/deep/nested/unicode/");
|
|
await page.getByLabel("Name, alias, character, or U+ code").fill("U+1F600");
|
|
await page.getByRole("button", { name: "Search", exact: true }).click();
|
|
const result = page.getByRole("button", { name: /GRINNING FACE/u });
|
|
await expect(result).toBeVisible({ timeout: 60_000 });
|
|
await result.click();
|
|
await expect(page.getByText("Unicode 6.1")).toBeVisible();
|
|
await expect(page.getByText("Common / Emoticons")).toBeVisible();
|
|
expect(external).toEqual([]);
|
|
});
|
|
|
|
test("virtualizes a range and labels surrogate code units explicitly", async ({
|
|
page,
|
|
}) => {
|
|
const external = await localOnly(page);
|
|
await page.goto("/deep/nested/unicode/");
|
|
await page.getByRole("button", { name: "Code chart" }).click();
|
|
await page.getByLabel("Range start").fill("U+D7F0");
|
|
await page.getByLabel("Range end").fill("U+D810");
|
|
await page.getByRole("button", { name: "Open range" }).click();
|
|
const surrogate = page.getByRole("gridcell", {
|
|
name: /U\+D800 UTF-16 SURROGATE CODE UNIT, surrogate/u,
|
|
});
|
|
await expect(surrogate).toBeVisible({ timeout: 60_000 });
|
|
await surrogate.click();
|
|
await expect(page.getByText(/not a Unicode scalar value/u)).toBeVisible();
|
|
await expect(
|
|
page.getByRole("button", { name: "Copy scalar" }),
|
|
).toBeDisabled();
|
|
await surrogate.press("ArrowRight");
|
|
await expect(
|
|
page.getByRole("gridcell", { name: /U\+D801 UTF-16 SURROGATE/u }),
|
|
).toBeFocused();
|
|
expect(external).toEqual([]);
|
|
});
|
|
|
|
test("inspects graphemes and compares UTS #39 confusable skeletons locally", async ({
|
|
page,
|
|
}) => {
|
|
const external = await localOnly(page);
|
|
await page.goto("/deep/nested/unicode/");
|
|
await page.getByRole("button", { name: "Text inspector" }).click();
|
|
await page.getByLabel("Text to inspect").fill("👨👩👧👦 🇩🇪");
|
|
await page.getByRole("button", { name: "Inspect text" }).click();
|
|
await expect(page.getByText("pictographic · ZWJ")).toBeVisible();
|
|
await expect(page.getByText("2 regional indicator(s)")).toBeVisible();
|
|
|
|
await page.getByRole("button", { name: "Normalize & confusables" }).click();
|
|
const normalization = page
|
|
.getByRole("heading", {
|
|
name: "Compare forms and compute a confusable skeleton",
|
|
})
|
|
.locator("..");
|
|
await normalization
|
|
.getByRole("textbox", { name: "Text", exact: true })
|
|
.fill("раypal");
|
|
await normalization
|
|
.getByRole("textbox", { name: "Compare identifier (optional)" })
|
|
.fill("paypal");
|
|
await page.getByRole("button", { name: "Analyze confusables" }).click();
|
|
await expect(
|
|
page.getByRole("heading", { name: "UTS #39 confusable analysis" }),
|
|
).toBeVisible({ timeout: 60_000 });
|
|
await expect(
|
|
page.getByText("yes — review", { exact: true }).last(),
|
|
).toBeVisible();
|
|
await expect(page.getByText(/mixed-script/u).first()).toBeVisible();
|
|
expect(external).toEqual([]);
|
|
});
|