mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(planner): switching an edited flight or train to car no longer brings back stops from an earlier booking
The transport form stays mounted between openings. Editing a flight or a
train after a car kept the car's stops (desktop and phone) and, on the
desktop, the from and to picks of that earlier booking as well. Switching
the type to car in the same dialog showed those stale stops and places,
and saving wrote them onto the booking. The desktop also kept stale
flight and train rows when opening a car, bus or other booking.
seedTransportRoute only reset the rows a type does not show when the
phone asked for it (resetHiddenRoutes), and never reset the car stops for
a flight or a train. It now returns every row for every type, so a seed
always replaces the whole route. The option is removed; both views get
the same clean route.
Red test: FE-PLANNER-TRANSPORTFORM-008 in
client/src/components/Planner/useTransportForm.test.ts failed with
"expected [ { location: { ... }, time: '' } ] to deeply equal []".
Changed assertions (they asserted the stale rows were kept):
- useTransportForm.test.ts FE-PLANNER-TRANSPORTFORM-005: desktop
fromPick toBe(picked) is now toEqual({}) (title updated), and the
resetHiddenRoutes field is dropped from seedOptions and the phone call.
- transportEndpoints.test.ts FE-PLANNER-TRANSPORTEP-005: desktop route
keys toEqual(['waypoints']) is now empty fromPick, toPick, carStops and
trainWaypoints.
- transportEndpoints.test.ts FE-PLANNER-TRANSPORTEP-010: desktop car
waypoints toBeUndefined() is now two empty rows (plus empty train rows),
and the bus route now also carries the two empty row sets.
- transportEndpoints.test.ts: resetHiddenRoutes dropped from DESKTOP and
PHONE.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-PLANNER-TRANSPORTFORM-001 to -007: the transport form state behind the
|
||||
// FE-PLANNER-TRANSPORTFORM-001 to -008: the transport form state behind the
|
||||
// desktop TransportModal and the phone's transport sheet.
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
@@ -30,7 +30,6 @@ const seedOptions = {
|
||||
fallbackType: 'transport_other' as const,
|
||||
dayId: '' as string | number,
|
||||
stopDaysFromEndpoints: false,
|
||||
resetHiddenRoutes: false,
|
||||
};
|
||||
|
||||
describe('useTransportForm', () => {
|
||||
@@ -105,19 +104,19 @@ describe('useTransportForm', () => {
|
||||
expect(result.current.form).not.toHaveProperty('url');
|
||||
});
|
||||
|
||||
it('FE-PLANNER-TRANSPORTFORM-005: the desktop keeps the rows a flight does not show, the phone clears them', () => {
|
||||
it('FE-PLANNER-TRANSPORTFORM-005: seeding a flight clears the rows a flight does not show, desktop and phone alike', () => {
|
||||
const flight = buildReservation({ type: 'flight', endpoints: [ep('from', 0, 'MUC'), ep('to', 1, 'BER')] });
|
||||
const picked = { location: { name: 'kept', lat: 0, lng: 0 } };
|
||||
|
||||
const desktop = renderHook(() => useTransportForm(EMPTY_TRANSPORT_FIELDS)).result;
|
||||
act(() => desktop.current.setFromPick(picked));
|
||||
act(() => desktop.current.seed(flight, days, seedOptions));
|
||||
expect(desktop.current.fromPick).toBe(picked);
|
||||
expect(desktop.current.fromPick).toEqual({});
|
||||
expect(desktop.current.waypoints.map((w) => w.airport?.iata)).toEqual(['MUC', 'BER']);
|
||||
|
||||
const phone = renderHook(() => useTransportForm(EMPTY_TRANSPORT_FIELDS)).result;
|
||||
act(() => phone.current.setFromPick(picked));
|
||||
act(() => phone.current.seed(flight, days, { ...seedOptions, resetHiddenRoutes: true }));
|
||||
act(() => phone.current.seed(flight, days, { ...seedOptions, stopDaysFromEndpoints: true }));
|
||||
expect(phone.current.fromPick).toEqual({});
|
||||
});
|
||||
|
||||
@@ -156,4 +155,30 @@ describe('useTransportForm', () => {
|
||||
expect.objectContaining({ role: 'to', name: 'B', sequence: 1, local_date: '2026-05-01' }),
|
||||
]);
|
||||
});
|
||||
|
||||
it('FE-PLANNER-TRANSPORTFORM-008: editing a flight or train after a car drops the car route, so switching back to car saves no stale stops', () => {
|
||||
const car = buildReservation({ type: 'car', endpoints: [ep('from', 0), ep('stop', 1), ep('to', 2)] });
|
||||
const flight = buildReservation({ type: 'flight', endpoints: [ep('from', 0, 'MUC'), ep('to', 1, 'BER')] });
|
||||
const train = buildReservation({ type: 'train', endpoints: [ep('from', 0), ep('to', 1)] });
|
||||
|
||||
for (const next of [flight, train]) {
|
||||
const { result } = renderHook(() => useTransportForm(EMPTY_TRANSPORT_FIELDS));
|
||||
act(() => result.current.seed(car, days, seedOptions));
|
||||
expect(result.current.carStops).toHaveLength(1);
|
||||
|
||||
act(() => result.current.seed(next, days, seedOptions));
|
||||
expect(result.current.carStops).toEqual([]);
|
||||
expect(result.current.fromPick).toEqual({});
|
||||
expect(result.current.toPick).toEqual({});
|
||||
|
||||
act(() => result.current.set('type', 'car'));
|
||||
const payload = result.current.payload(days, {
|
||||
reservation: next,
|
||||
prefill: null,
|
||||
budgetEnabled: false,
|
||||
anchorOnStations: false,
|
||||
});
|
||||
expect(payload.endpoints).toEqual([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user