fix(roadtrip): a late check-out morning says so, a road driven twice takes its via

The check-out row showed the room's last hour and, beside it, the time the
plan leaves the hotel, which can be hours later when a place further on is
pinned. The row now says "Leaves after check-out" when it does, on the
desktop and on the phone.

A click on a road the day drives twice, out of the hotel in the morning and
again between two of its own places, went to the first pass, the drive out
of the hotel, and was refused. The second pass now takes the via, and where
yesterday's drive into the hotel and today's leg share a road, today's leg
does. A road only the hotel's drives use still takes none.

The wiki says both.
This commit is contained in:
Maurice
2026-09-23 16:01:40 +02:00
parent e6e520b78f
commit 05f533dd0d
34 changed files with 307 additions and 41 deletions
@@ -1479,6 +1479,23 @@ describe('RoadtripSidebar with a booked night at the edge of the day', () => {
expect(screen.getByText('11:40')).toBeInTheDocument()
})
it('FE-ROADTRIP-SIDEBAR-074: a check-out morning left after the room is handed back says so, one left in time does not', () => {
const late = loop({
schedule: {
entries: ['12:27', '13:27', '14:27', '15:27'].map(arrival => ({ arrival, departure: arrival, anchored: false, dayOffset: 0 })),
warnings: [],
},
})
const { unmount } = wrap(<RoadtripSidebar routes={routes({ days: [late] })} />)
expect(screen.getByText('until 10:00')).toBeInTheDocument()
expect(screen.getByText('Leaves after check-out')).toBeInTheDocument()
unmount()
wrap(<RoadtripSidebar routes={routes({ days: [loop()] })} />)
expect(screen.getByText('until 10:00')).toBeInTheDocument()
expect(screen.queryByText('Leaves after check-out')).toBeNull()
})
it('FE-ROADTRIP-SIDEBAR-065: the hotel rows are neither dragged nor dropped on, and carry no stay, kind or fill control', () => {
const { container } = wrap(
<RoadtripSidebar routes={routes({ days: [loop()] })} onReorderStop={vi.fn()} onEditStay={vi.fn()} onSetStopKind={vi.fn()} onSetStopFill={vi.fn()} />,
@@ -18,7 +18,7 @@ import { formatDate, formatClockTime } from '../../utils/formatters'
import { formatDurationShort, isServiceStopType, serviceColor, type ScheduleEntry, type ScheduleWarning, refuelsRange } from './roadtripModel'
import { STOP_KIND_BY_KEY } from './stopKinds'
import { arrivingReroutable, bookendReading, destinationCount, isHop, legReroutable, movableWithin, resumeFoldsIntoBookend, type BookendReading } from './roadtripRowModel'
import { BOOKEND_ICON, bookendBooking, bookendMeta, bookendTitle } from './nightBookend'
import { BOOKEND_ICON, bookendBooking, bookendMeta, bookendTitle, leavesAfterCheckOut } from './nightBookend'
import { spurWorthLabelling } from './accessSpur'
import StopKindPicker from './StopKindPicker'
import StopFillPicker from './StopFillPicker'
@@ -876,7 +876,8 @@ function BookendStop({ reading, entry, late, driveFindings, continues, starts, o
const { t } = useTranslation()
const is12h = useSettingsStore(s => s.settings.time_format) === '12h'
const meta = bookendMeta(reading, t, is12h)
const badges = late.length + driveFindings.length > 0
const afterCheckOut = leavesAfterCheckOut(reading, entry)
const badges = afterCheckOut || late.length + driveFindings.length > 0
return (
<DiscRow Icon={BOOKEND_ICON} starts={starts} continues={continues} onOpen={onOpen}>
<span className="flex min-w-0 items-start gap-2 rounded-lg px-1.5 pb-1 pt-0.5 transition-colors group-hover:bg-surface-hover">
@@ -887,6 +888,12 @@ function BookendStop({ reading, entry, late, driveFindings, continues, starts, o
{meta || badges ? (
<span className="flex flex-wrap items-center gap-1">
{meta ? <span className="text-content-muted" style={{ fontSize: FS.meta }}>{meta}</span> : null}
{afterCheckOut ? (
<span className="inline-flex items-center gap-1 font-medium text-warning" style={{ fontSize: FS.meta }}>
<AlertTriangle size={10} aria-hidden="true" />
{t('roadtrip.bookend.afterCheckOut')}
</span>
) : null}
{driveFindings.map(w => <DriveFindingBadge key={w.code} warning={w} />)}
{late.map(w => <LateBadge key={w.code} late={w} />)}
</span>
@@ -1,9 +1,9 @@
import { describe, expect, it } from 'vitest'
import { BedDouble } from 'lucide-react'
import { BOOKEND_ICON, bookendBooking, bookendMeta, bookendTitle, staysAtTheirPlaces } from './nightBookend'
import { BOOKEND_ICON, bookendBooking, bookendMeta, bookendTitle, leavesAfterCheckOut, staysAtTheirPlaces } from './nightBookend'
import type { BookendReading } from './roadtripRowModel'
// FE-BOOKEND-001 to FE-BOOKEND-006
// FE-BOOKEND-001 to FE-BOOKEND-008
const reading = (over: Partial<BookendReading> = {}): BookendReading => ({
phase: 'morning',
@@ -38,6 +38,22 @@ describe('a booked night as the rail and the phone say it', () => {
expect(bookendMeta(reading({ phase: 'evening', variant: 'back' }), t, false)).toBeNull()
})
it('FE-BOOKEND-007: a day that sets out after the room is handed back says so', () => {
const checkOut = reading({ variant: 'checkOut', until: '10:00' })
expect(leavesAfterCheckOut(checkOut, { arrival: '12:27', dayOffset: 0 })).toBe(true)
expect(leavesAfterCheckOut(checkOut, { arrival: '10:01', dayOffset: 0 })).toBe(true)
expect(leavesAfterCheckOut(checkOut, { arrival: '10:00', dayOffset: 0 })).toBe(false)
expect(leavesAfterCheckOut(checkOut, { arrival: '08:30', dayOffset: 0 })).toBe(false)
// Past midnight it is later than any hour of the morning before.
expect(leavesAfterCheckOut(checkOut, { arrival: '01:00', dayOffset: 1 })).toBe(true)
})
it('FE-BOOKEND-008: nothing to say without a check-out hour or a clock to hold it against', () => {
expect(leavesAfterCheckOut(reading(), { arrival: '12:27', dayOffset: 0 })).toBe(false)
expect(leavesAfterCheckOut(reading({ variant: 'checkOut', until: '10:00' }), { arrival: null, dayOffset: 0 })).toBe(false)
expect(leavesAfterCheckOut(reading({ variant: 'checkOut', until: '10:00' }), undefined)).toBe(false)
})
it('FE-BOOKEND-004: a tap opens the booking behind the night for somebody who may edit bookings', () => {
expect(bookendBooking(reading(), true)).toBe(41)
// The editor is the only view a hotel booking has, so anybody else gets the place.
@@ -1,5 +1,6 @@
import { BedDouble, type LucideIcon } from 'lucide-react'
import { formatClockTime } from '../../utils/formatters'
import { parseClock, type ScheduleEntry } from './roadtripModel'
import type { TranslationFn } from '../../types'
import type { BookendReading } from './roadtripRowModel'
@@ -29,6 +30,22 @@ export function bookendMeta(reading: BookendReading, t: TranslationFn, is12h: bo
return reading.until ? t('roadtrip.stay.until', { time: formatClockTime(reading.until, is12h) }) : null
}
/**
* Whether the plan leaves the stay later than the room is handed back. The check-out hour
* never moves the start of the day, so a day that sets out at 12:30 from a room given up
* at 10:00 is a plan worth a second look, and the row says so instead of standing the two
* clocks side by side without a word.
*/
export function leavesAfterCheckOut(
reading: BookendReading,
entry: Pick<ScheduleEntry, 'arrival' | 'dayOffset'> | undefined,
): boolean {
const until = parseClock(reading.until)
const leaves = parseClock(entry?.arrival)
if (until === null || leaves === null) return false
return leaves + (entry?.dayOffset ?? 0) * 24 * 60 > until
}
/** The fields of a trip place the hotel of a stay is read from. */
export interface HotelPlace {
id: number