fix(roadtrip): a booked ferry is driven to, and one without a date says so

A ferry between two stops without a clock was seated by the clock alone, which files a
ride with nothing timed before it at the end of the day. The desktop day list stored that
slot, and the road trip drove overland to the far shore and back to the pier before the
crossing. A ride that leaves and lands on the same day, with both terminals located, now
takes the seat between the clocks that adds the fewest straight-line kilometres. One rule
in shared seats it for the day list, the slot the desktop stores, the phone and PDF lists
and the road trip in the browser and on the server. Slots already stored are left alone.

A flight, train, ferry, cruise or bus on no day made no seam and said nothing, while the
map still drew its arc. The rail and the phone tab now name such a booking with a way to
open it, and calculate_roadtrip lists it under undatedRides.
This commit is contained in:
Maurice
2026-09-23 10:21:00 +02:00
parent e6daed9403
commit ab3a81a9eb
37 changed files with 823 additions and 41 deletions
@@ -2522,6 +2522,55 @@ describe('DayPlanSidebar', () => {
expect(stored!.day_plan_position).toBe(positions[1].day_plan_position)
})
// The crossing from the report behind #2461: Amsterdam and Newcastle on the day, the
// ferry from IJmuiden to the Port of Tyne in the evening. The slot written here is the
// one every other reader takes from then on, the road trip included.
const crossing = (newcastleAt: string | null, withAmsterdam = true) => {
const day = buildDay({ id: 10, date: '2026-10-06', title: 'Day 2' })
const amsterdam = buildPlace({ id: 1, name: 'Amsterdam', lat: 52.3731, lng: 4.8926 })
const newcastle = buildPlace({ id: 2, name: 'Newcastle', lat: 54.9783, lng: -1.6178, place_time: newcastleAt })
const stops = [
buildAssignment({ id: 11, day_id: 10, order_index: 0, place: amsterdam }),
buildAssignment({ id: 12, day_id: 10, order_index: 1, place: newcastle }),
].filter(a => withAmsterdam || a.id !== 11)
const ferry = buildReservation({
id: 69, type: 'ferry', title: 'IJmuiden to Newcastle', day_id: 10,
reservation_time: '2026-10-06T17:30', reservation_end_time: '2026-10-06T23:00',
endpoints: [
{ role: 'from', sequence: 0, name: 'IJmuiden', code: null, lat: 52.4581, lng: 4.5879, timezone: null, local_date: null, local_time: null },
{ role: 'to', sequence: 1, name: 'Port of Tyne', code: null, lat: 54.9925, lng: -1.4522, timezone: null, local_date: null, local_time: null },
],
})
seedStore(useTripStore, { reservations: [ferry] })
render(<DayPlanSidebar {...makeDefaultProps({
days: [day], places: [amsterdam, newcastle], reservations: [ferry], assignments: { '10': stops },
})} />)
}
it('FE-PLANNER-DAYPLAN-218: a ferry between two untimed stops on its two shores is given the slot between them (#2461)', async () => {
const { reservationsApi } = await import('../../api/client')
crossing(null)
await waitFor(() => expect(vi.mocked(reservationsApi.updatePositions)).toHaveBeenCalled())
// By the clock alone it closed the day at 2.5, and the drive went overland first.
expect(vi.mocked(reservationsApi.updatePositions).mock.calls[0][1]).toEqual([{ id: 69, day_plan_position: 0.5 }])
expect(useTripStore.getState().reservations.find(r => r.id === 69)!.day_plan_position).toBe(0.5)
})
it('FE-PLANNER-DAYPLAN-219: a stop timed before the ferry keeps it behind that stop (#2461)', async () => {
const { reservationsApi } = await import('../../api/client')
crossing('10:00')
await waitFor(() => expect(vi.mocked(reservationsApi.updatePositions)).toHaveBeenCalled())
expect(vi.mocked(reservationsApi.updatePositions).mock.calls[0][1]).toEqual([{ id: 69, day_plan_position: 1.5 }])
})
it('FE-PLANNER-DAYPLAN-220: a ferry landing next to the only stop of the day opens it (#2461)', async () => {
const { reservationsApi } = await import('../../api/client')
crossing(null, false)
await waitFor(() => expect(vi.mocked(reservationsApi.updatePositions)).toHaveBeenCalled())
// Ahead of Newcastle, which is stored at order_index 1 here.
expect(vi.mocked(reservationsApi.updatePositions).mock.calls[0][1]).toEqual([{ id: 69, day_plan_position: 0.5 }])
})
it('FE-PLANNER-DAYPLAN-204: a rejected slot write puts the bookings back where the server has them', async () => {
const { reservationsApi } = await import('../../api/client')
vi.mocked(reservationsApi.updatePositions).mockRejectedValueOnce(new Error('offline'))
@@ -35,7 +35,7 @@ import { isDayInAccommodationRange, getAccommodationAnchors, getDayBookendHotels
import {
TRANSPORT_TYPES, parseTimeToMinutes, getSpanPhase, hidesOnMiddleDay, getDisplayTimeForDay, getTransportRouteEndpoints,
getTransportForDay as _getTransportForDay, getMergedItems as _getMergedItems, isCarrierTransport, hasCarrierEndpointOnDay,
getAssignmentReservations, timedSlot,
getAssignmentReservations, timedSlot, rideSeatKey,
type MergedItem,
} from '../../utils/dayMerge'
import { withinDriveRange } from '../../utils/geo'
@@ -439,6 +439,13 @@ function useDayPlanSidebar(props: DayPlanSidebarProps) {
// Compute initial day_plan_position for a transport based on time
const computeTransportPosition = (r, da) => {
// A ride that lands today goes where it adds the least road between the same clocks,
// by the rule the list and the road trip seat it with (`rideSeatKey`). This slot is
// stored, so seated by the clock alone a ferry between two untimed stops stayed at
// the end of the day, and the drive went overland before the crossing (#2461).
const seat = rideSeatKey(r, da.map(a => ({ type: 'place' as const, sortKey: a.order_index, data: a })))
if (seat === -Infinity) return Math.min(...da.map(a => a.order_index)) - 0.5
if (seat !== null) return seat + 0.5
const minutes = parseTimeToMinutes(r.reservation_time) ?? 0
// Find the last place with time <= transport time
let afterIdx = -1
@@ -1397,4 +1397,41 @@ describe('RoadtripSidebar with the drive in from the day before (#2461)', () =>
wrap(<RoadtripSidebar routes={routes({ days: [joined({ arrivingLine: undefined })] })} onAskAlternatives={vi.fn()} />)
expect(screen.getAllByLabelText('Other ways')).toHaveLength(1)
})
describe('a ride on no day (#2461)', () => {
const terminals = [
{ role: 'from', sequence: 0, name: 'IJmuiden', code: null, lat: 52.4581, lng: 4.5879, timezone: null, local_date: null, local_time: null },
{ role: 'to', sequence: 1, name: 'Port of Tyne', code: null, lat: 54.9925, lng: -1.4522, timezone: null, local_date: null, local_time: null },
]
const ferry = (over: Partial<Reservation>): Reservation =>
({ id: 70, trip_id: 1, type: 'ferry', title: 'IJmuiden to Newcastle', status: 'confirmed', day_id: null, endpoints: terminals, ...over }) as unknown as Reservation
it('FE-ROADTRIP-SIDEBAR-062: is named under the totals with its booking a click away; one on a day or without terminals is not', () => {
const onOpenBooking = vi.fn()
const reservations = [
ferry({}),
// On a day it is on the drive already; without terminals nothing says where it runs.
ferry({ id: 71, title: 'Dated ferry', day_id: 1 }),
ferry({ id: 72, title: 'Unlocated ferry', endpoints: [] } as Partial<Reservation>),
ferry({ id: 73, title: 'Table', type: 'restaurant' }),
]
wrap(<RoadtripSidebar routes={routes()} reservations={reservations} onOpenBooking={onOpenBooking} />)
const notice = screen.getByRole('status')
expect(within(notice).getByText('IJmuiden to Newcastle has no date, so the drive does not use it.')).toBeInTheDocument()
expect(within(notice).getAllByRole('listitem')).toHaveLength(1)
fireEvent.click(within(notice).getByRole('button', { name: 'Open booking' }))
expect(onOpenBooking).toHaveBeenCalledWith(70)
})
it('FE-ROADTRIP-SIDEBAR-063: says so without a button where bookings cannot be opened, and says nothing when every ride has a day', () => {
const reader = wrap(<RoadtripSidebar routes={routes()} reservations={[ferry({})]} />)
expect(screen.getByText('IJmuiden to Newcastle has no date, so the drive does not use it.')).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Open booking' })).toBeNull()
reader.unmount()
wrap(<RoadtripSidebar routes={routes()} reservations={[ferry({ day_id: 1 })]} onOpenBooking={vi.fn()} />)
expect(screen.queryByRole('status')).toBeNull()
})
})
})
@@ -23,7 +23,7 @@ import StopKindPicker from './StopKindPicker'
import StopFillPicker from './StopFillPicker'
import { useVehicleRange } from './useVehicleRange'
import { MAX_TRIP_DAYS, type RoadtripStopType } from '@trek/shared'
import { isCarrierMode, type CarrierTerminal } from '@trek/shared/roadtrip'
import { isCarrierMode, undatedRides, type CarrierTerminal } from '@trek/shared/roadtrip'
import type { QuietDay, RoadtripDay, RoadtripRoutes, RoadtripStop } from './useRoadtripRoutes'
import type { SpillMark } from './nightSpill'
import { ARRIVING_DRIVE, openOn, type LegAlternatives, type RailDrive } from './useRouteAlternatives'
@@ -2025,6 +2025,42 @@ function QuietDaySection({ day, onMoveStopToDay, drag }: {
)
}
/**
* The rides the drive leaves out because they are on no day (#2461).
*
* The map draws such a booking's arc between its terminals all the same, so without this
* the ferry looked planned while the rail drove round it by road. One line each, with the
* booking a click away, since the fix is a date in the booking itself.
*/
function UndatedRides({ rides, onOpenBooking }: {
rides: readonly Reservation[]
onOpenBooking?: RoadtripSidebarProps['onOpenBooking']
}): React.ReactElement | null {
const { t } = useTranslation()
if (!rides.length) return null
return (
<div role="status" className="mx-3.5 mt-2 rounded-xl bg-warning-soft p-3 text-caption text-content">
<ul className="flex flex-col gap-1.5">
{rides.map(ride => (
<li key={ride.id} className="flex items-start gap-2">
<AlertTriangle size={13} strokeWidth={2} aria-hidden="true" className="mt-0.5 shrink-0 text-warning" />
<span className="min-w-0 flex-1">{t('roadtrip.ride.undated', { title: ride.title })}</span>
{onOpenBooking ? (
<button
type="button"
onClick={() => onOpenBooking(ride.id)}
className="shrink-0 font-semibold text-content underline underline-offset-2 hover:text-content-secondary"
>
{t('roadtrip.ride.open')}
</button>
) : null}
</li>
))}
</ul>
</div>
)
}
/**
* The road trip rail: the whole trip as one chain of stops with the driving distance
* and time between them.
@@ -2057,6 +2093,7 @@ export default function RoadtripSidebar({
const numbers = new Map([...routes.days, ...routes.quietDays].map(d => [d.dayId, d.dayNumber]))
return (dayId: number): number | null => numbers.get(dayId) ?? null
}, [routes.days, routes.quietDays])
const undated = useMemo(() => undatedRides(reservations ?? []), [reservations])
// Nothing to total up, so nothing pretends to: no "0 km" standing above "No route yet".
if (routes.days.length === 0) {
@@ -2091,6 +2128,7 @@ export default function RoadtripSidebar({
{t(`roadtrip.window.${routes.dayWindowIssue}`, { days: MAX_TRIP_DAYS })}
</p>
) : null}
<UndatedRides rides={undated} onOpenBooking={onOpenBooking} />
</div>
<div className="roadtrip-rail-scroll flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto pb-3.5">
{routes.days.map(day => (