feat(tours): bike tours in the planner, CyclOSM, and the planned cards' last points (BIK-01 to BIK-06, RTE-01, IO-01, LIB-02)

The tour type is a dropdown; a bike tour picks its profile, routes for it,
says when a point lies off every way, and shows what it runs on: surfaces,
kinds of way and, for a mountain bike, the trail grades, each pointed at on
the map. A type's own map (OpenHikingMap for a hike, CyclOSM for a bike tour)
is offered while a tour of that type is open, with an admin switch each.

From the planned cards: a hike avoids steep climbs, steps or ferries, nothing
else; a saved tour can be shared where the platform takes GPX files; and the
tours rail adds a tour from one menu: plan new, import GPX, or take one over
from another trip.
This commit is contained in:
Maurice
2026-10-19 21:33:49 +02:00
parent adcaca3c5f
commit 73237ffedb
85 changed files with 3728 additions and 647 deletions
@@ -0,0 +1,46 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import apiClient from '../api/client';
import { cycleMapAdminApi, hikingMapAdminApi } from '../api/tourBaseMaps';
import { tourTrailGradeApi } from '../api/tourTrailGrade';
import { OnlineOnlyError } from './onlineOnly';
import { tourTrailGradeRepo } from './tourTrailGradeRepo';
// FE-REPO-TRAIL-GRADE-001 to FE-REPO-TRAIL-GRADE-003
const network = vi.hoisted(() => ({ offline: false }));
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: () => network.offline }));
beforeEach(() => {
network.offline = false;
vi.restoreAllMocks();
});
describe('tourTrailGradeRepo (BIK-05)', () => {
it('FE-REPO-TRAIL-GRADE-001: asks only online, and offline says so instead', async () => {
network.offline = true;
const grades = vi.spyOn(tourTrailGradeApi, 'grades');
await expect(tourTrailGradeRepo.grades(3, { way_ids: [1] })).rejects.toBeInstanceOf(OnlineOnlyError);
expect(grades).not.toHaveBeenCalled();
});
it('FE-REPO-TRAIL-GRADE-002: posts the ways to the trip, with a timeout long enough for a long tour', async () => {
const answer = { ways: [], unanswered: [] };
const post = vi.spyOn(apiClient, 'post').mockResolvedValue({ data: answer });
const signal = new AbortController().signal;
await expect(tourTrailGradeRepo.grades(3, { way_ids: [1, 2] }, signal)).resolves.toBe(answer);
expect(post).toHaveBeenCalledWith('/trips/3/tours/trail-grades', { way_ids: [1, 2] }, { signal, timeout: 60_000 });
});
});
describe('tourBaseMaps admin api (MAP-01, BIK-06)', () => {
it('FE-REPO-TRAIL-GRADE-003: each map on terms has its own switch, read and written at its own path', async () => {
const get = vi.spyOn(apiClient, 'get').mockResolvedValue({ data: { enabled: true } });
const put = vi.spyOn(apiClient, 'put').mockResolvedValue({ data: { enabled: false } });
expect(await cycleMapAdminApi.get()).toEqual({ enabled: true });
expect(get).toHaveBeenCalledWith('/admin/tours-cycle-map');
expect(await cycleMapAdminApi.update(false)).toEqual({ enabled: false });
expect(put).toHaveBeenCalledWith('/admin/tours-cycle-map', { enabled: false });
await hikingMapAdminApi.update(true);
expect(put).toHaveBeenLastCalledWith('/admin/tours-hiking-map', { enabled: true });
});
});
+19
View File
@@ -0,0 +1,19 @@
import type { TourTrailGradeRequest, TourTrailGradeResponse } from '@trek/shared';
import { tourTrailGradeApi } from '../api/tourTrailGrade';
import { requireOnline } from './onlineOnly';
/**
* BIK-05, online only: the grades come from OpenStreetMap through the server,
* and the server keeps them a day; the client keeps nothing. Offline the card
* says so.
*/
export const tourTrailGradeRepo = {
async grades(
tripId: number | string,
body: TourTrailGradeRequest,
signal?: AbortSignal
): Promise<TourTrailGradeResponse> {
requireOnline();
return await tourTrailGradeApi.grades(tripId, body, signal);
},
};