mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
fix(roadtrip): the drive between two days can take another way too
The drive from where one day ended to where the next begins was the one stretch of a connected road trip that offered no other ways. The band above a card's first stop had no button on the desk, and the phone did not show that drive at all. A via behind a day's last stop, where the map already files a point dropped on that drive, was deleted when the day was reordered under Days, and was left on no stop when that last stop was removed or dragged up the day. Switching the avoided road classes or the day's profile kept the old road and minutes on it until a reload. The drive in now opens the same picker as any leg, on the desk band and on a new row at the head of the phone's chain that names where it leaves. A choice is proven with the seam's own router and written behind the last stop of the day before, also when a day with a single stop lies between. The rule for that via lives once in shared (carriedSeam): it stays with the last stop while that stop stays last, and is read like any other once it is not, for the planner's drags and removals as for the server's sorts and seated nights. The cached answer for a seam now records its mode and avoided classes, so changing either asks for it again.
This commit is contained in:
@@ -145,7 +145,7 @@ const DRAWN = ['places', 'route', 'routeColors', 'accessLines', 'focusPoints'] a
|
||||
/** A picker open on leg 0 of day 3, with or without roads back yet. */
|
||||
function withPicker(overlays: AlternativeOverlay[], over: Partial<TripPlanner> = {}): Partial<TripPlanner> {
|
||||
const base = buildPlanner()
|
||||
const open: LegAlternatives = openLeg({ dayId: 3, index: 0, loading: overlays.length === 0 })
|
||||
const open: LegAlternatives = openLeg({ dayId: 3, drive: { kind: 'leg', index: 0 }, loading: overlays.length === 0 })
|
||||
return {
|
||||
routeAlternatives: { ...base.routeAlternatives, open },
|
||||
alternativeOverlays: overlays,
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { Reservation, TranslationFn } from '../../../../src/types'
|
||||
import type { RefuelSearch } from '../../../../src/components/Roadtrip/useRefuelSearch'
|
||||
import type { RefuelCandidate } from '../../../../src/components/Roadtrip/refuelSuggestion'
|
||||
|
||||
// FE-MOB-RTROW-001 to FE-MOB-RTROW-055
|
||||
// FE-MOB-RTROW-001 to FE-MOB-RTROW-056
|
||||
|
||||
// Same echo strategy as tests/helpers/mobileTrip: assertions stay on keys, not copy.
|
||||
const t: TranslationFn = (key, params) =>
|
||||
@@ -492,6 +492,20 @@ describe('RtLegRow', () => {
|
||||
expect(open.className).not.toContain('bg-m-act')
|
||||
})
|
||||
|
||||
it('FE-MOB-RTROW-056: the drive in from the day before names where it leaves, above its pill', () => {
|
||||
// The stop it leaves is on the card before, so the chain would open on a drive from
|
||||
// nowhere without it. Only a leg given an origin says one.
|
||||
const onAlternatives = vi.fn()
|
||||
render(<RtLegRow seg={SEG} mode="driving" origin="Hakone" chrome={chrome} onAlternatives={onAlternatives} />)
|
||||
|
||||
const origin = screen.getByText('roadtrip.leg.arrivingFrom:Hakone')
|
||||
const drive = screen.getByText('roadtrip.leg.driveText:210 km,2 h 40 min')
|
||||
expect(origin.compareDocumentPosition(drive) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
expect(origin.closest('button')).toBeNull()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'roadtrip.alt.ask' }))
|
||||
expect(onAlternatives).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('FE-MOB-RTROW-040: offline the button keeps its place but does nothing', () => {
|
||||
const onAlternatives = vi.fn()
|
||||
render(<RtLegRow seg={SEG} mode="driving" chrome={chrome} onAlternatives={onAlternatives} alternativesDisabled />)
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { CarrierTerminal, RoadtripDay, RoadtripRoutes, RoadtripStop, RouteS
|
||||
import type { LegAlternatives } from '../../../../src/components/Roadtrip/useRouteAlternatives'
|
||||
import { openLeg } from '../../../helpers/legAlternatives'
|
||||
|
||||
// FE-MOB-RTTAB-001 to FE-MOB-RTTAB-057
|
||||
// FE-MOB-RTTAB-001 to FE-MOB-RTTAB-060
|
||||
//
|
||||
// The stage bar pictures the place its day ends at. It reads that place out of the trip
|
||||
// store rather than the planner, the unfiltered list, so the picture tests seed the store.
|
||||
@@ -625,7 +625,7 @@ describe('MRoadtripTab', () => {
|
||||
function withPicker(open: Partial<LegAlternatives>, over: Partial<TripPlanner> = {}): TripPlanner {
|
||||
const base = buildPlanner()
|
||||
return planner({
|
||||
routeAlternatives: { ...base.routeAlternatives, open: openLeg({ dayId: 2, index: 0, loading: true, ...open }) },
|
||||
routeAlternatives: { ...base.routeAlternatives, open: openLeg({ dayId: 2, drive: { kind: 'leg', index: 0 }, loading: true, ...open }) },
|
||||
...over,
|
||||
})
|
||||
}
|
||||
@@ -676,7 +676,7 @@ describe('MRoadtripTab', () => {
|
||||
})
|
||||
|
||||
it('FE-MOB-RTTAB-047: the leg with the picker open shows pressed, and tapping it goes back to the answer without asking again', () => {
|
||||
const p = withPicker({ index: 0 })
|
||||
const p = withPicker({ drive: { kind: 'leg', index: 0 } })
|
||||
const { shell } = renderTab(p)
|
||||
|
||||
const [open, other] = askButtons()
|
||||
@@ -728,11 +728,66 @@ describe('MRoadtripTab', () => {
|
||||
first.unmount()
|
||||
|
||||
// The chain is a look back at the stage, not a way out of the question.
|
||||
const here = withPicker({ dayId: 2, index: 1 })
|
||||
const here = withPicker({ dayId: 2, drive: { kind: 'leg', index: 1 } })
|
||||
renderTab(here)
|
||||
expect(here.routeAlternatives.close).not.toHaveBeenCalled()
|
||||
expect(askButtons()[1]).toHaveAttribute('aria-pressed', 'true')
|
||||
})
|
||||
|
||||
/**
|
||||
* The stage joined to the day before by the road from where that day ended, with no
|
||||
* night drive between them: the drive in is drawn at the head of this card.
|
||||
*/
|
||||
const joinedStage = () => stage({
|
||||
spills: [],
|
||||
arrivingLeg: seg('95 km', '1 h 10 min'),
|
||||
arrivingFrom: {
|
||||
assignmentId: 499, ownerDayId: 1, ownerIndex: 2, placeId: 99, name: 'Hakone',
|
||||
lat: 35.23, lng: 139.02, time: null, dwellMinutes: null,
|
||||
legMode: null, incomingLegMode: null, stopType: null,
|
||||
},
|
||||
arrivingLine: [[35.23, 139.02], [35.36, 138.73]],
|
||||
} as Partial<RoadtripDay>)
|
||||
const joined = (over: Partial<TripPlanner> = {}) => planner({ roadtripRoutes: routes({ days: [joinedStage()] }), ...over })
|
||||
|
||||
it('FE-MOB-RTTAB-058: the drive in from the day before heads the chain, names where it leaves, and asks as the drive it is', () => {
|
||||
// #2461: the phone had no row for this drive at all, so it could neither be read
|
||||
// nor offered another way.
|
||||
const p = joined()
|
||||
renderTab(p)
|
||||
|
||||
const origin = screen.getByText('roadtrip.leg.arrivingFrom:Hakone')
|
||||
expect(screen.getByText('roadtrip.leg.driveText:95 km,1 h 10 min')).toBeInTheDocument()
|
||||
// Above the first stop, where the desk rail draws its band.
|
||||
expect(origin.compareDocumentPosition(screen.getByText('Fuji Viewpoint')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
// A drive, not a stop: the count and the numbering stay as they were.
|
||||
expect(screen.getByText('roadtrip.day.stopCount:2')).toBeInTheDocument()
|
||||
expect(screen.queryByText('3')).toBeNull()
|
||||
|
||||
// The drive in, then the two legs the stage offered before.
|
||||
expect(askButtons()).toHaveLength(3)
|
||||
fireEvent.click(askButtons()[0])
|
||||
expect(p.askRouteAlternatives).toHaveBeenCalledWith(2, { kind: 'arriving' })
|
||||
})
|
||||
|
||||
it('FE-MOB-RTTAB-059: the drive in and the first leg are told apart while a picker is open on either', () => {
|
||||
const onDriveIn = withPicker({ drive: { kind: 'arriving' } }, { roadtripRoutes: routes({ days: [joinedStage()] }) })
|
||||
const first = renderTab(onDriveIn)
|
||||
expect(askButtons().map(b => b.getAttribute('aria-pressed'))).toEqual(['true', 'false', 'false'])
|
||||
// Pressed, it goes back to the answer instead of asking again.
|
||||
fireEvent.click(askButtons()[0])
|
||||
expect(onDriveIn.askRouteAlternatives).not.toHaveBeenCalled()
|
||||
first.unmount()
|
||||
|
||||
renderTab(withPicker({ drive: { kind: 'leg', index: 0 } }, { roadtripRoutes: routes({ days: [joinedStage()] }) }))
|
||||
expect(askButtons().map(b => b.getAttribute('aria-pressed'))).toEqual(['false', 'true', 'false'])
|
||||
})
|
||||
|
||||
it('FE-MOB-RTTAB-060: a reader sees the drive in without the question', () => {
|
||||
renderTab(joined({ can: vi.fn(() => false) }))
|
||||
expect(screen.getByText('roadtrip.leg.arrivingFrom:Hakone')).toBeInTheDocument()
|
||||
expect(askButtons()).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
// The rides and the hire car the routing round seams into the day, and the day's
|
||||
|
||||
@@ -31,7 +31,7 @@ function overlays(routes: OfferedRoute[] = ROUTES) {
|
||||
|
||||
function planner(open: Partial<LegAlternatives> | null, over: Partial<TripPlanner> = {}): TripPlanner {
|
||||
const base = buildPlanner()
|
||||
const leg = open ? openLeg({ dayId: 2, index: 0, routes: ROUTES, ...open }) : null
|
||||
const leg = open ? openLeg({ dayId: 2, drive: { kind: 'leg', index: 0 }, routes: ROUTES, ...open }) : null
|
||||
return buildPlanner({
|
||||
selectedDayId: 2,
|
||||
routeAlternatives: { ...base.routeAlternatives, open: leg },
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { LegAlternatives, OfferedRoute } from '../../../../src/components/R
|
||||
import type { MTripShellApi, TripPlanner } from '../../../../src/mobile/screens/trip/MTripShell'
|
||||
import { openLeg } from '../../../helpers/legAlternatives'
|
||||
|
||||
// FE-MOB-RTALTH-001 to FE-MOB-RTALTH-010
|
||||
// FE-MOB-RTALTH-001 to FE-MOB-RTALTH-011
|
||||
//
|
||||
// The hook holds no picker state, so every case is a planner shape and what the hook
|
||||
// reads out of it or asks of it.
|
||||
@@ -26,7 +26,7 @@ const OVERLAYS = buildAlternativeOverlays(ROUTES, {
|
||||
})
|
||||
|
||||
function leg(over: Partial<LegAlternatives> = {}): LegAlternatives {
|
||||
return openLeg({ dayId: 2, index: 1, routes: ROUTES, ...over })
|
||||
return openLeg({ dayId: 2, drive: { kind: 'leg', index: 1 }, routes: ROUTES, ...over })
|
||||
}
|
||||
|
||||
/** A planner with the picker open on leg 1 of day 2, answered with three roads. */
|
||||
@@ -49,13 +49,13 @@ describe('useMRtAlternatives', () => {
|
||||
it('FE-MOB-RTALTH-001: a leg is open only when both its day and its position match', () => {
|
||||
const { result } = setup()
|
||||
|
||||
expect(result.current.isOpenFor(2, 1)).toBe(true)
|
||||
expect(result.current.isOpenFor(2, { kind: 'leg', index: 1 })).toBe(true)
|
||||
// The same position on another card, and another leg of the same card.
|
||||
expect(result.current.isOpenFor(1, 1)).toBe(false)
|
||||
expect(result.current.isOpenFor(2, 0)).toBe(false)
|
||||
expect(result.current.isOpenFor(1, { kind: 'leg', index: 1 })).toBe(false)
|
||||
expect(result.current.isOpenFor(2, { kind: 'leg', index: 0 })).toBe(false)
|
||||
|
||||
const closed = setup(planner({}, null))
|
||||
expect(closed.result.current.isOpenFor(2, 1)).toBe(false)
|
||||
expect(closed.result.current.isOpenFor(2, { kind: 'leg', index: 1 })).toBe(false)
|
||||
})
|
||||
|
||||
it('FE-MOB-RTALTH-002: reads the phase and the picked road off the planner, and has neither while closed', () => {
|
||||
@@ -98,7 +98,7 @@ describe('useMRtAlternatives', () => {
|
||||
const shell = buildShell({ rtView: 'list' })
|
||||
const { result } = setup(p, shell)
|
||||
|
||||
act(() => { result.current.ask(2, 0) })
|
||||
act(() => { result.current.ask(2, { kind: 'leg', index: 0 }) })
|
||||
|
||||
expect(p.setHighlightedAlternative).toHaveBeenCalledWith(null)
|
||||
expect(p.refuel.close).toHaveBeenCalledTimes(1)
|
||||
@@ -111,7 +111,7 @@ describe('useMRtAlternatives', () => {
|
||||
// Already on the map, the switch would take the traveller back to the chain.
|
||||
const onMap = buildShell({ rtView: 'map' })
|
||||
const second = setup(planner({}, null), onMap)
|
||||
act(() => { second.result.current.ask(2, 0) })
|
||||
act(() => { second.result.current.ask(2, { kind: 'leg', index: 0 }) })
|
||||
expect(second.planner.askRouteAlternatives).toHaveBeenCalledWith(2, { kind: 'leg', index: 0 })
|
||||
expect(onMap.toggleRtView).not.toHaveBeenCalled()
|
||||
})
|
||||
@@ -121,7 +121,7 @@ describe('useMRtAlternatives', () => {
|
||||
const shell = buildShell({ rtView: 'list' })
|
||||
const { result } = setup(p, shell)
|
||||
|
||||
act(() => { result.current.ask(2, 1) })
|
||||
act(() => { result.current.ask(2, { kind: 'leg', index: 1 }) })
|
||||
|
||||
// The planner's ask toggles an open leg shut, and the pick on it is still wanted.
|
||||
expect(p.askRouteAlternatives).not.toHaveBeenCalled()
|
||||
@@ -208,6 +208,19 @@ describe('useMRtAlternatives', () => {
|
||||
expect(p.chooseRouteAlternative).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTALTH-011: the drive in from the day before is a drive of its own, told apart from the first leg', () => {
|
||||
const { result } = setup(planner({}, leg({ drive: { kind: 'arriving' } })))
|
||||
expect(result.current.isOpenFor(2, { kind: 'arriving' })).toBe(true)
|
||||
expect(result.current.isOpenFor(2, { kind: 'leg', index: 0 })).toBe(false)
|
||||
expect(result.current.isOpenFor(1, { kind: 'arriving' })).toBe(false)
|
||||
|
||||
// Open on a leg, asking about the drive in is a new question and goes to the planner.
|
||||
const p = planner({}, leg())
|
||||
const onMap = setup(p, buildShell({ rtView: 'map' }))
|
||||
act(() => { onMap.result.current.ask(2, { kind: 'arriving' }) })
|
||||
expect(p.askRouteAlternatives).toHaveBeenCalledWith(2, { kind: 'arriving' })
|
||||
})
|
||||
|
||||
it('FE-MOB-RTALTH-009: the map lifts its floor by the bar and the gap it keeps from the dock', () => {
|
||||
// The same 15px a bar standing over the dock keeps from it. This is the only such bar
|
||||
// left: the stage bar that used to hold the slot the rest of the time is gone.
|
||||
|
||||
Reference in New Issue
Block a user