fix(tours): check a city walk's stops off and save a stop from its dialog, with the walk under test (CW-01 to CW-05, CW-09)

Marking a stop of a city walk visited or skipped answered with a server
error every time: the write that keeps a changed status stamped its time as
a function call, which neither SQLite nor Postgres takes. It now uses the
clock the database itself spells, so a stop checked off, skipped or taken
back stays that way and the day plan of everyone on the trip follows.

The Save button of a stop's dialog in the planner did nothing, because it
sat outside the dialog's form. It saves the name, stay, importance and
protection again. A walk saved with two points that carry one key, as a
loop back to the start does, keeps that key on the first point and gives
the other one of its own, so checking one off never marks both. A walk put
on one day twice is read for an assistant from its first assignment.

The server tests cover the visits from the repository to the routes: per
day, through a moved and a removed assignment, a copy of the walk and a
copied trip without visits, a removed stop taking its visits along, and
the refusals for another trip, a stop the walk does not have, a member who
may not edit days and an unknown key or body. The MCP progress of a walk,
the station fields and counts of the tour list, and the contracts in
shared are tested too; the existing tests expect the keys every saved
point now carries, the station count of a list row and the new entity.
The client tests cover the stop dialog and its pills, the walk themes and
categories of the search along a tour, the stop menu of the waypoint list,
the walk's timing, routing and type choice, and answer the trip planner's
read of the visits in the tests instead of leaving it unanswered.
This commit is contained in:
Maurice
2026-10-19 23:58:57 +00:00
parent 2a8dbf91a8
commit e5f01e570a
36 changed files with 2182 additions and 43 deletions
@@ -0,0 +1,157 @@
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '../../../../tests/helpers/render';
import { StationDialog } from './StationDialog';
import { StationPills } from './stationParts';
import type { TourPlannerWaypoint } from './tourPlannerWaypoints';
const cathedral: TourPlannerWaypoint = {
id: 'p1',
lat: 48.1,
lng: 11.5,
role: 'via',
key: 'stop-cathedral',
name: 'Cathedral',
stayMinutes: 30,
importance: 'must',
protected: true,
openingHours: 'Mo-Su 09:00-18:00',
};
function open(point: TourPlannerWaypoint, fallbackName?: string) {
const onSave = vi.fn();
const onClose = vi.fn();
render(<StationDialog point={point} fallbackName={fallbackName} onSave={onSave} onClose={onClose} />);
return { onSave, onClose };
}
const stayField = () => screen.getByLabelText('Stay in minutes');
const nameField = () => screen.getByLabelText('Label');
describe('StationDialog (CW-02, CW-03, CW-10)', () => {
it('starts from the station as it is: its name, stay, importance and protection', () => {
open(cathedral);
expect(screen.getByTestId('station-dialog')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Cathedral' })).toBeInTheDocument();
expect(nameField()).toHaveValue('Cathedral');
expect(stayField()).toHaveValue('30');
expect(screen.getByRole('button', { name: 'Must see' })).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByRole('button', { name: 'Protected' })).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByText('A change proposed later keeps it in the walk.')).toBeInTheDocument();
});
it('names a station without a name by the row it stands in, or as unnamed', () => {
open({ id: 'p2', lat: 48.11, lng: 11.51, role: 'via' }, 'Stop 2');
expect(screen.getByRole('heading', { name: 'Stop 2' })).toBeInTheDocument();
expect(nameField()).toHaveAttribute('placeholder', 'Stop 2');
expect(stayField()).toHaveValue('');
expect(screen.getByRole('button', { name: 'Regular' })).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByRole('button', { name: 'Protected' })).toHaveAttribute('aria-pressed', 'false');
fireEvent.change(nameField(), { target: { value: 'Fountain' } });
expect(screen.getByRole('heading', { name: 'Fountain' })).toBeInTheDocument();
});
it('calls a station without a name and without a row name an unnamed stop', () => {
open({ id: 'p3', lat: 48.12, lng: 11.52, role: 'end' });
expect(screen.getByRole('heading', { name: 'Unnamed stop' })).toBeInTheDocument();
expect(nameField()).toHaveAttribute('placeholder', 'What is here');
});
it('takes whole minutes up to a day only, and says so', () => {
const { onSave } = open(cathedral);
for (const typed of ['abc', '2000', '12.5', '-3']) {
fireEvent.change(stayField(), { target: { value: typed } });
expect(screen.getByText('Enter whole minutes, up to a day.')).toBeInTheDocument();
expect(screen.getByTestId('station-save')).toBeDisabled();
}
fireEvent.submit(screen.getByTestId('station-dialog').closest('form') as HTMLFormElement);
expect(onSave).not.toHaveBeenCalled();
fireEvent.change(stayField(), { target: { value: '1440' } });
expect(screen.queryByText('Enter whole minutes, up to a day.')).not.toBeInTheDocument();
expect(screen.getByText('Empty means not known yet; 0 for a point you only pass.')).toBeInTheDocument();
expect(screen.getByTestId('station-save')).toBeEnabled();
// A submit of the form saves too, and keeps the page where it is.
const submitted = fireEvent.submit(screen.getByTestId('station-dialog').closest('form') as HTMLFormElement);
expect(submitted).toBe(false);
expect(onSave).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({ key: 'stop-cathedral', stayMinutes: 1440 })
);
});
it('saves the edited station with its key and opening hours, a stay left empty as not known', () => {
const { onSave, onClose } = open(cathedral);
fireEvent.change(nameField(), { target: { value: ' Old cathedral ' } });
fireEvent.change(stayField(), { target: { value: '' } });
fireEvent.click(screen.getByRole('button', { name: 'Optional' }));
expect(screen.getByText('Can be left out when time runs short.')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'Protected' }));
fireEvent.click(screen.getByTestId('station-save'));
expect(onSave).toHaveBeenCalledExactlyOnceWith({
id: 'p1',
lat: 48.1,
lng: 11.5,
role: 'via',
key: 'stop-cathedral',
openingHours: 'Mo-Su 09:00-18:00',
name: 'Old cathedral',
importance: 'optional',
});
expect(onClose).not.toHaveBeenCalled();
});
it('saves 0 as a point passed through, and normal importance and a blank name as none', () => {
const { onSave } = open(cathedral);
fireEvent.change(nameField(), { target: { value: ' ' } });
fireEvent.change(stayField(), { target: { value: ' 0 ' } });
fireEvent.click(screen.getByRole('button', { name: 'Regular' }));
expect(screen.getByText('Visited as the walk goes.')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('station-save'));
expect(onSave).toHaveBeenCalledExactlyOnceWith({
id: 'p1',
lat: 48.1,
lng: 11.5,
role: 'via',
key: 'stop-cathedral',
openingHours: 'Mo-Su 09:00-18:00',
stayMinutes: 0,
protected: true,
});
});
it('cancelling closes the dialog and saves nothing', () => {
const { onSave, onClose } = open(cathedral);
fireEvent.change(nameField(), { target: { value: 'Changed' } });
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(onClose).toHaveBeenCalledOnce();
expect(onSave).not.toHaveBeenCalled();
});
});
describe('StationPills (CW-02, CW-03, CW-10)', () => {
const pills = (point: Partial<TourPlannerWaypoint>) => {
render(<StationPills point={{ id: 'p', lat: 0, lng: 0, role: 'via', ...point }} />);
return screen.getByTestId('station-pills');
};
it('says a stay nobody entered is unknown, and nothing of a normal, unprotected station', () => {
const row = pills({});
expect(row).toHaveTextContent('Stay unknown');
expect(row).not.toHaveTextContent('Must see');
expect(row).not.toHaveTextContent('Optional');
expect(screen.queryByLabelText('Protected')).not.toBeInTheDocument();
});
it('names a point passed through', () => {
expect(pills({ stayMinutes: 0 })).toHaveTextContent('Passing through');
});
it('shows the stay, a must-see and a protection', () => {
const row = pills({ stayMinutes: 45, importance: 'must', protected: true });
expect(row).toHaveTextContent('45');
expect(row).toHaveTextContent('Must see');
expect(screen.getByLabelText('Protected')).toBeInTheDocument();
});
it('shows an optional station as optional', () => {
expect(pills({ stayMinutes: 90, importance: 'optional' })).toHaveTextContent('Optional');
});
});
@@ -49,7 +49,9 @@ export function StationDialog({
const stayMinutes = parseStay(stay);
const stayInvalid = stayMinutes === undefined;
const save = () => {
// The footer sits outside the dialog's form: its button saves by its own click, and a submit of the form stays here.
const save = (event?: { preventDefault: () => void }) => {
event?.preventDefault();
if (stayInvalid) return;
onSave(
withStationFields(point, {
@@ -85,7 +87,7 @@ export function StationDialog({
<DialogFooter>
<FooterSpacer />
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
<DialogButton variant="primary" type="submit" disabled={stayInvalid} data-testid="station-save">
<DialogButton variant="primary" onClick={() => save()} disabled={stayInvalid} data-testid="station-save">
{t('common.save')}
</DialogButton>
</DialogFooter>
@@ -749,7 +749,7 @@ describe('TourPlannerRail', () => {
expect(controller.cancelNewTour).toHaveBeenCalledOnce()
rerender(<TourPlannerRail planner={controller} />)
fireEvent.click(screen.getByRole('button', { name: 'Discard changes and start new tour' }))
fireEvent.click(screen.getByRole('button', { name: 'Discard and start' }))
expect(controller.startNewTour).toHaveBeenCalledWith(true)
})
@@ -44,6 +44,23 @@ describe('TourTypeFields (PAD-01)', () => {
expect(field).toHaveAttribute('aria-expanded', 'false');
});
it('CW-01: a city walk is a type of its own, on foot from stop to stop, with no fields of a bike or a boat', () => {
const hike = planner({ tourType: 'hike', isPaddle: false });
const { unmount } = render(<TourTypeFields planner={hike} locked={false} />);
fireEvent.click(screen.getByTestId('tour-type-select'));
const option = screen.getByTestId('tour-type-option-walk');
expect(option).toHaveTextContent('City / sightseeing walk');
expect(option).toHaveTextContent('On foot from stop to stop, without a hiking limit');
fireEvent.click(option);
expect(hike.setTourType).toHaveBeenCalledWith('walk');
unmount();
render(<TourTypeFields planner={planner({ tourType: 'walk', isPaddle: false })} locked={false} />);
expect(screen.getByTestId('tour-type-select')).toHaveTextContent('City / sightseeing walk');
expect(screen.queryByTestId('tour-planner-paddle-fields')).not.toBeInTheDocument();
expect(screen.queryByTestId('tour-planner-bike-fields')).not.toBeInTheDocument();
});
it('BIK-01 to BIK-04: a bike tour names its profile like a boat, with what the profile asks for', () => {
const bike = planner({ tourType: 'bike', isPaddle: false, isBike: true, bikeProfile: 'gravel' });
render(<TourTypeFields planner={bike} locked={false} />);
@@ -1,4 +1,5 @@
// FE-TOUR-WAYPOINT-LIST-001 to FE-TOUR-WAYPOINT-LIST-006: shaping points and the water router's answers in the list (P2A-03, P2A-05, PAD-11).
// FE-TOUR-WAYPOINT-LIST-001 to FE-TOUR-WAYPOINT-LIST-007: shaping points, the water router's answers
// and a city walk's stops in the list (P2A-03, P2A-05, PAD-11, CW-01).
import userEvent from '@testing-library/user-event';
import type { PaddleRouteLeg } from '@trek/shared';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -171,4 +172,48 @@ describe('TourWaypointList', () => {
await userEvent.click(screen.getByTestId('tour-planner-route-on-water'));
expect(controller.routeDrawnLegsOnWater).toHaveBeenCalled();
});
it('FE-TOUR-WAYPOINT-LIST-007: a city walk names its stops, shows their stay and edits one stop from its menu', async () => {
const cathedral = {
...STOP,
key: 'stop-cathedral',
name: 'Cathedral',
stayMinutes: 30,
importance: 'must' as const,
};
const controller = planner({
tourType: 'walk',
waypoints: [START, SHAPE, cathedral, END],
selectedWaypointId: 'b',
});
render(<TourWaypointList planner={controller} canEdit isSaving={false} />);
const rows = screen.getAllByTestId('tour-planner-waypoint-row');
expect(within(at(rows, 2)).getByTestId('tour-planner-waypoint-name')).toHaveTextContent('Cathedral');
expect(within(at(rows, 2)).getByTestId('station-pills')).toHaveTextContent('Must see');
expect(within(at(rows, 0)).getByTestId('station-pills')).toHaveTextContent('Stay unknown');
expect(within(at(rows, 1)).queryByTestId('station-pills')).not.toBeInTheDocument();
await userEvent.click(within(at(rows, 2)).getByRole('button', { name: 'More actions' }));
await userEvent.click(screen.getByRole('button', { name: 'Edit stop' }));
const stay = screen.getByLabelText('Stay in minutes');
await userEvent.clear(stay);
await userEvent.type(stay, '45');
await userEvent.click(screen.getByTestId('station-save'));
expect(screen.queryByTestId('station-dialog')).not.toBeInTheDocument();
expect(controller.editWaypoints).toHaveBeenCalledTimes(1);
const update = vi.mocked(controller.editWaypoints).mock.calls[0]?.[0] as (
points: TourPlannerController['waypoints']
) => TourPlannerController['waypoints'];
expect(update([START, SHAPE, cathedral, END])).toEqual([START, SHAPE, { ...cathedral, stayMinutes: 45 }, END]);
});
it('FE-TOUR-WAYPOINT-LIST-007b: a hike has no stop pills and no stop to edit', async () => {
const controller = planner({ selectedWaypointId: 'b' });
render(<TourWaypointList planner={controller} canEdit isSaving={false} />);
expect(screen.queryByTestId('station-pills')).not.toBeInTheDocument();
await userEvent.click(
within(at(screen.getAllByTestId('tour-planner-waypoint-row'), 2)).getByRole('button', { name: 'More actions' })
);
expect(screen.queryByRole('button', { name: 'Edit stop' })).not.toBeInTheDocument();
});
});
@@ -88,6 +88,34 @@ describe('tourPlannerFacts', () => {
expect(unknown.walkingDurationMinutes).toBeNull();
expect(unknown.savedDurationSeconds).toBeNull();
});
it('CW-02: times a city walk by the router on foot, its stays on top in place of breaks, and saves no hiking limit', () => {
const analysis = { distanceKm: 4, gain: 300, loss: 300 } as TourPlannerFactsInput['routeAnalysis'];
const walk = hike({
tourType: 'walk',
routeAnalysis: analysis,
durationSeconds: 3_000,
breakAdditionalMinutes: 40,
stationStayMinutes: 75,
hikingPreferences: { avoid_steps: true },
});
const facts = tourPlannerFacts(walk);
expect(facts.walkingDurationMinutes).toBe(50);
expect(facts.automaticPlannedTotalMinutes).toBe(125);
expect(facts.plannedTotalMinutes).toBe(125);
expect(facts.savedDurationSeconds).toBe(3_000);
expect(facts.typeFields).toMatchObject({
tour_type: 'walk',
max_hiking_difficulty: null,
hiking_preferences: null,
bike_profile: null,
boat_type: null,
});
// Stays nobody entered count for nothing; a total typed by hand still wins.
expect(tourPlannerFacts({ ...walk, stationStayMinutes: null }).automaticPlannedTotalMinutes).toBe(50);
expect(tourPlannerFacts({ ...walk, plannedDurationMinutes: 180 }).plannedTotalMinutes).toBe(180);
expect(tourPlannerFacts({ ...walk, durationSeconds: null }).automaticPlannedTotalMinutes).toBeNull();
});
});
describe('usePlannerHistory', () => {
@@ -1,8 +1,12 @@
// FE-TOUR-WAYPOINTS-001 to FE-TOUR-WAYPOINTS-005: the editor's waypoint model, shaping points and drawn legs (P2A-03, PAD-11).
// FE-TOUR-WAYPOINTS-001 to FE-TOUR-WAYPOINTS-007: the editor's waypoint model, shaping points, drawn legs
// and a city walk's stations (P2A-03, PAD-11, CW-01 to CW-04).
import type { TourWaypoint } from '@trek/shared';
import { describe, expect, it } from 'vitest';
import {
normalizePlannerWaypoints,
plannerWaypointsOf,
sameWaypointSnapshot,
savedWaypointsOf,
tourWaypointKey,
withDrawnLegsRouted,
withShaping,
@@ -80,4 +84,66 @@ describe('tourPlannerWaypoints', () => {
expect(sameWaypointSnapshot([A, B, C], [A, B, C])).toBe(true);
expect(normalizePlannerWaypoints([C, A, B]).map((point) => point.role)).toEqual(['start', 'via', 'end']);
});
const SAVED: TourWaypoint[] = [
{
lat: 48.1,
lng: 11.5,
role: 'start',
sequence: 0,
key: 'stop-cathedral',
name: 'Cathedral',
stay_minutes: 30,
importance: 'must',
protected: true,
opening_hours: 'Mo-Su 09:00-18:00',
},
{ lat: 48.105, lng: 11.505, role: 'via', sequence: 1, key: 'shape-1', shaping: true },
{ lat: 48.11, lng: 11.51, role: 'end', sequence: 2, key: 'stop-market', stay_minutes: 0 },
];
const ids = () => {
let next = 0;
return () => `p${++next}`;
};
it("FE-TOUR-WAYPOINTS-006: a saved walk's stations come into the editor with their key, name, stay, importance and hours", () => {
const points = plannerWaypointsOf(SAVED, ids());
expect(points).toEqual([
{
id: 'p1',
lat: 48.1,
lng: 11.5,
role: 'start',
key: 'stop-cathedral',
name: 'Cathedral',
stayMinutes: 30,
importance: 'must',
protected: true,
openingHours: 'Mo-Su 09:00-18:00',
},
{ id: 'p2', lat: 48.105, lng: 11.505, role: 'via', key: 'shape-1', shaping: true },
// A stay of 0 is a point passed through, kept as such.
{ id: 'p3', lat: 48.11, lng: 11.51, role: 'end', key: 'stop-market', stayMinutes: 0 },
]);
expect(savedWaypointsOf(points, 'walk')).toEqual(SAVED);
});
it("FE-TOUR-WAYPOINTS-007: another type sends a station's key, name and hours, but no stay, importance or protection", () => {
const points = plannerWaypointsOf(SAVED, ids());
const plain = [
{
lat: 48.1,
lng: 11.5,
role: 'start',
sequence: 0,
key: 'stop-cathedral',
name: 'Cathedral',
opening_hours: 'Mo-Su 09:00-18:00',
},
{ lat: 48.105, lng: 11.505, role: 'via', sequence: 1, key: 'shape-1', shaping: true },
{ lat: 48.11, lng: 11.51, role: 'end', sequence: 2, key: 'stop-market' },
];
expect(savedWaypointsOf(points, 'hike')).toEqual(plain);
expect(savedWaypointsOf(points)).toEqual(plain);
});
});
@@ -12,7 +12,7 @@ vi.mock('../../Map/valhallaRoute', () => ({
valhallaTurn,
}))
import { enrichTourElevations, parseValhallaElevation, routeBikeTour, routeWalkingTour, type TourRouteResult } from './tourRouting'
import { enrichTourElevations, parseValhallaElevation, routeBikeTour, routeCityWalk, routeWalkingTour, type TourRouteResult } from './tourRouting'
/** A route as the planner reads it, for the cases that expect one. */
const route = async (...args: Parameters<typeof routeWalkingTour>) => (await routeWalkingTour(...args)) as TourRouteResult | null
@@ -229,4 +229,10 @@ describe('routing on land, bike profiles and unreachable points (BIK-01)', () =>
await routeWalkingTour([{ lat: 47.39, lng: 11.01, fixedLeg: free }, { lat: 47.392, lng: 11.012 }, { lat: 47.4, lng: 11.02 }])
).toEqual({ unreachable: 1, snappedMeters: 400 })
})
it('TOUR-ROUTING-033: a city walk goes on foot with no hiking limit and no choice of a hike (CW-01)', async () => {
valhallaRun.mockResolvedValueOnce(run([3, 4]))
expect(await routeCityWalk(waypoints)).toMatchObject({ distanceMeters: 1500, durationSeconds: 300 })
expect(valhallaRun).toHaveBeenCalledWith(waypoints, 'walking', [], undefined, {})
})
})
@@ -13,7 +13,7 @@ import { usePoiInsertion, type PoiInsertionPlanner } from './usePoiInsertion';
import { useTourPoiMarkers } from './useTourPoiMarkers';
import { useTourPoiSearch } from './useTourPoiSearch';
// FE-TOUR-POI-001 to FE-TOUR-POI-010
// FE-TOUR-POI-001 to FE-TOUR-POI-015
vi.mock('../planner/useWaypointPlaceNames', () => ({ useWaypointPlaceNames: () => ({}) }));
@@ -246,3 +246,107 @@ describe('TourPoiSearchCard', () => {
expect(result.current.outcome).toEqual({ kind: 'measuring', name: 'Drinking water' });
});
});
describe('a city walk along its places (CW-05)', () => {
const CAFE: TourPoi = {
...SPRING,
id: 'node:3',
name: 'Cafe Luitpold',
category: 'cafe',
kind: 'amenity=cafe',
opening_hours: null,
};
const walkPlanner = () =>
({ ...searchPlanner({ tourType: 'walk' }), ...insertionPlanner() }) as unknown as TourPlannerController;
const themeButton = (theme: string) => screen.getByTestId(`tour-poi-theme-${theme}`);
it('FE-TOUR-POI-011: a walk offers four themes; one sets its categories at once, a change of them leaves it', async () => {
const planner = walkPlanner();
render(<TourPoiSearchCard planner={planner} />);
const themes = screen.getByTestId('tour-poi-themes');
expect(
within(themes)
.getAllByRole('button')
.map((button) => button.textContent)
).toEqual(['Culture and history', 'Parks and views', 'Food and local life', 'A bit of everything']);
// The walk starts with its first three categories, which no theme is.
for (const theme of ['culture', 'parks', 'food', 'mixed'])
expect(themeButton(theme)).toHaveAttribute('aria-pressed', 'false');
expect(themes).toHaveTextContent('Your own pick of categories below; a theme sets them for you.');
fireEvent.click(themeButton('food'));
expect(themeButton('food')).toHaveAttribute('aria-pressed', 'true');
expect(themes).toHaveTextContent('Coffee shops, places to eat and markets along the route.');
expect(screen.getByTestId('tour-poi-categories')).toHaveTextContent('Coffee shops, Places to eat +1');
fireEvent.click(screen.getByTestId('tour-poi-search'));
await waitFor(() =>
expect(search).toHaveBeenCalledWith(
4,
expect.objectContaining({ tour_type: 'walk', categories: ['cafe', 'restaurant', 'market'] }),
expect.any(AbortSignal)
)
);
fireEvent.click(screen.getByTestId('tour-poi-categories'));
fireEvent.click(screen.getByRole('button', { name: 'Markets' }));
expect(themeButton('food')).toHaveAttribute('aria-pressed', 'false');
expect(themes).toHaveTextContent('Your own pick of categories below; a theme sets them for you.');
});
it('FE-TOUR-POI-012: the category field names two categories, counts the rest, and says when none is chosen', () => {
render(<TourPoiSearchCard planner={walkPlanner()} />);
const field = screen.getByTestId('tour-poi-categories');
expect(field).toHaveTextContent('Sights, Museums and galleries +1');
expect(field).toHaveAttribute('aria-expanded', 'false');
fireEvent.click(field);
expect(field).toHaveAttribute('aria-expanded', 'true');
const list = screen.getByRole('group', { name: 'What to look for' });
fireEvent.click(within(list).getByRole('button', { name: 'Parks and gardens' }));
expect(field).toHaveTextContent('Sights, Museums and galleries');
expect(field).not.toHaveTextContent('+1');
fireEvent.click(within(list).getByRole('button', { name: 'Sights' }));
fireEvent.click(within(list).getByRole('button', { name: 'Museums and galleries' }));
expect(field).toHaveTextContent('No category chosen');
expect(screen.getByTestId('tour-poi-search')).toBeDisabled();
});
it('FE-TOUR-POI-013: a place found for a theme says which theme suggested it', async () => {
search.mockResolvedValue({ ...ANSWER, pois: [CAFE, SPRING] });
render(<TourPoiSearchCard planner={walkPlanner()} />);
fireEvent.click(themeButton('food'));
fireEvent.click(screen.getByTestId('tour-poi-search'));
const cafe = await screen.findByTestId('tour-poi-node:3');
fireEvent.click(within(cafe).getByRole('button', { name: /Cafe Luitpold/ }));
expect(within(cafe).getByText('Suggested for Food and local life')).toBeInTheDocument();
fireEvent.click(within(screen.getByTestId('tour-poi-node:1')).getByRole('button', { name: /Spring/ }));
expect(screen.queryByText('Suggested for Food and local life')).not.toBeInTheDocument();
});
it('FE-TOUR-POI-014: a hike has no themes', () => {
render(<TourPoiSearchCard planner={searchPlanner()} />);
expect(screen.queryByTestId('tour-poi-themes')).not.toBeInTheDocument();
expect(screen.getByTestId('tour-poi-categories')).toHaveTextContent('Viewpoints, Huts and shelters +1');
});
it('FE-TOUR-POI-015: a place taken in keeps its name and opening hours, and a place without them adds none', () => {
const planner = insertionPlanner();
const { result } = renderHook(() => usePoiInsertion(planner), { wrapper: TranslationProvider });
act(() => {
result.current.insert(SPRING);
});
act(() => {
result.current.insert({ ...CAFE, id: 'node:4', name: '', along_m: 400 });
});
const added = vi
.mocked(planner.editWaypoints)
.mock.calls.map(
([update]) =>
(update as (points: TourPlannerWaypoint[]) => TourPlannerWaypoint[])(POINTS).find(
(point) => !POINTS.includes(point)
) as TourPlannerWaypoint
);
expect(added[0]).toMatchObject({ name: 'Spring', openingHours: 'Mo-Su 08:00-18:00' });
expect(added[1]).not.toHaveProperty('name');
expect(added[1]).not.toHaveProperty('openingHours');
});
});