mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
test(tours): follow the reworked planner, ferrata and map stage in their suites; keep the map's waypoint list stable between renders
This commit is contained in:
@@ -203,7 +203,7 @@ describe('TripPlannerPage — shell', () => {
|
||||
toursEnabled: true,
|
||||
places: [],
|
||||
});
|
||||
const input = screen.getByRole('combobox', { name: 'reservations.searchLocation' });
|
||||
const input = screen.getByRole('combobox', { name: 'tours.planner.mapSearch' });
|
||||
const mapElement = screen.getByTestId('map-view');
|
||||
|
||||
await user.type(input, 'Kyoto');
|
||||
@@ -245,6 +245,6 @@ describe('TripPlannerPage — shell', () => {
|
||||
|
||||
view.unmount();
|
||||
renderPage({ activeTab: 'plan', showPlaceForm: true });
|
||||
expect(screen.queryByRole('combobox', { name: 'reservations.searchLocation' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('combobox', { name: 'tours.planner.mapSearch' })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { act, fireEvent, render, screen, waitFor } from '../../../tests/helpers/
|
||||
import { useTripFerratas } from '../../components/Ferratas/useTripFerratas';
|
||||
import type { MapViewProps } from '../../components/Map/mapViewContract';
|
||||
import { useSettingsStore } from '../../store/settingsStore';
|
||||
import { initialTourPlaceToolState, useTourPlaceToolStore } from '../../store/tourPlaceToolStore';
|
||||
import { TourPlannerMapStage, type TourPlannerMapStageProps } from './TourPlannerMapStage';
|
||||
|
||||
type Handler = (event?: unknown) => void;
|
||||
@@ -19,6 +20,21 @@ const stage = vi.hoisted(() => {
|
||||
once: vi.fn(() => map),
|
||||
off: vi.fn(() => map),
|
||||
loaded: vi.fn(() => false),
|
||||
// The style never finishes in these tests: the ferrata layer waits for it and draws nothing.
|
||||
isStyleLoaded: vi.fn(() => false),
|
||||
getContainer: vi.fn(() => document.body),
|
||||
getLayer: vi.fn(() => undefined),
|
||||
hasImage: vi.fn(() => false),
|
||||
addImage: vi.fn(),
|
||||
removeImage: vi.fn(),
|
||||
addSource: vi.fn(),
|
||||
addLayer: vi.fn(),
|
||||
removeLayer: vi.fn(),
|
||||
removeSource: vi.fn(),
|
||||
setFilter: vi.fn(),
|
||||
setPaintProperty: vi.fn(),
|
||||
queryRenderedFeatures: vi.fn(() => []),
|
||||
getCanvas: vi.fn(() => ({ style: {} })),
|
||||
getBounds: vi.fn(() => ({
|
||||
getSouth: () => 46.5,
|
||||
getWest: () => 11.7,
|
||||
@@ -153,6 +169,7 @@ async function openTerrain() {
|
||||
|
||||
beforeEach(() => {
|
||||
window.sessionStorage.clear();
|
||||
useTourPlaceToolStore.setState(initialTourPlaceToolState());
|
||||
stage.listeners.clear();
|
||||
stage.flatMap.props = null;
|
||||
stage.search.props = null;
|
||||
@@ -251,6 +268,7 @@ describe('TourPlannerMapStage', () => {
|
||||
null,
|
||||
false,
|
||||
{ south: 46, west: 7, north: 46, east: 7 },
|
||||
[],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -277,8 +295,8 @@ describe('TourPlannerMapStage', () => {
|
||||
const overlay = screen.getByTestId('ferrata-detail-overlay');
|
||||
// The right panel's 380px plus the 20px the layer pill keeps to the left one.
|
||||
expect(overlay.style.insetInlineEnd).toBe('400px');
|
||||
// Above the bottom row: its 12px gap, the 42px pill, the same gap again.
|
||||
expect(overlay.style.bottom).toBe('66px');
|
||||
// On the flat map nothing is under its corner: it rests at the edge gap.
|
||||
expect(overlay.style.bottom).toBe('12px');
|
||||
expect(overlay).toHaveTextContent('Via delle Trincee');
|
||||
expect(stage.flatMap.props?.ferrataLayer?.selectedId).toBe(group.id);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ const hookText = readFileSync(resolve(process.cwd(), 'src/pages/tripPlanner/useT
|
||||
const pageControllerText = readFileSync(resolve(process.cwd(), 'src/pages/tripPlanner/useTripPlannerPage.ts'), 'utf8')
|
||||
// The Tours map and its edit gates live in the map stage the page renders.
|
||||
const mapStageText = readFileSync(resolve(process.cwd(), 'src/pages/tripPlanner/TourPlannerMapStage.tsx'), 'utf8')
|
||||
// Which clicks place a point is decided by the map stage's points hook.
|
||||
const mapPointsText = readFileSync(resolve(process.cwd(), 'src/pages/tripPlanner/useTourMapPoints.ts'), 'utf8')
|
||||
const parse = (file: string, text: string) => ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true)
|
||||
const page = parse(pagePath, pageText)
|
||||
const hook = parse(hookPath, hookText)
|
||||
@@ -187,17 +189,18 @@ test('B4A desktop page delegates Tours state and permissions to its page hook',
|
||||
const mapClickGate = collect(mapStage, node => ts.isJsxAttribute(node)
|
||||
&& node.name.getText(mapStage) === 'onMapClick'
|
||||
&& node.initializer && ts.isJsxExpression(node.initializer)
|
||||
&& !!node.initializer.expression && /canEditRoute|canPlaceEdit/.test(node.initializer.expression.getText(mapStage)))
|
||||
&& !!node.initializer.expression && /onAdd/.test(node.initializer.expression.getText(mapStage)))
|
||||
assert.ok(mapClickGate.length > 0)
|
||||
// The gate the 2D and 3D maps share is derived from the place permission.
|
||||
assert.match(mapStageText, /const canEditRoute = canPlaceEdit && /)
|
||||
assert.match(mapStageText, /useTourMapPoints\(\{[\s\S]*?canPlaceEdit,/)
|
||||
assert.match(mapPointsText, /const canEditRoute = canPlaceEdit && /)
|
||||
})
|
||||
|
||||
test('B4A dedicated desktop controller retains GPX, draft, focus, and saved rail wiring', () => {
|
||||
assert.ok(callNamed(pageController, 'useTourPlanner'))
|
||||
assert.ok(pageText.includes('const pageState = useTripPlannerPage()'))
|
||||
assert.ok(pageControllerText.includes("tourPlanner.mode.type === 'view-gpx'"))
|
||||
for (const mode of ['new-draft', 'edit-saved']) assert.ok(mapStageText.includes(`tourPlanner.mode.type === '${mode}'`))
|
||||
for (const mode of ['new-draft', 'edit-saved']) assert.ok(mapPointsText.includes(`tourPlanner.mode.type === '${mode}'`))
|
||||
assert.match(pageControllerText, /readOnlyGpxAnalysis\?\.routeCoordinates/)
|
||||
assert.match(mapStageText, /routeProfileFocus=\{tourPlanner\.routeProfileFocus\}/)
|
||||
assert.match(pageText, /tourPlanner\.viewGpxTour\(tour, place\?\.route_geometry \?\? null\)/)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import type { useOutsidePressGuard } from '../../components/Ferratas/useOutsidePressGuard';
|
||||
import type { TourPlannerController } from '../../components/Tours/planner/useTourPlanner';
|
||||
import { useWaypointPlaceNames } from '../../components/Tours/planner/useWaypointPlaceNames';
|
||||
@@ -5,6 +6,7 @@ import { useTranslation } from '../../i18n';
|
||||
import { usePlacedPointHint } from './usePlacedPointHint';
|
||||
import { useTourMapPlacing, type TourMapMode } from './useTourMapPlacing';
|
||||
|
||||
const NO_POINTS: never[] = [];
|
||||
const ROLE_KEY = {
|
||||
start: 'tours.planner.start',
|
||||
via: 'tours.planner.via',
|
||||
@@ -44,7 +46,7 @@ export function useTourMapPoints({ tourPlanner, canPlaceEdit, mode, ferrataOpen,
|
||||
const { t } = useTranslation();
|
||||
const editing = tourPlanner.mode.type === 'new-draft' || tourPlanner.mode.type === 'edit-saved';
|
||||
// The same lookup as the waypoint list, so a pin is named on hover as its row is.
|
||||
const placeNames = useWaypointPlaceNames(editing ? tourPlanner.waypoints : []);
|
||||
const placeNames = useWaypointPlaceNames(editing ? tourPlanner.waypoints : NO_POINTS);
|
||||
const canEditRoute = canPlaceEdit && !tourPlanner.isSaving && editing;
|
||||
const { active, toggle, gate, attach } = useTourMapPlacing(mode);
|
||||
const placeOn = canEditRoute && active;
|
||||
@@ -61,16 +63,23 @@ export function useTourMapPoints({ tourPlanner, canPlaceEdit, mode, ferrataOpen,
|
||||
addWaypoint(lat, lng);
|
||||
};
|
||||
const onAdd = guard(gate(placeOn ? addPoint : undefined));
|
||||
|
||||
return {
|
||||
waypoints: {
|
||||
points: editing
|
||||
? tourPlanner.waypoints.map((point, index) => ({
|
||||
// Kept by identity while nothing about the points changed, so the map does not redraw its pins on every render.
|
||||
const { waypoints } = tourPlanner;
|
||||
const points = useMemo(
|
||||
() =>
|
||||
editing
|
||||
? waypoints.map((point, index) => ({
|
||||
...point,
|
||||
name: placeNames[point.id] ?? t('tours.planner.waypointLabel', { n: index + 1 }),
|
||||
detail: t(ROLE_KEY[point.role]),
|
||||
}))
|
||||
: [],
|
||||
: NO_POINTS,
|
||||
[editing, waypoints, placeNames, t]
|
||||
);
|
||||
|
||||
return {
|
||||
waypoints: {
|
||||
points,
|
||||
selectedId: editing ? tourPlanner.selectedWaypointId : null,
|
||||
onSelect: tourPlanner.setSelectedWaypointId,
|
||||
onMove: canEditRoute ? tourPlanner.setWaypointPosition : undefined,
|
||||
|
||||
Reference in New Issue
Block a user