mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
109 lines
3.8 KiB
TypeScript
109 lines
3.8 KiB
TypeScript
import { RoadtripHazardsService } from '../../../src/nest/roadtrip/roadtrip-hazards.service';
|
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
const polygon = {
|
|
type: 'Polygon',
|
|
coordinates: [
|
|
[
|
|
[10, 50],
|
|
[11, 50],
|
|
[11, 51],
|
|
[10, 50],
|
|
],
|
|
],
|
|
};
|
|
const feed = (features: unknown[]) => new Response(JSON.stringify({ type: 'FeatureCollection', features }));
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
describe('roadtrip hazard sources', () => {
|
|
it('isolates failed providers and caches concurrent reads', async () => {
|
|
const fetcher = vi.fn(async (url: string) => {
|
|
if (url.includes('dwd.de')) throw new Error('down');
|
|
return feed([]);
|
|
});
|
|
vi.stubGlobal('fetch', fetcher);
|
|
const service = new RoadtripHazardsService();
|
|
const [first, second] = await Promise.all([service.read(), service.read()]);
|
|
expect(first).toEqual(second);
|
|
expect(first.sources).toEqual([
|
|
{ source: 'DWD', status: 'unavailable' },
|
|
{ source: 'GDACS', status: 'ok' },
|
|
]);
|
|
await service.read();
|
|
expect(fetcher).toHaveBeenCalledTimes(2);
|
|
});
|
|
it('gives warnings that share a feature id an id of their own, the first keeping it', async () => {
|
|
const warning = (headline: string) => ({
|
|
id: 'Warnungen_Gemeinden_vereinigt.DEU-1',
|
|
geometry: polygon,
|
|
properties: { HEADLINE: headline, SENT: '2026-01-01T00:00:00Z', EXPIRES: '2099-01-01T00:00:00Z' },
|
|
});
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async (url: string) => feed(url.includes('dwd.de') ? [warning('Rain'), warning('Wind')] : [])),
|
|
);
|
|
const saved = await new RoadtripHazardsService().read();
|
|
expect(saved.hazards.map((hazard) => hazard.id)).toEqual([
|
|
'dwd-Warnungen_Gemeinden_vereinigt.DEU-1',
|
|
'dwd-Warnungen_Gemeinden_vereinigt.DEU-1-1',
|
|
]);
|
|
});
|
|
it('drops expired warnings and marks malformed records as incomplete', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async (url: string) =>
|
|
feed(
|
|
url.includes('dwd.de')
|
|
? [
|
|
{
|
|
geometry: polygon,
|
|
properties: { HEADLINE: 'Rain', SENT: '2026-01-01T00:00:00Z', EXPIRES: '2099-01-01T00:00:00Z' },
|
|
},
|
|
{
|
|
geometry: polygon,
|
|
properties: { HEADLINE: 'Old', SENT: '2020-01-01T00:00:00Z', EXPIRES: '2020-01-02T00:00:00Z' },
|
|
},
|
|
{ geometry: null, properties: {} },
|
|
]
|
|
: [],
|
|
),
|
|
),
|
|
);
|
|
const saved = await new RoadtripHazardsService().read();
|
|
expect(saved.hazards).toHaveLength(1);
|
|
expect(saved.hazards[0].title).toBe('Rain');
|
|
expect(saved.sources[0].status).toBe('partial');
|
|
});
|
|
it('uses affected polygons rather than the global event footprint', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async (url: string) => {
|
|
if (url.includes('dwd.de')) return feed([]);
|
|
if (url.includes('getgeometry'))
|
|
return feed([
|
|
{ geometry: polygon, properties: { Class: 'Poly_Affected' } },
|
|
{ geometry: polygon, properties: { Class: 'Poly_Global' } },
|
|
]);
|
|
return feed([
|
|
{
|
|
geometry: { type: 'Point', coordinates: [10, 50] },
|
|
properties: {
|
|
eventtype: 'FL',
|
|
eventid: 1,
|
|
episodeid: 2,
|
|
name: 'Flood',
|
|
description: 'Flood report',
|
|
datemodified: '2026-09-12T08:00:00',
|
|
iscurrent: 'true',
|
|
},
|
|
},
|
|
]);
|
|
}),
|
|
);
|
|
const saved = await new RoadtripHazardsService().read();
|
|
expect(saved.hazards[0].geometry).toEqual({ type: 'MultiPolygon', coordinates: [polygon.coordinates] });
|
|
expect(saved.hazards[0].updatedAt).toBe('2026-09-12T08:00:00.000Z');
|
|
});
|
|
});
|