diff --git a/client/src/utils/dayMerge.test.ts b/client/src/utils/dayMerge.test.ts index 91c81c931..712b4fdab 100644 --- a/client/src/utils/dayMerge.test.ts +++ b/client/src/utils/dayMerge.test.ts @@ -81,19 +81,30 @@ describe('hidesOnMiddleDay', () => { describe('getTransportRouteEndpoints', () => { const pickup = { role: 'from', lat: 48.1, lng: 11.5 } const dropoff = { role: 'to', lat: 52.5, lng: 13.4 } + // An overnight train spanning day 1 (departure) through day 3 (arrival). + const rental = { type: 'train', day_id: 1, end_day_id: 3, endpoints: [pickup, dropoff] } // A car rental spanning day 1 (pickup) through day 3 (drop-off). - const rental = { day_id: 1, end_day_id: 3, endpoints: [pickup, dropoff] } + const car = { ...rental, type: 'car' } - it('routes to the pickup only on the start day of a multi-day rental', () => { + it('routes to the departure only on the start day of a booking spanning days', () => { expect(getTransportRouteEndpoints(rental, 1)).toEqual({ from: { lat: 48.1, lng: 11.5 }, to: null }) }) - it('routes from the drop-off only on the end day', () => { + it('routes from the arrival only on the end day', () => { expect(getTransportRouteEndpoints(rental, 3)).toEqual({ from: null, to: { lat: 52.5, lng: 13.4 } }) }) it('adds no waypoints on the days in between (regression for #1210)', () => { expect(getTransportRouteEndpoints(rental, 2)).toEqual({ from: null, to: null }) + expect(getTransportRouteEndpoints(car, 2)).toEqual({ from: null, to: null }) + }) + + it('passes a rental the traveller drives through its pickup and its return', () => { + // The drive goes to the desk and on from it, and to the return and on from it. + expect(getTransportRouteEndpoints(car, 1)).toEqual({ from: { lat: 48.1, lng: 11.5 }, to: { lat: 48.1, lng: 11.5 } }) + expect(getTransportRouteEndpoints(car, 3)).toEqual({ from: { lat: 52.5, lng: 13.4 }, to: { lat: 52.5, lng: 13.4 } }) + const bike = { ...rental, type: 'bicycle' } + expect(getTransportRouteEndpoints(bike, 3)).toEqual({ from: { lat: 52.5, lng: 13.4 }, to: { lat: 52.5, lng: 13.4 } }) }) it('uses both endpoints for a single-day transport', () => { diff --git a/client/src/utils/dayMerge.ts b/client/src/utils/dayMerge.ts index b45dff17a..77490a9fc 100644 --- a/client/src/utils/dayMerge.ts +++ b/client/src/utils/dayMerge.ts @@ -82,12 +82,23 @@ export function isCarrierTransport(r: { type?: string | null }): boolean { return !!r.type && CARRIER_TRANSPORT_TYPES.has(r.type) } +/** + * Vehicles a traveller drives themselves. Picked up or returned on another day than the + * booking's other end, such a booking is a stop the day's drive passes through: you get to + * the rental desk and drive on from it, and you drive to the return and leave from there. + * Anything else that spans days is ridden, an overnight train or bus, so the day it starts + * only leaves from its departure and the day it ends only arrives at its destination. + */ +const SELF_DRIVEN_TYPES = new Set(['car', 'bicycle']) + /** * The route waypoints a transport contributes on a given day, respecting multi-day spans. - * A car rental (or any reservation whose span covers several days) is only routed to on its - * pickup day (the departure endpoint) and from on its drop-off day (the arrival endpoint) — on - * the days in between you simply hold the vehicle, so it adds no waypoints and must not pull the - * route to those points. Single-day transports contribute both endpoints. + * A reservation whose span covers several days is routed to its departure on its first day + * and from its arrival on its last; a rental the traveller drives (SELF_DRIVEN_TYPES) is + * routed through its pickup and its return instead, so the drive to the rental desk, the one + * away from it and the one to the return all show. On the days in between you simply hold + * the vehicle, so it adds no waypoints and must not pull the route to those points. + * Single-day transports contribute both endpoints. */ export function getTransportRouteEndpoints( r: any, @@ -111,11 +122,12 @@ export function getTransportRouteEndpoints( if (legIdx != null) return point(ordered[role === 'from' ? legIdx : legIdx + 1]) return point((r.endpoints || []).find((x: { role?: string }) => x.role === role)) } + const passedThrough = SELF_DRIVEN_TYPES.has(r.type) switch (getSpanPhase(r, dayId)) { case 'start': - return { from: ep('from'), to: null } + return { from: ep('from'), to: passedThrough ? ep('from') : null } case 'end': - return { from: null, to: ep('to') } + return { from: passedThrough ? ep('to') : null, to: ep('to') } case 'middle': return { from: null, to: null } default: diff --git a/client/tests/unit/mobile/trip/planTimelineModel.test.ts b/client/tests/unit/mobile/trip/planTimelineModel.test.ts index de6a830e7..b3ca973f0 100644 --- a/client/tests/unit/mobile/trip/planTimelineModel.test.ts +++ b/client/tests/unit/mobile/trip/planTimelineModel.test.ts @@ -11,7 +11,7 @@ import type { Accommodation, Assignment, Day, DayNote, Place, Reservation, RouteSegment, TranslationFn, } from '../../../../src/types' -// FE-MOB-PTLM-001 to FE-MOB-PTLM-060 +// FE-MOB-PTLM-001 to FE-MOB-PTLM-063 const DAYS = [ { id: 1, trip_id: 1, day_number: 1, date: '2026-05-01', title: null }, @@ -900,3 +900,59 @@ describe('planTimelineModel — chronology helpers', () => { expect(breaksChronology([...drawn, breakfast], 2, getDisplayTimeForDay)).toBe(true) }) }) + +describe('planTimelineModel: a rental car picked up or returned on the day', () => { + // A car hired on day 1 and returned on day 2 before an evening flight home: the + // traveller drives the car to the return desk, so that drive belongs to the day. + const MIRADOR = { lat: 27.756, lng: -15.571 } + const PICKUP = { lat: 27.95, lng: -15.4 } + const RETURN = { lat: 27.92, lng: -15.38 } + const LPA = { lat: 27.932, lng: -15.387 } + const MUC = { lat: 48.353, lng: 11.786 } + const endpoint = (role: 'from' | 'to', sequence: number, name: string, at: { lat: number; lng: number }) => ({ + role, sequence, name, code: null, ...at, timezone: null, local_date: null, local_time: null, + }) + const car = (dayId: number, endDayId: number) => buildReservation({ + id: 71, type: 'car', title: 'Avis', day_id: dayId, end_day_id: endDayId, + reservation_time: '2026-05-01T10:00', reservation_end_time: '2026-05-02T17:00', + endpoints: [endpoint('from', 0, 'Avis pickup', PICKUP), endpoint('to', 1, 'Avis return', RETURN)], + }) + const flightHome = buildReservation({ + id: 72, type: 'flight', title: 'Home', day_id: 2, end_day_id: 2, + reservation_time: '2026-05-02T20:00', reservation_end_time: '2026-05-02T23:55', + endpoints: [endpoint('from', 0, 'LPA', LPA), endpoint('to', 1, 'MUC', MUC)], + }) + const mirador = buildAssignment({ id: 31, day_id: 2, order_index: 0, place: place(931, 'Mirador de las Dunas', MIRADOR.lat, MIRADOR.lng) }) + + const planOf = (dayId: number, dayAssignments: Assignment[], reservations: Reservation[]) => { + const merged = getMergedItems({ + dayAssignments, + dayNotes: [], + dayTransports: getTransportForDay({ reservations, dayId, dayAssignmentIds: dayAssignments.map(a => a.id), days: DAYS }), + dayId, + }) + const runs = buildDayRouteRuns(dayId, { + days: DAYS, assignments: { [String(dayId)]: dayAssignments }, reservations, accommodations: [], optimizeFromAccommodation: false, + }) + return { runs, rows: buildPlanRows({ merged, reservations, routeSegments: segmentsOf(runs), dayId }) } + } + const at = (p: { lat: number; lng: number }): [number, number] => [p.lat, p.lng] + + it('FE-MOB-PTLM-062: on the return day the drive from the last stop to the return desk shows and is drawn', () => { + const { runs, rows } = planOf(2, [mirador], [car(1, 2), flightHome]) + expect(rows.map(r => r.key)).toEqual(['pl-31', 'conn-pl-31', 'tr-71', 'tr-72']) + expect(connectors(rows).map(s => [s.from, s.to])).toEqual([[at(MIRADOR), at(RETURN)]]) + // The map draws the same drive, ending at the return desk. + expect(runs.map(run => run.map(p => [p.lat, p.lng]))).toEqual([[at(MIRADOR), at(RETURN)]]) + }) + + it('FE-MOB-PTLM-063: on the pickup day the drive away from the rental desk shows under the booking', () => { + const later = buildAssignment({ id: 32, day_id: 2, order_index: 0, place: place(932, 'Dunes', MIRADOR.lat, MIRADOR.lng, '12:00') }) + const pickup = buildReservation({ + ...car(2, 3), reservation_time: '2026-05-02T10:00', reservation_end_time: '2026-05-03T17:00', + }) + const { rows } = planOf(2, [later], [pickup]) + expect(rows.map(r => r.key)).toEqual(['tr-71', 'conn-tr-71', 'pl-32']) + expect(connectors(rows).map(s => [s.from, s.to])).toEqual([[at(PICKUP), at(MIRADOR)]]) + }) +})