Initial release of Geo Tools 0.1.0

This commit is contained in:
2026-09-01 02:55:06 +02:00
commit 2acdb66399
59 changed files with 8637 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
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("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.1.0",
entry: "./",
});
});
+17
View File
@@ -0,0 +1,17 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { App } from "../../src/App";
describe("Geo Tools", () => {
it("renders the local workbench and standard shell", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async () => new Response("Not found", { status: 404 })),
);
render(<App />);
expect(
await screen.findByRole("heading", { name: "Geo Tools" }),
).toBeVisible();
expect(await screen.findByText("No map requests")).toBeVisible();
});
});
+76
View File
@@ -0,0 +1,76 @@
import { describe, expect, it } from "vitest";
import {
analyseCollection,
haversine,
simplifyLine,
toDms,
} from "../../src/geo/analysis";
import {
parseCoordinateCsv,
parseGeoJson,
parseGpx,
serializeGeo,
} from "../../src/geo/formats";
describe("geospatial formats", () => {
it("parses GeoJSON and preserves safe scalar properties", () => {
const result = parseGeoJson(
'{"type":"Feature","properties":{"name":"A","nested":{"x":1}},"geometry":{"type":"Point","coordinates":[13.4,52.5]}}',
);
expect(result.collection.features[0]?.properties).toEqual({ name: "A" });
});
it("rejects XML document types", () =>
expect(() => parseGpx("<!DOCTYPE gpx><gpx/>")).toThrow(/DOCTYPE/u));
it("rejects excessive XML nesting before DOM construction", () =>
expect(() => parseGpx(`${"<x>".repeat(257)}${"</x>".repeat(257)}`)).toThrow(
/256-level/u,
));
it("round-trips coordinate CSV into valid GeoJSON", () => {
const result = parseCoordinateCsv(
"name,lat,lon,elevation\nBerlin,52.5,13.4,42",
);
expect(
parseGeoJson(serializeGeo(result.collection, "geojson").text).collection,
).toEqual(result.collection);
});
});
describe("geospatial analysis", () => {
it("uses great-circle distance", () =>
expect(haversine([0, 0], [1, 0])).toBeCloseTo(111_195, -1));
it("simplifies a line while preserving endpoints", () =>
expect(
simplifyLine(
[
[0, 0],
[0.001, 0.00001],
[0.002, 0],
],
10,
),
).toEqual([
[0, 0],
[0.002, 0],
]));
it("analyses distance and elevation", () =>
expect(
analyseCollection({
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: {},
geometry: {
type: "LineString",
coordinates: [
[0, 0, 10],
[0.01, 0, 25],
],
},
},
],
}),
).toMatchObject({ points: 2, features: 1, ascent: 15, descent: 0 }));
it("formats directional DMS", () =>
expect(toDms(-13.5, "longitude")).toBe("13° 30 0.000″ W"));
});