Files
geo-tools/tests/browser/app.spec.ts
T
zemion 3538e4e12b
Verify / verify (push) Canceled after 0s
Release Geo Tools 0.2.0
2026-09-02 12:02:09 +02:00

95 lines
3.3 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/geo/");
await expect(page.getByRole("heading", { name: "Geo Tools" })).toBeVisible();
expect(external).toEqual([]);
expect(errors).toEqual([]);
});
test("parses coordinate CSV and updates the local analysis", async ({
page,
}) => {
const external = await localOnly(page);
await page.goto("/deep/nested/geo/");
await page.getByLabel("Input format").selectOption("csv");
await page
.getByLabel("Geospatial source")
.fill("name,lat,lon,elevation\nA,52.5,13.4,10\nB,52.6,13.5,20");
await page.getByRole("button", { name: "Parse locally" }).click();
await expect(page.getByText("Last successful model · CSV")).toBeVisible();
await expect(page.getByText("2", { exact: true }).first()).toBeVisible();
await expect(
page.getByRole("img", { name: /Local coordinate plot/u }),
).toBeVisible();
expect(external).toEqual([]);
});
test("edits full-feature geometry, inventories tracks and measures locally", async ({
page,
}) => {
await page.goto("/deep/nested/geo/");
await expect(
page.getByRole("heading", { name: "Track inventory" }),
).toBeVisible();
await expect(
page
.getByRole("region", { name: "Track inventory" })
.getByText("Berlin walk", { exact: true }),
).toBeVisible();
await page.getByLabel("Editable GeoJSON feature").fill(
JSON.stringify({
type: "Feature",
properties: { name: "Edited point" },
geometry: { type: "Point", coordinates: [7.1, 50.7] },
}),
);
await page.getByRole("button", { name: "Apply feature edit" }).click();
const featurePicker = page
.getByRole("region", { name: "Edit any GeoJSON feature" })
.getByRole("combobox");
await expect(featurePicker.locator("option:checked")).toHaveText(
"1: Edited point",
);
await page.getByLabel("Start longitude,latitude[,elevation]").fill("0,0");
await page.getByLabel("End longitude,latitude[,elevation]").fill("1,0");
await expect(page.getByText(/111195/)).toBeVisible();
await expect(page.getByText("90.00°")).toBeVisible();
});
test("serves the release identity and hardened headers", async ({
request,
}) => {
const index = await request.get("/deep/nested/geo/");
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/geo/toolbox-app.json");
await expect(manifest.json()).resolves.toMatchObject({
id: "de.add-ideas.geo-tools",
version: "0.2.0",
entry: "./",
});
});