mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
feat(dayplan): offer public transport on any connector leg (#1281 follow-up)
The per-segment travel-mode menu now carries a "Public transit" entry on every editable connector: stop-to-stop legs and the boundary hotel/booking bookends alike. Choosing it opens the existing transit search pre-filled with the leg's origin, destination and the stop's departure time, instead of drawing an OSRM road route. A connector only renders when both endpoints are located, so the option is inherently limited to legs that can actually be searched. A leg's coordinates are resolved back to named, timed points from the trip's places, accommodations and booking endpoints. TransitSearchPanel gains an initialTime prop so the departure time can be seeded.
This commit is contained in:
@@ -183,11 +183,17 @@ beforeEach(() => {
|
||||
// otherwise leak into the ones after them.
|
||||
vi.mocked(calculateRouteWithLegs).mockImplementation(waypoints => Promise.resolve({
|
||||
coordinates: [], distance: 0, duration: 0,
|
||||
legs: Array.from({ length: Math.max(0, (waypoints?.length ?? 0) - 1) }, () => ({
|
||||
mid: [0, 0] as [number, number], from: [0, 0] as [number, number], to: [0, 0] as [number, number],
|
||||
distance: 2000, duration: 600, distanceText: '2 km', durationText: '10 min',
|
||||
drivingText: '10 min', walkingText: '25 min',
|
||||
})),
|
||||
// Each leg carries its endpoint coordinates (mirrors the real RouteCalculator), so
|
||||
// connector-driven features that read seg.from/seg.to see faithful [lat, lng] pairs.
|
||||
legs: Array.from({ length: Math.max(0, (waypoints?.length ?? 0) - 1) }, (_, i) => {
|
||||
const a = waypoints[i], b = waypoints[i + 1]
|
||||
return {
|
||||
mid: [(a.lat + b.lat) / 2, (a.lng + b.lng) / 2] as [number, number],
|
||||
from: [a.lat, a.lng] as [number, number], to: [b.lat, b.lng] as [number, number],
|
||||
distance: 2000, duration: 600, distanceText: '2 km', durationText: '10 min',
|
||||
drivingText: '10 min', walkingText: '25 min',
|
||||
}
|
||||
}),
|
||||
}))
|
||||
vi.mocked(generateGoogleMapsUrl).mockReturnValue('https://maps.google.com/...')
|
||||
sessionStorage.clear()
|
||||
@@ -3427,6 +3433,72 @@ describe('DayPlanSidebar', () => {
|
||||
expect(vi.mocked(assignmentsApi.updateTransport)).toHaveBeenLastCalledWith(1, 11, null)
|
||||
})
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-171b: a stop-to-stop connector offers public transport pre-filled from the leg', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onPlanTransitLeg = vi.fn()
|
||||
const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
|
||||
const assignments = {
|
||||
'10': [
|
||||
buildAssignment({ id: 11, day_id: 10, order_index: 0, place: buildPlace({ id: 1, name: 'Louvre', place_time: '10:30', lat: 48.86, lng: 2.34 }) }),
|
||||
buildAssignment({ id: 12, day_id: 10, order_index: 1, place: buildPlace({ id: 2, name: 'Orsay', lat: 48.87, lng: 2.33 }) }),
|
||||
],
|
||||
}
|
||||
render(<DayPlanSidebar {...makeDefaultProps({ days: [day], assignments, selectedDayId: 10, routeShown: true, onPlanTransitLeg })} />)
|
||||
await user.click(await screen.findByTitle('Change travel mode'))
|
||||
await user.click(contextMenu().getByRole('button', { name: 'Public transit' }))
|
||||
// Origin/destination + this stop's departure time, resolved back from the leg coords.
|
||||
expect(onPlanTransitLeg).toHaveBeenCalledWith({
|
||||
dayId: 10,
|
||||
from: { name: 'Louvre', lat: 48.86, lng: 2.34 },
|
||||
to: { name: 'Orsay', lat: 48.87, lng: 2.33 },
|
||||
time: '10:30',
|
||||
})
|
||||
})
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-171c: the public-transport entry is absent without the onPlanTransitLeg handler', async () => {
|
||||
const user = userEvent.setup()
|
||||
const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
|
||||
const assignments = {
|
||||
'10': [
|
||||
buildAssignment({ id: 11, day_id: 10, order_index: 0, place: buildPlace({ id: 1, name: 'A', lat: 48.85, lng: 2.35 }) }),
|
||||
buildAssignment({ id: 12, day_id: 10, order_index: 1, place: buildPlace({ id: 2, name: 'B', lat: 48.86, lng: 2.36 }) }),
|
||||
],
|
||||
}
|
||||
render(<DayPlanSidebar {...makeDefaultProps({ days: [day], assignments, selectedDayId: 10, routeShown: true })} />)
|
||||
await user.click(await screen.findByTitle('Change travel mode'))
|
||||
expect(contextMenu().queryByRole('button', { name: 'Public transit' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-171d: a hotel bookend connector offers public transport from the hotel', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onPlanTransitLeg = vi.fn()
|
||||
const days = [
|
||||
buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' }),
|
||||
buildDay({ id: 11, date: '2025-06-02', title: 'Day 2' }),
|
||||
buildDay({ id: 12, date: '2025-06-03', title: 'Day 3' }),
|
||||
]
|
||||
const accommodations: Accommodation[] = [{
|
||||
id: 1, trip_id: 1, start_day_id: 10, end_day_id: 12,
|
||||
place_lat: 48.85, place_lng: 2.35, place_name: 'Hotel Lutetia',
|
||||
}]
|
||||
const assignments = {
|
||||
'11': [
|
||||
buildAssignment({ id: 11, day_id: 11, order_index: 0, place: buildPlace({ id: 1, name: 'Louvre', lat: 48.86, lng: 2.34 }) }),
|
||||
buildAssignment({ id: 12, day_id: 11, order_index: 1, place: buildPlace({ id: 2, name: 'Orsay', lat: 48.87, lng: 2.33 }) }),
|
||||
],
|
||||
}
|
||||
render(<DayPlanSidebar {...makeDefaultProps({ days, assignments, accommodations, selectedDayId: 11, routeShown: true, onPlanTransitLeg })} />)
|
||||
// The morning bookend (hotel -> first stop) is the first connector in the list.
|
||||
const connectors = await screen.findAllByTitle('Change travel mode')
|
||||
await user.click(connectors[0])
|
||||
await user.click(contextMenu().getByRole('button', { name: 'Public transit' }))
|
||||
expect(onPlanTransitLeg).toHaveBeenCalledWith(expect.objectContaining({
|
||||
dayId: 11,
|
||||
from: { name: 'Hotel Lutetia', lat: 48.85, lng: 2.35 },
|
||||
to: { name: 'Louvre', lat: 48.86, lng: 2.34 },
|
||||
}))
|
||||
})
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-172: a failing per-segment save is reported and the days are refetched', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { assignmentsApi } = await import('../../api/client')
|
||||
|
||||
Reference in New Issue
Block a user