Files
BuTzZ b98ec8bc6f
Test and publish container images / test (push) Successful in 2m27s
Test and publish container images / publish (push) Failing after 4s
Hinweise optimiert
2026-07-27 13:04:32 +02:00

80 lines
2.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 &amp; Hamm &lt;Test&gt;");
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/);
});
it("does not export retired route warnings", () => {
const gpx = createRouteGpx({
...routeFixture,
warnings: [
{
code: "FAIRWAY_ROUTE",
severity: "info",
message: "Alter Graph-Hinweis"
},
{
code: "NO_KNOWN_DEPTH",
severity: "caution",
message: "Alter Tiefen-Hinweis"
},
{
code: "ROUTE_SEARCH_LIMITED",
severity: "caution",
message: "Aktueller Such-Hinweis"
}
]
});
expect(gpx).not.toContain("Alter Graph-Hinweis");
expect(gpx).not.toContain("Alter Tiefen-Hinweis");
expect(gpx).toContain("Aktueller Such-Hinweis");
});
});
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" }],
dataSources: ["OpenStreetMap <curated>"],
routingMode: "fairway"
};