mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
fix(mobile): booking routes on the phone map follow the day they run on
A booking switched on with "On map" stayed drawn on every day of the phone's plan map, so a flight from the first day crossed the map of the third, although a day chip frames one day and drops the other days' pins. The plan map now draws such a booking only on the days it runs on, the arrival day of an overnight one included, and the all-days view still shows every booking that is switched on. The switch itself stays trip-wide, and the desktop, collections and the road trip stage draw exactly as before. "On map" in a booking's sheet now reads as on only where the plan map draws the route. From any other day a tap takes the map to the booking's day, switching the route on when it is off, instead of hiding a route that is not drawn there anyway. The phone settings also gain the "Always show booking routes" switch the desktop already had. As on the desktop it sets the default for trips not yet touched on this device, so a trip where a route was switched on or off by hand keeps that choice.
This commit is contained in:
@@ -190,4 +190,31 @@ describe('MSettingsGeneral', () => {
|
||||
|
||||
expect(updateSetting).toHaveBeenCalledWith('start_trip_tab', 'finanzplan');
|
||||
});
|
||||
|
||||
// #2456: the account-wide default behind every trip's booking routes. Desktop has it
|
||||
// under Settings -> Display; a phone had no way to reach it, so a booking route on the
|
||||
// phone map only ever came from switching each booking on by hand.
|
||||
it('FE-MOB-SET-015: the travel card carries the always-show-booking-routes default, off until set', async () => {
|
||||
const user = userEvent.setup();
|
||||
const updateSetting = vi.fn().mockResolvedValue(undefined);
|
||||
seedStore(useSettingsStore, { settings: buildSettings({ language: 'en' }), updateSetting });
|
||||
render(<MSettingsGeneral />);
|
||||
|
||||
const toggle = screen.getByRole('switch', { name: 'Always show booking routes' });
|
||||
expect(toggle).toHaveAttribute('aria-checked', 'false');
|
||||
await user.click(toggle);
|
||||
expect(updateSetting).toHaveBeenCalledWith('map_always_show_routes', true);
|
||||
});
|
||||
|
||||
it('FE-MOB-SET-016: the always-show-booking-routes toggle reflects a stored true and switches it off', async () => {
|
||||
const user = userEvent.setup();
|
||||
const updateSetting = vi.fn().mockResolvedValue(undefined);
|
||||
seedStore(useSettingsStore, { settings: buildSettings({ language: 'en', map_always_show_routes: true }), updateSetting });
|
||||
render(<MSettingsGeneral />);
|
||||
|
||||
const toggle = screen.getByRole('switch', { name: 'Always show booking routes' });
|
||||
expect(toggle).toHaveAttribute('aria-checked', 'true');
|
||||
await user.click(toggle);
|
||||
expect(updateSetting).toHaveBeenCalledWith('map_always_show_routes', false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,12 +9,13 @@ import { MAP_LAYER_SWITCHER_INSET, MAP_ROUND_CONTROL_SIZE } from '../../../../sr
|
||||
import { useSettingsStore } from '../../../../src/store/settingsStore'
|
||||
import { useTripStore } from '../../../../src/store/tripStore'
|
||||
import { seedStore } from '../../../helpers/store'
|
||||
import type { Place } from '../../../../src/types'
|
||||
import type { Day, Place, Reservation } from '../../../../src/types'
|
||||
import { visibleRouteReservations, type RouteVisibilityOptions } from '../../../../src/utils/reservationRoutes'
|
||||
import type { AlternativeOverlay } from '../../../../src/components/Roadtrip/alternativeOverlays'
|
||||
import type { LegAlternatives } from '../../../../src/components/Roadtrip/useRouteAlternatives'
|
||||
import { RT_ALT_BAR_LIFT } from '../../../../src/mobile/screens/trip/roadtrip/useMRtAlternatives'
|
||||
|
||||
// FE-MOB-MAPAREA-001 to FE-MOB-MAPAREA-037
|
||||
// FE-MOB-MAPAREA-001 to FE-MOB-MAPAREA-042
|
||||
//
|
||||
// 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.
|
||||
@@ -791,10 +792,99 @@ describe('MMapArea', () => {
|
||||
const { rerender } = render(<MMapArea planner={planner} shell={shell} />)
|
||||
|
||||
expect(mocks.props.visibleConnectionIds).toEqual([70])
|
||||
// A seamed ride joins the road whatever day it was booked on, so the stage does not
|
||||
// hold bookings to the selected day the way the plan map does.
|
||||
expect(mocks.props.scopeConnectionsToDay).toBe(false)
|
||||
|
||||
// The plan tab keeps the traveller's own toggles, as the desktop does off road trip mode.
|
||||
rerender(<MMapArea planner={planner} shell={{ ...shell, trTab: 'plan' }} />)
|
||||
expect(mocks.props.visibleConnectionIds).toBe(planner.visibleConnections)
|
||||
expect(mocks.props.visibleConnectionIds).toEqual([])
|
||||
expect(mocks.props.scopeConnectionsToDay).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* #2456: the phone map is one day's picture. A day chip frames the day, draws its route
|
||||
* and drops the other days' pins (MTripShell.selectDayOnMap), and the automated
|
||||
* transports ride the day since #2019. A booking switched on through its own toggle
|
||||
* ("On map") stayed on every day's map, though, because the per-booking branch of
|
||||
* visibleRouteReservations is trip-wide.
|
||||
*
|
||||
* The renderer is mocked here, so what it WOULD draw is worked out the way both engines
|
||||
* work it out: MapView and MapViewGL hand their own props to visibleRouteReservations.
|
||||
* The whole prop bag goes in, so a day-scoping option added to the renderers under the
|
||||
* util's own name is picked up as well as a filtered id list is.
|
||||
*/
|
||||
describe('MMapArea booking routes on the day-scoped plan map (#2456)', () => {
|
||||
const DAYS = [
|
||||
{ id: 10, trip_id: 1, day_number: 1, date: '2026-05-01' },
|
||||
{ id: 11, trip_id: 1, day_number: 2, date: '2026-05-02' },
|
||||
{ id: 12, trip_id: 1, day_number: 3, date: '2026-05-03' },
|
||||
] as Day[]
|
||||
|
||||
function flight(over: Partial<Reservation> = {}): Reservation {
|
||||
return {
|
||||
id: 7, trip_id: 1, type: 'flight', title: 'FRA → LIS', status: 'confirmed',
|
||||
day_id: 10, end_day_id: 10,
|
||||
reservation_time: '2026-05-01T09:00', reservation_end_time: '2026-05-01T11:00',
|
||||
endpoints: [
|
||||
{ role: 'from', sequence: 0, name: 'Frankfurt', code: 'FRA', lat: 50.03, lng: 8.57, timezone: null, local_time: null, local_date: null },
|
||||
{ role: 'to', sequence: 1, name: 'Lisbon', code: 'LIS', lat: 38.77, lng: -9.13, timezone: null, local_time: null, local_date: null },
|
||||
],
|
||||
...over,
|
||||
} as unknown as Reservation
|
||||
}
|
||||
|
||||
/** The plan tab's map in front, a booking switched on, and the given day on the chips. */
|
||||
function renderPlanMap(selectedDayId: number | null, booking: Reservation = flight()) {
|
||||
const planner = buildPlanner({
|
||||
days: DAYS,
|
||||
selectedDayId,
|
||||
reservations: [booking],
|
||||
visibleConnections: [booking.id],
|
||||
transitRoutesShown: false,
|
||||
} as unknown as Partial<TripPlanner>)
|
||||
render(<MMapArea planner={planner} shell={buildShell({ view: 'map', mapFront: true, trTab: 'plan' })} />)
|
||||
}
|
||||
|
||||
/** The booking ids either renderer would draw a route for, from the props it was handed. */
|
||||
const drawnBookingIds = () => visibleRouteReservations(
|
||||
(mocks.props.reservations as Reservation[]) ?? [],
|
||||
mocks.props as unknown as RouteVisibilityOptions,
|
||||
).map(r => r.id)
|
||||
|
||||
it('FE-MOB-MAPAREA-038: a booking switched on for day 1 is not drawn on the map of day 3', () => {
|
||||
renderPlanMap(12)
|
||||
|
||||
expect(drawnBookingIds()).toEqual([])
|
||||
})
|
||||
|
||||
it('FE-MOB-MAPAREA-039: the booking stays drawn on the day it runs on', () => {
|
||||
renderPlanMap(10)
|
||||
|
||||
expect(drawnBookingIds()).toEqual([7])
|
||||
})
|
||||
|
||||
it('FE-MOB-MAPAREA-040: an overnight booking is drawn on both of its days and on no other', () => {
|
||||
const overnight = flight({ day_id: 10, end_day_id: 11 })
|
||||
|
||||
renderPlanMap(11, overnight)
|
||||
expect(drawnBookingIds()).toEqual([7])
|
||||
|
||||
renderPlanMap(12, overnight)
|
||||
expect(drawnBookingIds()).toEqual([])
|
||||
})
|
||||
|
||||
it('FE-MOB-MAPAREA-041: the all days view keeps every switched-on booking', () => {
|
||||
renderPlanMap(null)
|
||||
|
||||
expect(drawnBookingIds()).toEqual([7])
|
||||
})
|
||||
|
||||
it('FE-MOB-MAPAREA-042: a booking bound to no day keeps drawing on every day', () => {
|
||||
renderPlanMap(12, flight({ day_id: null, end_day_id: null }))
|
||||
|
||||
expect(drawnBookingIds()).toEqual([7])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
|
||||
import { resetAllStores, seedStore } from '../../../helpers/store'
|
||||
import { fireEvent, render, screen } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-TRSH-001 to FE-MOB-TRSH-024
|
||||
// FE-MOB-TRSH-001 to FE-MOB-TRSH-030
|
||||
|
||||
vi.mock('../../../../src/utils/fileDownload', () => ({ openFile: vi.fn() }))
|
||||
|
||||
@@ -301,4 +301,110 @@ describe('MTransportSheet', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
|
||||
expect(shell.closeSheet).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
/**
|
||||
* #2456: the phone map is one day's picture, so "On map" has to land on a day the
|
||||
* booking runs on. The Transports tab lists the whole trip, and the day the chips hold
|
||||
* can be any other day: switched on from there, the route went to a map that frames,
|
||||
* and (once booking routes follow the day) draws, a different day.
|
||||
*
|
||||
* The booking's day goes in after the view switch: entering the map re-selects the day
|
||||
* the shell still holds (MTripShell.toggleView), so it has to come last to win.
|
||||
*/
|
||||
describe('On map lands on a day the booking runs on (#2456)', () => {
|
||||
const DAYS = [
|
||||
{ id: 3, trip_id: 1, day_number: 1, date: '2026-05-01' },
|
||||
{ id: 4, trip_id: 1, day_number: 2, date: '2026-05-02' },
|
||||
{ id: 5, trip_id: 1, day_number: 3, date: '2026-05-03' },
|
||||
]
|
||||
|
||||
it("FE-MOB-TRSH-025: from another day, switches the map to the booking's own day", () => {
|
||||
const planner = makePlanner({ days: DAYS, selectedDayId: 5 })
|
||||
const shell = makeShell({ trTab: 'transports', view: 'plan' })
|
||||
render(<MTransportSheet planner={planner} shell={shell} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'On map' }))
|
||||
|
||||
expect(planner.toggleConnection).toHaveBeenCalledWith(7)
|
||||
expect(planner.handleSelectDay).toHaveBeenCalledWith(3, false)
|
||||
expect(planner.setExpandedDayIds).toHaveBeenCalledWith(new Set([3]))
|
||||
const viewSwitch = vi.mocked(shell.toggleView).mock.invocationCallOrder[0]
|
||||
const daySwitches = vi.mocked(planner.handleSelectDay).mock.invocationCallOrder
|
||||
expect(daySwitches[daySwitches.length - 1]).toBeGreaterThan(viewSwitch)
|
||||
})
|
||||
|
||||
it("FE-MOB-TRSH-026: with the map already in front, still moves it to the booking's day", () => {
|
||||
const planner = makePlanner({ days: DAYS, selectedDayId: 5 })
|
||||
const shell = makeShell({ trTab: 'transports', view: 'map' })
|
||||
render(<MTransportSheet planner={planner} shell={shell} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'On map' }))
|
||||
|
||||
expect(shell.toggleView).not.toHaveBeenCalled()
|
||||
expect(planner.handleSelectDay).toHaveBeenCalledWith(3, false)
|
||||
expect(planner.setExpandedDayIds).toHaveBeenCalledWith(new Set([3]))
|
||||
})
|
||||
|
||||
it("FE-MOB-TRSH-027: keeps the selected day while it is one of the booking's days", () => {
|
||||
// Overnight: departs on day 3, lands on day 4, which the chips hold.
|
||||
const overnight = { ...FLIGHT, end_day_id: 4 } as unknown as Reservation
|
||||
const planner = makePlanner({ days: DAYS, selectedDayId: 4, reservations: [overnight] })
|
||||
render(<MTransportSheet planner={planner} shell={makeShell({ trTab: 'plan', view: 'plan' })} />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'On map' }))
|
||||
|
||||
expect(planner.toggleConnection).toHaveBeenCalledWith(7)
|
||||
expect(planner.handleSelectDay).not.toHaveBeenCalled()
|
||||
expect(planner.setExpandedDayIds).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FE-MOB-TRSH-028: leaves the all days view and a booking bound to no day alone', () => {
|
||||
const unbound = { ...FLIGHT, day_id: null, end_day_id: null } as unknown as Reservation
|
||||
const allDays = makePlanner({ days: DAYS, selectedDayId: null })
|
||||
const { unmount } = render(<MTransportSheet planner={allDays} shell={makeShell({ trTab: 'transports', view: 'map' })} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'On map' }))
|
||||
expect(allDays.handleSelectDay).not.toHaveBeenCalled()
|
||||
unmount()
|
||||
|
||||
const noDay = makePlanner({ days: DAYS, selectedDayId: 5, reservations: [unbound] })
|
||||
render(<MTransportSheet planner={noDay} shell={makeShell({ trTab: 'transports', view: 'plan' })} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'On map' }))
|
||||
expect(noDay.toggleConnection).toHaveBeenCalledWith(7)
|
||||
expect(noDay.handleSelectDay).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
// A booking already switched on is still left off another day's map, which is also
|
||||
// where "Always show booking routes" leaves every booking. The button follows the map
|
||||
// there, and a tap takes it to the booking rather than switching the route off unseen.
|
||||
it('FE-MOB-TRSH-029: a booking switched on but not drawn on this day reads off and a tap moves to its day', () => {
|
||||
const planner = makePlanner({ days: DAYS, selectedDayId: 5, visibleConnections: [7] })
|
||||
const shell = makeShell({ trTab: 'transports', view: 'plan' })
|
||||
render(<MTransportSheet planner={planner} shell={shell} />)
|
||||
|
||||
const btn = screen.getByRole('button', { name: 'On map' })
|
||||
expect(btn).toHaveAttribute('aria-pressed', 'false')
|
||||
fireEvent.click(btn)
|
||||
|
||||
expect(planner.toggleConnection).not.toHaveBeenCalled()
|
||||
expect(shell.closeSheet).toHaveBeenCalledTimes(1)
|
||||
expect(shell.setTrTab).toHaveBeenCalledWith('plan')
|
||||
expect(planner.handleSelectDay).toHaveBeenCalledWith(3, false)
|
||||
expect(planner.setExpandedDayIds).toHaveBeenCalledWith(new Set([3]))
|
||||
})
|
||||
|
||||
it("FE-MOB-TRSH-030: on one of the booking's days a switched-on route reads on and a tap hides it in place", () => {
|
||||
const overnight = { ...FLIGHT, end_day_id: 4 } as unknown as Reservation
|
||||
const planner = makePlanner({ days: DAYS, selectedDayId: 4, reservations: [overnight], visibleConnections: [7] })
|
||||
const shell = makeShell({ trTab: 'plan', view: 'map' })
|
||||
render(<MTransportSheet planner={planner} shell={shell} />)
|
||||
|
||||
const btn = screen.getByRole('button', { name: 'On map' })
|
||||
expect(btn).toHaveAttribute('aria-pressed', 'true')
|
||||
fireEvent.click(btn)
|
||||
|
||||
expect(planner.toggleConnection).toHaveBeenCalledWith(7)
|
||||
expect(shell.closeSheet).not.toHaveBeenCalled()
|
||||
expect(planner.handleSelectDay).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user