mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
feat(tours): a city walk's arrivals and opening hours for the day it is on, at each stop in the planner and the detail (CW-02, CW-04)
A city walk now shows, at each stop, when the walk gets there, until when the stay lasts, and what the stop's opening hours say about that visit. The same lines appear under each stop row in the planner and under each stop in the walk's detail, in the user's 12 or 24 hour format. A conflict names the stop, the arrival, the end of the stay and the hours it was checked against, for instance "Lenbachhaus closes at 18:00, during the stay from 17:20 to 18:20 (open 10:00 to 18:00)", in the warning colour. Nothing is changed by these hints: no stop, order or route moves. The times belong to one day the walk is on. Opened from a day of the plan, the detail keeps that day, and checking stops off stays bound to it. Opened otherwise, and in the planner, a small pill above the stops names the day and its start, and the walk's other days can be picked from it; it starts on the first day with a start time. The pick is only what is looked at and is never saved, and another day never takes over the times quietly. Without a day, a date or a start time the line says what is missing and no arrival is shown. TREK keeps no time zone on a trip, so start, arrivals and opening hours are all read as the local time of the plan, and an arrival after midnight is said to be on the next day without being checked. Opening hours come from the trip place a stop stands for, as the travellers entered them, and otherwise from OpenStreetMap; a pill at each stop names the source, and a notice says the hours are a hint to check. A stop without hours stays unknown and is never shown as open, hours that are not in a plain form are shown as written, and an arrival that is only a lower bound, because a stay before it is not entered yet, is not judged unless no later arrival could escape the conflict. A trip place that a stop stands for also gives the stop its name before "Stop N". The arrival at a stop is found where the route passes it in the walk's order, so the end of a loop and a stop passed on the way out and back get the right time. The rules live once in the shared package, for the server to give the same answers. The walk's detail reads its stops again after a save, its own or a teammate's.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
// FE-TOUR-WAYPOINT-LIST-001 to FE-TOUR-WAYPOINT-LIST-008: shaping points, the water router's answers
|
||||
// and a city walk's stops in the list (P2A-03, P2A-05, PAD-11, CW-01).
|
||||
// FE-TOUR-WAYPOINT-LIST-001 to FE-TOUR-WAYPOINT-LIST-011: shaping points, the water router's answers
|
||||
// and a city walk's stops in the list, with their arrivals and opening hours on a day of the walk
|
||||
// (P2A-03, P2A-05, PAD-11, CW-01, CW-02, CW-04).
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import type { PaddleRouteLeg } from '@trek/shared';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { buildAssignment, buildDay, buildPlace } from '../../../../tests/helpers/factories';
|
||||
import { render, screen, within } from '../../../../tests/helpers/render';
|
||||
import { resetAllStores, seedStore } from '../../../../tests/helpers/store';
|
||||
import { hikePlannerDefaults } from '../../../../tests/helpers/tourPlannerStub';
|
||||
import { useSettingsStore } from '../../../store/settingsStore';
|
||||
import { useTripStore } from '../../../store/tripStore';
|
||||
import type { PaddleTourRoute } from './paddleRouting';
|
||||
import TourWaypointList from './TourWaypointList';
|
||||
import type { TourPlannerController } from './useTourPlanner';
|
||||
@@ -232,4 +235,85 @@ describe('TourWaypointList', () => {
|
||||
await userEvent.click(within(at(rows, 2)).getByRole('button', { name: 'More actions' }));
|
||||
expect(screen.queryByRole('button', { name: 'Edit stop' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('a city walk on a day of the plan (CW-02, CW-04)', () => {
|
||||
const lenbachhaus = {
|
||||
...START,
|
||||
key: 'stop-lenbachhaus',
|
||||
name: 'Lenbachhaus',
|
||||
stayMinutes: 60,
|
||||
openingHours: 'Mo-Fr 10:00-18:00',
|
||||
};
|
||||
const cafe = { ...STOP, name: 'Cafe', stayMinutes: 30 };
|
||||
const ROUTE: Array<[number, number]> = [
|
||||
[49.1, 12.1],
|
||||
[49.08, 12.11],
|
||||
[49.05, 12.12],
|
||||
[49.0, 12.1],
|
||||
];
|
||||
|
||||
/** A walk being edited, its route planned for the points as they are; on Monday 19 October from 17:20. */
|
||||
function walkPlanner(overrides: Partial<TourPlannerController> = {}) {
|
||||
return planner({
|
||||
tourType: 'walk',
|
||||
editingPlaceId: 42,
|
||||
waypoints: [lenbachhaus, SHAPE, cafe, END],
|
||||
route: ROUTE,
|
||||
routeCurrent: true,
|
||||
walkingDurationMinutes: 40,
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
const day = buildDay({ id: 7, date: '2026-10-19' });
|
||||
const entry = buildAssignment({
|
||||
day_id: 7,
|
||||
place_id: 42,
|
||||
assignment_time: '17:20',
|
||||
place: buildPlace({ id: 42 }),
|
||||
});
|
||||
seedStore(useTripStore, { days: [day], assignments: { '7': [entry] } });
|
||||
});
|
||||
|
||||
it('FE-TOUR-WAYPOINT-LIST-009: names the day above the stops and the conflict at the stop it is about', () => {
|
||||
render(<TourWaypointList planner={walkPlanner()} canEdit isSaving={false} />);
|
||||
expect(screen.getByTestId('walk-day')).toHaveTextContent('Day 1, start 17:20');
|
||||
const rows = screen.getAllByTestId('tour-planner-waypoint-row');
|
||||
const first = within(at(rows, 0)).getByTestId('walk-station-schedule');
|
||||
expect(within(first).getByText('Arrival about 17:20, stay until 18:20')).toBeInTheDocument();
|
||||
expect(within(first).getByTestId('walk-station-conflict')).toHaveTextContent(
|
||||
'Lenbachhaus closes at 18:00, during the stay from 17:20 to 18:20 (open 10:00 to 18:00)'
|
||||
);
|
||||
// Beside the row's select button, never inside it.
|
||||
expect(within(at(rows, 0)).getByRole('button', { current: false, name: /Lenbachhaus/ })).not.toContainElement(
|
||||
first
|
||||
);
|
||||
expect(within(at(rows, 1)).queryByTestId('walk-station-schedule')).not.toBeInTheDocument();
|
||||
expect(within(at(rows, 2)).getByTestId('walk-station-schedule')).not.toHaveTextContent('closes');
|
||||
expect(screen.getAllByTestId('walk-station-conflict')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('FE-TOUR-WAYPOINT-LIST-010: shows no arrival while the route is not planned for the points as they are', () => {
|
||||
render(<TourWaypointList planner={walkPlanner({ routeCurrent: false })} canEdit isSaving={false} />);
|
||||
expect(screen.getByTestId('walk-day')).toHaveTextContent('Day 1, start 17:20');
|
||||
expect(screen.queryByTestId('walk-station-schedule')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('walk-station-conflict')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-TOUR-WAYPOINT-LIST-011: gives the way back of a loop no arrival of its own, and a hike no day line', () => {
|
||||
const back = { ...START, id: 'back', role: 'end' as const };
|
||||
const loop = walkPlanner({ isLoop: true, waypoints: [lenbachhaus, STOP, back], route: ROUTE.slice(0, 3) });
|
||||
const { unmount } = render(<TourWaypointList planner={loop} canEdit isSaving={false} />);
|
||||
const rows = screen.getAllByTestId('tour-planner-waypoint-row');
|
||||
expect(within(at(rows, 0)).getByTestId('walk-station-schedule')).toBeInTheDocument();
|
||||
expect(within(at(rows, 1)).getByTestId('walk-station-schedule')).toBeInTheDocument();
|
||||
expect(within(at(rows, 2)).queryByTestId('walk-station-schedule')).not.toBeInTheDocument();
|
||||
unmount();
|
||||
|
||||
render(<TourWaypointList planner={walkPlanner({ tourType: 'hike' })} canEdit isSaving={false} />);
|
||||
expect(screen.queryByTestId('walk-day-line')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('walk-station-schedule')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,6 +37,9 @@ import { usePaddleRegionLoad } from '../paddle/usePaddleRegionLoad';
|
||||
import { usePaddleWaypointActions } from '../paddle/usePaddleWaypointActions';
|
||||
import { usePortageRouting } from '../paddle/usePortageRouting';
|
||||
import { RailCard } from '../tourParts';
|
||||
import { StationScheduleRow } from '../walk/StationSchedule';
|
||||
import { usePlannerWalkSchedule } from '../walk/useWalkSchedule';
|
||||
import { WalkDayLine } from '../walk/WalkDayLine';
|
||||
import { paddlePlanPoints, paddleRolesById } from './paddlePlanOf';
|
||||
import { StationDialog } from './StationDialog';
|
||||
import { StationPills } from './stationParts';
|
||||
@@ -584,6 +587,8 @@ export default function TourWaypointList({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const tripPlaces = useTripPlaceWaypoints(planner, tourPlaceIds);
|
||||
// CW-02, CW-04: the arrivals and opening hours of a city walk on one of its days; hints only, nothing saved.
|
||||
const walk = usePlannerWalkSchedule(planner, tripPlaces.linkedPlaceOf);
|
||||
const [placesOpen, setPlacesOpen] = useState(false);
|
||||
const addRows = canEdit && (
|
||||
<>
|
||||
@@ -654,6 +659,7 @@ export default function TourWaypointList({
|
||||
|
||||
return card(
|
||||
<>
|
||||
<WalkDayLine {...walk} className="mb-2" />
|
||||
<ol data-touch-drag className="m-0 -mx-1.5 flex list-none flex-col gap-px p-0">
|
||||
{planner.waypoints.map((point, index) => {
|
||||
const selected = planner.selectedWaypointId === point.id;
|
||||
@@ -661,6 +667,7 @@ export default function TourWaypointList({
|
||||
const loopEnd = planner.isLoop && index === lastIndex;
|
||||
const linkedPlace = tripPlaces.linkedPlaceOf(point);
|
||||
const placeName = linkedPlace?.name ?? placeNames[point.id];
|
||||
const stop = stopNumbers.get(point.id) ?? index + 1;
|
||||
return (
|
||||
<Fragment key={point.id}>
|
||||
<li
|
||||
@@ -717,7 +724,7 @@ export default function TourWaypointList({
|
||||
<GripVertical size={14} strokeWidth={1.8} />
|
||||
</span>
|
||||
<WaypointNumber
|
||||
stop={stopNumbers.get(point.id) ?? index + 1}
|
||||
stop={stop}
|
||||
selected={selected}
|
||||
ferrata={ferrataEnds[point.id] ?? null}
|
||||
loopEnd={loopEnd}
|
||||
@@ -751,6 +758,7 @@ export default function TourWaypointList({
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<StationScheduleRow schedule={walk.schedule} point={point} placeName={placeName} number={stop} />
|
||||
</li>
|
||||
<WaypointLegRows
|
||||
planner={planner}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useCallback, useMemo } from 'react';
|
||||
import { useTripStore } from '../../../store/tripStore';
|
||||
import type { Category, Place } from '../../../types';
|
||||
import { randomId } from '../../../utils/randomId';
|
||||
import { useLinkedPlaceOf } from '../walk/useWalkSchedule';
|
||||
import { unlinkedPoint, type TourPlannerWaypoint } from './tourPlannerWaypoints';
|
||||
import { withPointAppended } from './tourRouteActions';
|
||||
import type { TourPlannerController } from './useTourPlanner';
|
||||
@@ -49,7 +50,7 @@ export function useTripPlaceWaypoints(planner: TourPlannerController, tourPlaceI
|
||||
const categories = useTripStore((state) => state.categories) ?? NO_CATEGORIES;
|
||||
const { editWaypoints, setSelectedWaypointId, waypoints, route } = planner;
|
||||
|
||||
const placesById = useMemo(() => new Map(places.map((place) => [place.id, place])), [places]);
|
||||
const linkedPlaceOf = useLinkedPlaceOf();
|
||||
|
||||
const candidates = useMemo((): TripPlaceCandidate[] => {
|
||||
const line = tourLine({ route, waypoints });
|
||||
@@ -87,13 +88,6 @@ export function useTripPlaceWaypoints(planner: TourPlannerController, tourPlaceI
|
||||
[editWaypoints]
|
||||
);
|
||||
|
||||
/** The place a point stands for while the trip still has it. */
|
||||
const linkedPlaceOf = useCallback(
|
||||
(point: Pick<TourPlannerWaypoint, 'linkedPlaceId'>) =>
|
||||
point.linkedPlaceId ? (placesById.get(point.linkedPlaceId) ?? null) : null,
|
||||
[placesById]
|
||||
);
|
||||
|
||||
return { candidates, add, unlink, linkedPlaceOf };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user