Keep route drawings in sync
Test and publish container images / test (push) Successful in 2m26s
Test and publish container images / publish (push) Successful in 1m16s

This commit is contained in:
BuTzZ
2026-07-31 07:45:06 +02:00
parent 6cd697abfa
commit 6801fa9089
6 changed files with 258 additions and 31 deletions
+132 -2
View File
@@ -28,6 +28,7 @@ vi.mock("maplibre-gl", () => {
layerDefinitions = new globalThis.Map<string, any>();
renderedFeatures: any[] = [];
zoom = 13;
styleLoaded = true;
container: HTMLElement;
fitBounds = vi.fn(() => this);
easeTo = vi.fn(() => this);
@@ -110,7 +111,7 @@ vi.mock("maplibre-gl", () => {
}
isStyleLoaded() {
return true;
return this.styleLoaded;
}
getZoom() {
@@ -553,6 +554,128 @@ describe("MapView marine feature information", () => {
);
});
it("atomically replaces and clears route drawings while other map data is loading", async () => {
const stableOnPickCoordinate = vi.fn();
const stableOnMapReady = vi.fn();
const firstRoute: RouteResult = {
id: "first",
name: "Hauptroute",
geometry: {
type: "LineString",
coordinates: [
[7.1, 53.1],
[7.2, 53.2],
[7.3, 53.3]
]
},
distanceNm: 10,
eta: null,
warnings: [],
dataSources: [],
routingMode: "fairway"
};
const secondRoute: RouteResult = {
...firstRoute,
id: "second",
name: "Alternative 1",
geometry: {
type: "LineString",
coordinates: [
[8.1, 54.1],
[8.2, 54.2],
[8.3, 54.3],
[8.4, 54.4]
]
}
};
const view = render(
<MapView
config={config}
position={{ lat: 53.1, lon: 7.1 }}
accuracyM={5}
startPoint={{ lat: 53.1, lon: 7.1 }}
destination={{ lat: 53.3, lon: 7.3 }}
waypoints={[{ lat: 53.2, lon: 7.2 }]}
pickMode={null}
route={firstRoute}
guidanceActive
guidanceTarget={{ lat: 53.2, lon: 7.2 }}
onPickCoordinate={stableOnPickCoordinate}
onMapReady={stableOnMapReady}
/>
);
await act(async () => maplibreState.current.emit("load"));
const routeSource = maplibreState.current.sources.get("route");
const guidanceSource = maplibreState.current.sources.get("route-guidance");
const startSource = maplibreState.current.sources.get("start-point");
const destinationSource = maplibreState.current.sources.get("destination");
const waypointSource = maplibreState.current.sources.get("waypoints");
maplibreState.current.styleLoaded = false;
view.rerender(
<MapView
config={config}
position={{ lat: 54.1, lon: 8.1 }}
accuracyM={5}
startPoint={{ lat: 54.1, lon: 8.1 }}
destination={{ lat: 54.4, lon: 8.4 }}
waypoints={[{ lat: 54.3, lon: 8.3 }]}
pickMode={null}
route={secondRoute}
guidanceActive
guidanceTarget={{ lat: 54.2, lon: 8.2 }}
onPickCoordinate={stableOnPickCoordinate}
onMapReady={stableOnMapReady}
/>
);
expect(routeSource.setData).toHaveBeenLastCalledWith({
type: "Feature",
properties: {},
geometry: secondRoute.geometry
});
view.rerender(
<MapView
config={config}
position={{ lat: 54.1, lon: 8.1 }}
accuracyM={5}
startPoint={null}
destination={null}
waypoints={[]}
pickMode={null}
route={null}
guidanceActive={false}
guidanceTarget={null}
onPickCoordinate={stableOnPickCoordinate}
onMapReady={stableOnMapReady}
/>
);
expect(routeSource.setData).toHaveBeenLastCalledWith({
type: "Feature",
properties: {},
geometry: { type: "LineString", coordinates: [] }
});
expect(guidanceSource.setData).toHaveBeenLastCalledWith({
type: "FeatureCollection",
features: []
});
expect(startSource.setData).toHaveBeenLastCalledWith({
type: "FeatureCollection",
features: []
});
expect(destinationSource.setData).toHaveBeenLastCalledWith({
type: "FeatureCollection",
features: []
});
expect(waypointSource.setData).toHaveBeenLastCalledWith({
type: "FeatureCollection",
features: []
});
});
it("focuses a route event requested by the shared navigation workspace", async () => {
const stableOnMapReady = vi.fn();
const view = render(
@@ -636,7 +759,14 @@ describe("MapView marine feature information", () => {
startPoint={{ lat: 52, lon: 7 }}
destination={{ lat: 52, lon: 7.1 }}
pickMode={null}
route={null}
route={{
geometry: { type: "LineString", coordinates: [[7, 52], [7.1, 52]] },
distanceNm: 4,
eta: null,
warnings: [],
dataSources: [],
routingMode: "fairway"
}}
guidanceActive
guidanceTarget={{ lat: 52.001, lon: 7.01 }}
onPickCoordinate={vi.fn()}
+38 -1
View File
@@ -383,6 +383,7 @@ describe("RoutePlanner", () => {
});
it("opens the compact result view and keeps critical warnings above secondary route details", () => {
const onEditRoute = vi.fn();
const result = {
...routeOption("primary", "Hauptroute", 4),
warnings: [
@@ -411,6 +412,7 @@ describe("RoutePlanner", () => {
onClearDestination={vi.fn()}
onUseGpsAsStart={vi.fn()}
onSelectRoute={vi.fn()}
onEditRoute={onEditRoute}
onCollapse={vi.fn()}
/>
);
@@ -422,9 +424,44 @@ describe("RoutePlanner", () => {
expect(screen.queryByRole("button", { name: "Start auf Karte setzen" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Plan ändern" }));
expect(onEditRoute).toHaveBeenCalledTimes(1);
expect(screen.getByText("Route planen")).toBeVisible();
expect(screen.getByRole("button", { name: "Start auf Karte setzen" })).toBeVisible();
expect(screen.getByRole("button", { name: "Zur Route" })).toBeVisible();
});
it("explicitly discards a planned route through the parent state", () => {
const onCancelRoute = vi.fn();
const result = routeOption("primary", "Hauptroute", 4);
render(
<RoutePlanner
startPoint={{ lat: 52, lon: 7 }}
gpsPosition={null}
destination={{ lat: 52, lon: 7.1 }}
result={result}
routeOptions={[result]}
weatherReport={null}
weatherLoading={false}
weatherError={null}
loading={false}
error={null}
pickMode={null}
onSubmit={vi.fn()}
onPickStart={vi.fn()}
onPickDestination={vi.fn()}
onClearStart={vi.fn()}
onClearDestination={vi.fn()}
onUseGpsAsStart={vi.fn()}
onSelectRoute={vi.fn()}
onCancelRoute={onCancelRoute}
onCollapse={vi.fn()}
/>
);
fireEvent.click(screen.getByRole("button", { name: "Route verwerfen" }));
expect(onCancelRoute).toHaveBeenCalledTimes(1);
expect(screen.getByText("Route planen")).toBeVisible();
});
it("filters retired fairway and depth warnings from route results", () => {