Initial Watermaps import
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { RouteResult } from "@watermaps/shared";
|
||||
import { createRouteGpx } from "../src/lib/gpx";
|
||||
|
||||
describe("GPX export", () => {
|
||||
it("creates parseable GPX 1.1 route and track metadata", () => {
|
||||
const gpx = createRouteGpx(routeFixture, {
|
||||
name: "Emden & Hamm <Test>",
|
||||
createdAt: "2026-07-19T12:00:00.000Z"
|
||||
});
|
||||
const document = new DOMParser().parseFromString(gpx, "application/xml");
|
||||
const root = document.documentElement;
|
||||
|
||||
expect(document.querySelector("parsererror")).toBeNull();
|
||||
expect(root.localName).toBe("gpx");
|
||||
expect(root.getAttribute("version")).toBe("1.1");
|
||||
expect(root.namespaceURI).toBe("http://www.topografix.com/GPX/1/1");
|
||||
expect(document.getElementsByTagNameNS(root.namespaceURI, "metadata")).toHaveLength(1);
|
||||
expect(document.getElementsByTagNameNS(root.namespaceURI, "rte")).toHaveLength(1);
|
||||
expect(document.getElementsByTagNameNS(root.namespaceURI, "trk")).toHaveLength(1);
|
||||
expect(document.getElementsByTagNameNS(root.namespaceURI, "rtept")).toHaveLength(3);
|
||||
expect(document.getElementsByTagNameNS(root.namespaceURI, "trkpt")).toHaveLength(3);
|
||||
expect(document.getElementsByTagNameNS(root.namespaceURI, "time")[0]?.textContent).toBe("2026-07-19T12:00:00.000Z");
|
||||
expect(gpx).toContain("Emden & Hamm <Test>");
|
||||
expect(gpx).toContain("minlat=\"51.6814536\"");
|
||||
});
|
||||
|
||||
it("rejects invalid or incomplete geometry", () => {
|
||||
expect(() => createRouteGpx({
|
||||
...routeFixture,
|
||||
geometry: { type: "LineString", coordinates: [[7, 53]] }
|
||||
})).toThrow(/nicht genügend Punkte/);
|
||||
expect(() => createRouteGpx({
|
||||
...routeFixture,
|
||||
geometry: { type: "LineString", coordinates: [[7, 53], [181, 52]] }
|
||||
})).toThrow(/ungültige Koordinaten/);
|
||||
});
|
||||
});
|
||||
|
||||
const routeFixture: RouteResult = {
|
||||
id: "emden-hamm",
|
||||
name: "Emden – Hamm",
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
coordinates: [[7.186111, 53.344167], [7.1, 52.4], [7.8042615, 51.6814536]]
|
||||
},
|
||||
distanceNm: 153.69,
|
||||
eta: null,
|
||||
warnings: [{ code: "NOT_OFFICIAL", severity: "caution", message: "Nicht amtlich & vor Ort prüfen" }],
|
||||
minKnownDepthM: null,
|
||||
unknownDepthRatio: 1,
|
||||
dataSources: ["OpenStreetMap <curated>"],
|
||||
routingMode: "fairway"
|
||||
};
|
||||
Reference in New Issue
Block a user