feat(roadtrip): a booked night can stand at both ends of its days

The drive learns what a booked night at the edge of a day is, while nothing seats one
yet. One rule in shared, seatNightBookends, picks the stay a day wakes up in and the one
it sleeps in the way Days does, over real nights and in id order, and puts each hotel at
the edge of the day as a stop of its own that belongs to no assignment.

The schedule, the day window, the spill into the next morning, the sums and the connected
days read a night spent at one hotel as a leg going nowhere, never cut or postpone the
drive to tonight's hotel, and pass the hotel over wherever a stop is looked up by its
stored index. That lookup now also puts a place added behind a terminal where it fell.

The rail and the phone chain draw the hotel as a row of its own that opens the booking or
the stay, offers no other ways and takes no via, in every language. Until a trip switches
it on, every plan is the one stored.
This commit is contained in:
Maurice
2026-09-23 14:18:59 +02:00
parent 7fa0434570
commit 514e2e62ee
60 changed files with 2563 additions and 134 deletions
@@ -16,7 +16,7 @@ import type { LegAlternatives } from '../../../../src/components/Roadtrip/useRou
import { openLeg } from '../../../helpers/legAlternatives'
import { RT_ALT_BAR_LIFT } from '../../../../src/mobile/screens/trip/roadtrip/useMRtAlternatives'
// FE-MOB-MAPAREA-001 to FE-MOB-MAPAREA-042
// FE-MOB-MAPAREA-001 to FE-MOB-MAPAREA-043
//
// The stage's pins come out of the trip store rather than the planner's map list, so the
// stage fixtures seed the store and leave `mapPlaces` to stand for what the plan tab shows.
@@ -889,3 +889,35 @@ describe('MMapArea booking routes on the day-scoped plan map (#2456)', () => {
expect(drawnBookingIds()).toEqual([7])
})
})
describe('MMapArea and a booked night at the edge of the stage', () => {
it('FE-MOB-MAPAREA-043: a pin at the hotel opens its stored stop, never the bookend in front of it, else the inspector', () => {
const base = drivePlanner(3)
const [before, loop] = base.roadtripRoutes.days
const hotel = (placeId: number) => ({
...loop.stops[0],
assignmentId: -6_000_000_006,
placeId,
ownerIndex: 0,
stopType: 'hotel',
bookend: { phase: 'morning', accommodationId: 5, reservationId: null, checkingOut: false, checkingIn: false, checkOut: null },
})
const withBookend = (placeId: number) => ({
...base,
roadtripRoutes: { ...base.roadtripRoutes, days: [before, { ...loop, stops: [hotel(placeId), ...loop.stops] }] },
}) as TripPlanner
const shell = stageShell()
const { unmount } = render(<MMapArea planner={withBookend(11)} shell={shell} />)
tapPin(11)
expect(shell.openSheet).toHaveBeenLastCalledWith('rtstop', { dayId: 3, assignmentId: 31 })
unmount()
// A hotel the drive has as its bookend only: the road trip has no stop to open.
const only = withBookend(99)
const other = stageShell()
render(<MMapArea planner={only} shell={other} />)
tapPin(99)
expect(other.openSheet).not.toHaveBeenCalled()
expect(only.handleMarkerClick).toHaveBeenCalledWith(99)
})
})
@@ -1,15 +1,15 @@
import { describe, expect, it, vi } from 'vitest'
import { fireEvent, render, screen } from '../../../helpers/render'
import {
RtAutoRow, RtBookingChips, RtDryRow, RtLegRow, RtRideRow, RtSpillRow, RtStopRow, type RowChrome,
RtAutoRow, RtBookendRow, RtBookingChips, RtDryRow, RtLegRow, RtRideRow, RtSpillRow, RtStopRow, type RowChrome,
} from '../../../../src/mobile/screens/trip/roadtrip/MRoadtripRows'
import type { RoadtripRow, StopRow } from '../../../../src/components/Roadtrip/roadtripRowModel'
import type { BookendReading, RoadtripRow, StopRow } from '../../../../src/components/Roadtrip/roadtripRowModel'
import type { CarrierTerminal, RouteSegment, ScheduleWarning } from '@trek/shared/roadtrip'
import type { Reservation, TranslationFn } from '../../../../src/types'
import type { RefuelSearch } from '../../../../src/components/Roadtrip/useRefuelSearch'
import type { RefuelCandidate } from '../../../../src/components/Roadtrip/refuelSuggestion'
// FE-MOB-RTROW-001 to FE-MOB-RTROW-056
// FE-MOB-RTROW-001 to FE-MOB-RTROW-058
// Same echo strategy as tests/helpers/mobileTrip: assertions stay on keys, not copy.
const t: TranslationFn = (key, params) =>
@@ -801,3 +801,45 @@ describe('RtSpillRow', () => {
expect(screen.queryByText('roadtrip.spill.departs:21:30')).toBeNull()
})
})
describe('RtBookendRow', () => {
const reading = (over: Partial<BookendReading> = {}): BookendReading => ({
phase: 'morning',
variant: 'checkOut',
name: 'Hotel Alpenblick',
until: '10:00',
reservationId: 41,
accommodationId: 5,
placeId: 900,
...over,
})
const row = (over: Partial<StopRow> = {}) =>
stopRow({ number: null, service: true, time: '08:40', stop: { ...stopRow().stop, name: 'Hotel Alpenblick', stopType: 'hotel' }, ...over })
it('FE-MOB-RTROW-057: says which night it is on the bed a stay wears, with no number, and opens on a tap', () => {
const onOpen = vi.fn()
const { container } = render(<RtBookendRow row={row()} bookend={reading()} chrome={chrome} onOpen={onOpen} />)
expect(screen.getByText('roadtrip.bookend.checkOut:Hotel Alpenblick')).toBeInTheDocument()
expect(screen.getByText('roadtrip.stay.until:10:00')).toBeInTheDocument()
expect(screen.getByText('08:40')).toBeInTheDocument()
expect(container.querySelector('.lucide-bed-double')).not.toBeNull()
expect(screen.queryByText('2')).toBeNull()
fireEvent.click(screen.getByRole('button'))
fireEvent.keyDown(screen.getByRole('button'), { key: 'Enter' })
expect(onOpen).toHaveBeenCalledTimes(2)
})
it('FE-MOB-RTROW-058: an evening says nothing under its name but what the drive into it ran over', () => {
const warning: ScheduleWarning = { index: 3, code: 'leg', overMinutes: 30 }
const quiet = render(<RtBookendRow row={row({ time: null })} bookend={reading({ phase: 'evening', variant: 'back', until: null })} chrome={chrome} onOpen={vi.fn()} />)
expect(screen.getByText('roadtrip.bookend.back:Hotel Alpenblick')).toBeInTheDocument()
expect(screen.queryByText(/roadtrip\.stay\.until/)).toBeNull()
expect(screen.queryByText('08:40')).toBeNull()
quiet.unmount()
render(<RtBookendRow row={row({ warning, time: '19:10' })} bookend={reading({ phase: 'evening', variant: 'back', until: null })} chrome={{ ...chrome, is12h: true }} onOpen={vi.fn()} />)
expect(screen.getByText('30 min')).toBeInTheDocument()
expect(screen.getByText('7:10 PM')).toBeInTheDocument()
})
})
@@ -10,7 +10,7 @@ import type { CarrierTerminal, RoadtripDay, RoadtripRoutes, RoadtripStop, RouteS
import type { LegAlternatives } from '../../../../src/components/Roadtrip/useRouteAlternatives'
import { openLeg } from '../../../helpers/legAlternatives'
// FE-MOB-RTTAB-001 to FE-MOB-RTTAB-061
// FE-MOB-RTTAB-001 to FE-MOB-RTTAB-064
//
// The stage bar pictures the place its day ends at. It reads that place out of the trip
// store rather than the planner, the unfiltered list, so the picture tests seed the store.
@@ -937,6 +937,77 @@ describe('MRoadtripTab', () => {
fireEvent.click(within(notice).getByRole('button', { name: 'roadtrip.ride.open' }))
expect(shell.openSheet).toHaveBeenCalledWith('transport', { reservationId: 70 })
})
describe('a booked night at the edge of the stage', () => {
const bookend = (phase: 'morning' | 'evening', ownerIndex: number): RoadtripStop => ({
...real(phase === 'morning' ? -6_000_000_004 : -6_000_000_005, 900, 'Hotel Alpenblick'),
ownerIndex,
lat: 47.2,
lng: 11.4,
stopType: 'hotel',
bookend: { phase, accommodationId: 5, reservationId: 41, checkingOut: phase === 'morning', checkingIn: false, checkOut: phase === 'morning' ? '10:00' : null },
})
/** Out of the hotel on its check-out morning, two places, and into the night's hotel. */
const hotelStage = (first: RoadtripStop[] = []) => stage({
stops: [...first, bookend('morning', 0), real(503, 103, 'Kyoto Station'), { ...real(505, 105, 'Munich'), ownerIndex: 1 }, bookend('evening', 2)],
legs: [...first.map((): RouteSegment => ({ ...seg('', ''), distance: 0, from: [47.2, 11.4], to: [47.2, 11.4] })), seg('12 km', '20 min'), seg('30 km', '35 min'), seg('40 km', '45 min')],
schedule: {
entries: [...first.map(() => entry('08:00')), entry('08:40'), entry('09:00', '09:30'), entry('10:05'), entry('10:50')],
warnings: [],
},
legVias: [[], [], [], []], driveWarnings: [], spills: [], dryPoints: [],
})
const hotelBooking = booking({ id: 41, title: 'Hotel Alpenblick', type: 'hotel', day_id: 1 })
it('FE-MOB-RTTAB-062: the stage leaves from the hotel and comes back to one, with no number and no kind on either', () => {
renderTab(planner({ roadtripRoutes: routes({ days: [hotelStage()] }) }))
expect(screen.getByText('roadtrip.bookend.checkOut:Hotel Alpenblick')).toBeInTheDocument()
expect(screen.getByText('roadtrip.stay.until:10:00')).toBeInTheDocument()
expect(screen.getByText('roadtrip.bookend.back:Hotel Alpenblick')).toBeInTheDocument()
// Only the two places offer to become a stop on the way, and the count says two.
expect(screen.getAllByRole('button', { name: 'roadtrip.stop.makeService' })).toHaveLength(2)
expect(screen.getByText('roadtrip.day.stopCount:2')).toBeInTheDocument()
// The stage starts when the hotel is left and ends when the next one is reached.
const start = screen.getByText('mobileTrip.rtStart').parentElement as HTMLElement
expect(within(start).getByText('08:40')).toBeInTheDocument()
const arrive = screen.getByText('roadtrip.stay.arrive').parentElement as HTMLElement
expect(within(arrive).getByText('10:50')).toBeInTheDocument()
})
it('FE-MOB-RTTAB-063: a tap opens the booking behind the night, or the stay for somebody who may not edit bookings', () => {
const editor = planner({ roadtripRoutes: routes({ days: [hotelStage()] }), reservations: [hotelBooking] })
const first = renderTab(editor)
fireEvent.click(screen.getByText('roadtrip.bookend.back:Hotel Alpenblick'))
expect(editor.setEditingReservation).toHaveBeenCalledWith(hotelBooking)
expect(editor.setShowReservationModal).toHaveBeenCalledWith(true)
expect(first.shell.openSheet).not.toHaveBeenCalled()
first.unmount()
const dayEditor = planner({
roadtripRoutes: routes({ days: [hotelStage()] }),
reservations: [hotelBooking],
can: (action: string) => action !== 'reservation_edit',
})
const { shell } = renderTab(dayEditor)
fireEvent.click(screen.getByText('roadtrip.bookend.checkOut:Hotel Alpenblick'))
expect(shell.openSheet).toHaveBeenCalledWith('accommodation', { dayId: 2, accId: 5 })
expect(dayEditor.setEditingReservation).not.toHaveBeenCalled()
})
it('FE-MOB-RTTAB-064: a reader gets the hotel as a place, and the morning marker there is the hotel row', () => {
const reader = planner({
roadtripRoutes: routes({ days: [hotelStage([{ ...bookend('morning', 0), assignmentId: -2_000_000_003, bookend: undefined, automaticNight: { phase: 'start', fromDayNumber: 1 } } as RoadtripStop])] }),
can: vi.fn(() => false),
})
const { shell } = renderTab(reader)
expect(screen.queryByText('roadtrip.window.resume')).toBeNull()
fireEvent.click(screen.getByText('roadtrip.bookend.checkOut:Hotel Alpenblick'))
expect(reader.handlePlaceClick).toHaveBeenCalledWith(900)
expect(shell.openSheet).not.toHaveBeenCalled()
})
})
})
describe('day swipe', () => {
@@ -10,7 +10,7 @@ import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
import { resetAllStores, seedStore } from '../../../helpers/store'
import { fireEvent, render, screen, waitFor } from '../../../helpers/render'
// FE-MOB-RTSTAY-001 to FE-MOB-RTSTAY-025
// FE-MOB-RTSTAY-001 to FE-MOB-RTSTAY-026
//
// The sheet renders inside the real TranslationProvider, so the copy is asserted
// in English.
@@ -322,3 +322,29 @@ describe('MRtStaySheet', () => {
})
})
})
describe('MRtStaySheet and a booked night at the edge of the stage', () => {
beforeEach(() => {
resetAllStores()
})
it('FE-MOB-RTSTAY-026: the arrival is the stop of the place, not the hotel the day sets out from there', () => {
// The morning's hotel stands on Bremen's place at the head of the card, with a clock of
// its own. Found by the place, it put 07:10 in the preview for a stop reached at 22:30.
const hotel = {
...STAGE.stops[1],
assignmentId: -6_000_000_022,
ownerIndex: 0,
stopType: 'hotel',
bookend: { phase: 'morning', accommodationId: 5, reservationId: null, checkingOut: false, checkingIn: false, checkOut: null },
}
const withHotel = {
...STAGE,
stops: [hotel, ...STAGE.stops],
schedule: { entries: [{ arrival: '07:10', departure: '07:10', anchored: false, dayOffset: 0 }, ...STAGE.schedule.entries], warnings: [] },
} as unknown as RoadtripDay
renderSheet({ roadtripRoutes: { days: [withHotel] } }, { sheet: { id: 'rtstay', payload: { placeId: 202, minutes: 30, name: 'Bremen Marktplatz' } } })
expect(screen.getByText('22:30')).toBeInTheDocument()
expect(screen.queryByText('07:10')).not.toBeInTheDocument()
})
})