mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(roadtrip): also take intermediate stops into account
A booking's intermediate stops are now part of the route drawn on the map, and they show up in the day list under their place name. They no longer need the pickup and return times to be filled in. Roadtrips that span several days work properly too. A car picked up on one day and returned on the next showed both days as empty, and only the first half of the drive was drawn.
This commit is contained in:
@@ -102,6 +102,23 @@ describe('TerminalStop', () => {
|
||||
expect(screen.getByText('HAM')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-BOOKINGROWS-001d: a place the booking is driven through reads the place, not the booking', () => {
|
||||
// The booking's name belongs on the desks, where the car changes hands. On a place
|
||||
// the drive only passes through, it says the same thing twice and names no place:
|
||||
// a car taken Hanover → Osnabrück → Bremen read "Weird Roadtrip" where Osnabrück goes.
|
||||
wrap(
|
||||
<TerminalStop
|
||||
stop={stop({ name: 'Osnabrück', carrier: carrier({ type: 'car', role: 'stop', code: null }) })}
|
||||
booking={booking({ id: 7, type: 'car', title: 'Weird Roadtrip' })}
|
||||
entry={entry()}
|
||||
late={[]}
|
||||
continues
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('Osnabrück')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Weird Roadtrip')).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-BOOKINGROWS-001c: a check-in the drive cannot make takes no pill on the card, neither the check-in nor that it is missed', () => {
|
||||
wrap(
|
||||
<TerminalStop
|
||||
|
||||
@@ -41,10 +41,16 @@ export function TerminalStop({ stop, booking, entry, late, continues, starts, on
|
||||
const { t } = useTranslation()
|
||||
const is12h = useSettingsStore(s => s.settings.time_format) === '12h'
|
||||
const { end, desk, checkIn } = terminalReading(stop, entry, late, t, is12h)
|
||||
// Only ever called for a stop a booking put on the day, which is what carries one.
|
||||
const carrier = stop.carrier!
|
||||
// A place the booking is driven through is that place. The booking's own name belongs
|
||||
// on the desks, where the car changes hands and the name is what the traveller asks
|
||||
// for; on the road between them it says the same thing twice and names no place.
|
||||
const title = carrier.role === 'stop' ? end.place : (booking?.title ?? end.place)
|
||||
return (
|
||||
<TransportCard
|
||||
type={booking?.type ?? stop.carrier!.type}
|
||||
title={booking?.title ?? end.place}
|
||||
type={booking?.type ?? carrier.type}
|
||||
title={title}
|
||||
clock={end.clock ? <TimetableClock end={end} /> : entry?.arrival ? <Arrival entry={entry} /> : null}
|
||||
checkIn={checkIn?.state === 'ok' ? checkIn : null}
|
||||
starts={starts}
|
||||
|
||||
@@ -1146,6 +1146,99 @@ describe('a booking the traveller rides (#2428)', () => {
|
||||
expect(result.current.totalStops).toBe(2)
|
||||
expect(result.current.lines).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-ROUTES-069: the drive to the return desk runs over the stops the booking names', async () => {
|
||||
// Reported on a hire car booked with a stop in the middle: the day plan routed over
|
||||
// that stop and the road trip drew the short way round, which is a different
|
||||
// journey from the one booked.
|
||||
calculateRouteWithLegs.mockImplementation(async (points: { lat: number; lng: number }[]) => hourly(points))
|
||||
const viaBerlin = flight({
|
||||
id: 72,
|
||||
type: 'car',
|
||||
title: 'Sixt Hamburg',
|
||||
reservation_time: '09:00',
|
||||
reservation_end_time: '18:00',
|
||||
endpoints: [
|
||||
{ role: 'from', sequence: 0, name: 'Hamburg', code: null, lat: HAMBURG[0], lng: HAMBURG[1], timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'stop', sequence: 1, name: 'Lüneburg', code: null, lat: LUENEBURG[0], lng: LUENEBURG[1], timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'to', sequence: 2, name: 'Berlin', code: null, lat: BERLIN[0], lng: BERLIN[1], timezone: null, local_time: null, local_date: null },
|
||||
],
|
||||
})
|
||||
const { result } = renderHook(() => useRoadtripRoutes(7, [day(1, 1)], map(1, []), 'driving', {}, [], [], [viaBerlin]))
|
||||
await waitFor(() => expect(result.current.loading).toBe(false))
|
||||
|
||||
// Two desks with the place it is driven through standing between them as a stop of
|
||||
// the drive, and the road asked for runs over it.
|
||||
expect(result.current.days[0].stops.map(s => `${s.carrier?.role}:${s.name}`))
|
||||
.toEqual(['pickup:Hamburg', 'stop:Lüneburg', 'return:Berlin'])
|
||||
// Driven through and nothing more: it holds the drive up by no minutes at all.
|
||||
expect(result.current.days[0].stops[1]).toMatchObject({ dwellMinutes: 0, time: null })
|
||||
const asked = calculateRouteWithLegs.mock.calls.map(c => c[0].map((p: { lat: number }) => p.lat))
|
||||
expect(asked).toEqual([[HAMBURG[0], LUENEBURG[0], BERLIN[0]]])
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-ROUTES-070: the destination standing on the day as well keeps the road on the booking', async () => {
|
||||
// The usual shape: the car goes back to a desk at the destination, and the destination
|
||||
// is on the day as a place too (a stay seats it there, a clock here), so the run holds
|
||||
// a stop of the day's own between the two desks. The booking's own stop keeps its
|
||||
// place behind the pick-up, and the drive still passes through it first.
|
||||
calculateRouteWithLegs.mockImplementation(async (points: { lat: number; lng: number }[]) => hourly(points))
|
||||
const viaBerlin = flight({
|
||||
id: 72,
|
||||
type: 'car',
|
||||
title: 'Sixt Hamburg',
|
||||
reservation_time: '09:00',
|
||||
reservation_end_time: '18:00',
|
||||
endpoints: [
|
||||
{ role: 'from', sequence: 0, name: 'Hamburg', code: null, lat: HAMBURG[0], lng: HAMBURG[1], timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'stop', sequence: 1, name: 'Lüneburg', code: null, lat: LUENEBURG[0], lng: LUENEBURG[1], timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'to', sequence: 2, name: 'Berlin', code: null, lat: BERLIN[0], lng: BERLIN[1], timezone: null, local_time: null, local_date: null },
|
||||
],
|
||||
})
|
||||
const berlinOnTheDay = map(1, [{ id: 1, at: BERLIN, time: '17:00' }])
|
||||
const { result } = renderHook(() => useRoadtripRoutes(7, [day(1, 1)], berlinOnTheDay, 'driving', {}, [], [], [viaBerlin]))
|
||||
await waitFor(() => expect(result.current.loading).toBe(false))
|
||||
|
||||
expect(result.current.days[0].stops.map(s => s.carrier?.role ?? 'day')).toEqual(['pickup', 'stop', 'day', 'return'])
|
||||
const asked = calculateRouteWithLegs.mock.calls.map(c => c[0].map((p: { lat: number }) => p.lat))
|
||||
// Hamburg → Lüneburg → the day's Berlin stop → the desk there, not Hamburg → Berlin.
|
||||
expect(asked).toEqual([[HAMBURG[0], LUENEBURG[0], BERLIN[0], BERLIN[0]]])
|
||||
})
|
||||
|
||||
it('FE-ROADTRIP-ROUTES-071: the drive back to the desk is asked for across midnight without one continuous drive', async () => {
|
||||
// A car taken out in the morning and handed back at 02:00 the next day. The road to
|
||||
// the desk is the booking's own, not the gap a day-at-a-time routing leaves between
|
||||
// two cards, so it is asked for with "one continuous drive" off, as it is here.
|
||||
calculateRouteWithLegs.mockImplementation(async (points: { lat: number; lng: number }[]) => hourly(points))
|
||||
const overnight = flight({
|
||||
id: 73,
|
||||
type: 'car',
|
||||
title: 'Sixt Hamburg',
|
||||
day_id: 1,
|
||||
end_day_id: 2,
|
||||
reservation_time: '06:00',
|
||||
reservation_end_time: '02:00',
|
||||
endpoints: [
|
||||
{ role: 'from', sequence: 0, name: 'Hamburg', code: null, lat: HAMBURG[0], lng: HAMBURG[1], timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'stop', sequence: 1, name: 'Lüneburg', code: null, lat: LUENEBURG[0], lng: LUENEBURG[1], timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'to', sequence: 2, name: 'Berlin', code: null, lat: BERLIN[0], lng: BERLIN[1], timezone: null, local_time: null, local_date: null },
|
||||
],
|
||||
})
|
||||
const days = [day(1, 1), day(2, 2)]
|
||||
const { result } = renderHook(() => useRoadtripRoutes(7, days, map(1, []), 'driving', {}, [], [], [overnight]))
|
||||
await waitFor(() => expect(result.current.loading).toBe(false))
|
||||
|
||||
// A desk on each day, and the place it is driven through on the day it set out.
|
||||
expect(result.current.days.map(d => d.stops.map(s => `${s.carrier?.role}:${s.name}`))).toEqual([
|
||||
['pickup:Hamburg', 'stop:Lüneburg'],
|
||||
['return:Berlin'],
|
||||
])
|
||||
await waitFor(() => {
|
||||
const asked = calculateRouteWithLegs.mock.calls.map(c => c[0].map((p: { lat: number }) => p.lat))
|
||||
// The day's own road, then the one leading to the desk it goes back to.
|
||||
expect(asked).toEqual([[HAMBURG[0], LUENEBURG[0]], [LUENEBURG[0], BERLIN[0]]])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -701,6 +701,18 @@ export function useRoadtripRoutes(
|
||||
const to = routingChains[d + 1].stops[0]
|
||||
if (from && to) want(from, to, routingChains[d + 1].dayId)
|
||||
}
|
||||
} else {
|
||||
// The drive back to a hire car's desk is the booking's own road, not the gap
|
||||
// between two cards, so it is drawn whether or not one continuous drive was asked
|
||||
// for. A car taken out in the morning and handed back after midnight had the day
|
||||
// it set out on drawn and nothing from there to the desk, which reads as a drive
|
||||
// that stops halfway.
|
||||
for (let d = 1; d < routingChains.length; d++) {
|
||||
const to = routingChains[d].stops[0]
|
||||
if (to?.carrier?.role !== 'return') continue
|
||||
const from = routingChains[d - 1].stops[routingChains[d - 1].stops.length - 1]
|
||||
if (from) want(from, to, routingChains[d].dayId)
|
||||
}
|
||||
}
|
||||
return { seams: out, seamMisses: misses }
|
||||
}, [chains, plan, quietDays, window, legsByDay, seamLegs, rideLegs, viasByDay, connectDays, legModeOf, avoidKey, distanceUnit])
|
||||
|
||||
@@ -293,7 +293,7 @@ function carrier(role: CarrierTerminal['role'], over: Partial<CarrierTerminal> =
|
||||
role,
|
||||
title: car ? 'Sixt Hamburg' : 'LH 2020',
|
||||
code: role === 'departure' ? 'HAM' : role === 'arrival' ? 'MUC' : null,
|
||||
at: { departure: '13:20', arrival: '14:30', pickup: '09:00', return: '11:30' }[role],
|
||||
at: { departure: '13:20', arrival: '14:30', pickup: '09:00', return: '11:30', stop: null }[role],
|
||||
...over,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user