feat(roadtrip): edit a stop's place from its phone sheet, title centred on the disc

The stop sheet had no way into the place, so a fixed time could not be set
from the road. A pencil in the header now hands over to the place editor
the plan tab uses, with this visit in context, so Start (the time the chain
anchors on) can be set or cleared there. It shows with place_edit, once the
place row resolves from the whole trip store and the visit carries a server
id. No second writer for the time is added.

Opening the editor on a booked night or a service stop the day lists hide
used to miss the visit, prefill Start from the pool place and write that
over the pin on a plain save, dropping the note too. MPlaceEditSheet now
resolves the visit from the stored assignments.

The header row is centred, so a one line name no longer hangs from the top
of the 34px disc.
This commit is contained in:
Maurice
2026-09-16 22:23:01 +00:00
parent bf03d91345
commit 5b60dda150
6 changed files with 300 additions and 32 deletions
@@ -10,7 +10,7 @@ import { server } from '../../../helpers/msw/server'
import { resetAllStores, seedStore } from '../../../helpers/store'
import { fireEvent, render, screen, waitFor } from '../../../helpers/render'
// FE-MOB-PLEDIT-001 to FE-MOB-PLEDIT-024, plus FE-MOB-PLEDIT-033 to -035
// FE-MOB-PLEDIT-001 to FE-MOB-PLEDIT-040, plus the 009b, 025b and 029b variants
// planner.t echoes the key, so every label/placeholder is asserted as its key.
const CATEGORIES = [
@@ -93,7 +93,9 @@ describe('MPlaceEditSheet', () => {
id: 7, day_id: 2, place_id: 42, order_index: 0,
place: { ...EDITED, place_time: '14:00', end_time: '15:00' },
} as unknown as Assignment
setup({ editingPlace: EDITED, editingAssignmentId: 7, assignments: { '2': [assignment] } })
// A visit the plan tab lists is in both of the planner's lists.
const visits = { '2': [assignment] }
setup({ editingPlace: EDITED, editingAssignmentId: 7, assignments: visits, storedAssignments: visits })
expect(screen.getByText('places.startTime')).toBeInTheDocument()
const times = screen.getAllByDisplayValue(/^1[45]:00$/)
expect(times.map(el => (el as HTMLInputElement).value)).toEqual(['14:00', '15:00'])
@@ -293,7 +295,8 @@ describe('MPlaceEditSheet', () => {
it('FE-MOB-PLEDIT-024: blocks the save while the end time is not after the start', () => {
const assignment = { id: 7, day_id: 2, place_id: 42, order_index: 0, place: EDITED } as unknown as Assignment
setup({ editingPlace: EDITED, editingAssignmentId: 7, assignments: { '2': [assignment] } })
const visits = { '2': [assignment] }
setup({ editingPlace: EDITED, editingAssignmentId: 7, assignments: visits, storedAssignments: visits })
const [start, end] = screen.getAllByDisplayValue(/^0[89]:[0-3]0$/) as HTMLInputElement[]
expect(submit()).not.toBeDisabled()
fireEvent.change(end, { target: { value: '07:00' } })
@@ -466,4 +469,78 @@ describe('MPlaceEditSheet', () => {
expect(onOpenExpense).not.toHaveBeenCalled()
})
})
// ── A visit the day lists hide (the road trip stop sheet opens the editor on them) ──
describe('a visit the day lists hide', () => {
/**
* A booked night: the phone's filtered `assignments` never carries it, the stored
* map does. Its own times differ from the pool place's (08:00 to 09:30), so a
* lookup in the wrong list shows up as the wrong clock.
*/
const NIGHT = {
id: 7, day_id: 2, place_id: 42, order_index: 0, accommodation_id: 9, notes: 'Late check-in',
place: { ...EDITED, place_time: '10:00', end_time: '11:00' },
} as unknown as Assignment
const openOnNight = (overrides: Partial<TripPlanner> = {}) => setup({
editingPlace: EDITED,
editingAssignmentId: 7,
assignments: {},
storedAssignments: { '2': [NIGHT] },
...overrides,
})
it('FE-MOB-PLEDIT-036: reads the times and the day note off the stored visit', () => {
openOnNight()
const times = screen.getAllByDisplayValue(/^1[01]:00$/) as HTMLInputElement[]
expect(times.map(el => el.value)).toEqual(['10:00', '11:00'])
expect(screen.getByPlaceholderText('places.assignmentNotesPlaceholder')).toHaveValue('Late check-in')
})
it('FE-MOB-PLEDIT-037: saving it untouched keeps the pinned time and sends no note', async () => {
const { planner } = openOnNight()
fireEvent.click(submit())
await waitFor(() => expect(planner.handleSavePlace).toHaveBeenCalledTimes(1))
const payload = vi.mocked(planner.handleSavePlace).mock.calls[0][0]
expect(payload).toMatchObject({ place_time: '10:00', end_time: '11:00' })
expect(payload).not.toHaveProperty('assignment_notes')
})
it('FE-MOB-PLEDIT-038: an edited day note on it travels with the save', async () => {
const { planner } = openOnNight()
fireEvent.change(screen.getByPlaceholderText('places.assignmentNotesPlaceholder'), { target: { value: 'Key box at the door' } })
fireEvent.click(submit())
await waitFor(() => expect(planner.handleSavePlace).toHaveBeenCalledTimes(1))
expect(planner.handleSavePlace).toHaveBeenCalledWith(expect.objectContaining({ assignment_notes: 'Key box at the door' }))
})
it('FE-MOB-PLEDIT-039: clearing Start on it sends the empty time that unpins the stop', async () => {
const { planner } = openOnNight()
const [start] = screen.getAllByDisplayValue('10:00')
fireEvent.change(start, { target: { value: '' } })
fireEvent.click(submit())
await waitFor(() => expect(planner.handleSavePlace).toHaveBeenCalledTimes(1))
expect(planner.handleSavePlace).toHaveBeenCalledWith(expect.objectContaining({ place_time: '', end_time: '11:00' }))
})
it('FE-MOB-PLEDIT-040: the overlap warning names what the day lists show, never a hidden stop', () => {
const listed = {
id: 8, day_id: 2, place_id: 50, order_index: 1,
place: { id: 50, name: 'Kaminarimon', place_time: '10:30', end_time: '11:30' },
} as unknown as Assignment
const hiddenPump = {
id: 9, day_id: 2, place_id: 51, order_index: 2,
place: { id: 51, name: 'ENEOS Asakusa', stop_type: 'fuel', place_time: '10:15', end_time: '10:45' },
} as unknown as Assignment
openOnNight({
assignments: { '2': [listed] },
storedAssignments: { '2': [NIGHT, listed, hiddenPump] },
})
// The night itself is hidden too, and still gets warned: the warning reads its day off it.
const warning = screen.getByText(/places\.timeCollision/)
expect(warning).toHaveTextContent('Kaminarimon')
expect(warning).not.toHaveTextContent('ENEOS')
})
})
})
@@ -4,13 +4,17 @@ import type { MTripShellApi, TripPlanner } from '../../../../src/mobile/screens/
import type { Place } from '../../../../src/types'
import type { RoadtripDay, RoadtripStop } from '@trek/shared/roadtrip'
import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
import { resetAllStores } from '../../../helpers/store'
import { useTripStore } from '../../../../src/store/tripStore'
import { resetAllStores, seedStore } from '../../../helpers/store'
import { fireEvent, render, screen, waitFor } from '../../../helpers/render'
// FE-MOB-RTSTOP-001 to FE-MOB-RTSTOP-027
// FE-MOB-RTSTOP-001 to FE-MOB-RTSTOP-034
//
// The sheet renders inside the real TranslationProvider, so the copy is asserted
// in English. `planner.t` from the fixture is never consulted here.
//
// The place rows come from the trip store, not from the planner: the sheet reads the
// unfiltered list, so renderSheet seeds the store and the planner keeps its empty one.
// The charging panel polls a repo of its own every minute; stubbed so the sheet's
// wiring can be asserted without a live availability lookup in the background.
@@ -93,7 +97,6 @@ const PLACES = [
function makePlanner(overrides: Record<string, unknown> = {}) {
return buildPlanner({
tripId: 4,
places: PLACES,
dailyTimesActive: true,
setRoadtripEndDay: vi.fn(async () => undefined),
roadtripRoutes: { days: [DAY_A, DAY_B] },
@@ -108,7 +111,12 @@ function makeShell(overrides: Record<string, unknown> = {}) {
} as unknown as Partial<MTripShellApi>)
}
function renderSheet(plannerOverrides: Record<string, unknown> = {}, shellOverrides: Record<string, unknown> = {}) {
function renderSheet(
plannerOverrides: Record<string, unknown> = {},
shellOverrides: Record<string, unknown> = {},
storePlaces: Place[] = PLACES,
) {
seedStore(useTripStore, { places: storePlaces })
const planner = makePlanner(plannerOverrides)
const shell = makeShell(shellOverrides)
render(<MRtStopSheet planner={planner} shell={shell} />)
@@ -183,7 +191,7 @@ describe('MRtStopSheet', () => {
})
it('FE-MOB-RTSTOP-009: offers the map apps built from the stop itself when no place row matches', () => {
renderSheet({ places: [] })
renderSheet({}, {}, [])
fireEvent.click(screen.getByRole('button', { name: 'Navigation' }))
expect(screen.getByRole('menu')).toBeInTheDocument()
expect(screen.getByRole('menuitem', { name: 'Google Maps' })).toBeInTheDocument()
@@ -192,9 +200,11 @@ describe('MRtStopSheet', () => {
it('FE-MOB-RTSTOP-010: has no delete, no reorder and no stop-kind control at all', () => {
renderSheet()
// Close, navigation, stay, show-on-map, plus the end-day switch, which is a switch.
expect(screen.getAllByRole('button')).toHaveLength(4)
// Close, edit, navigation, stay, show-on-map, plus the end-day switch, which is a switch.
// Edit is a hand-over to the place editor, not a control of this sheet (RTSTOP-030).
expect(screen.getAllByRole('button')).toHaveLength(5)
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Navigation' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: /^Stay/ })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Show on map' })).toBeInTheDocument()
@@ -310,7 +320,7 @@ describe('MRtStopSheet', () => {
it('FE-MOB-RTSTOP-022: one map app means no picker, the tap opens it and names it on the tile', () => {
const open = vi.spyOn(window, 'open').mockReturnValue(null)
// Name only: no coordinates and no address, so only the OSM search link survives.
renderSheet({ places: [{ id: 203, name: 'Bremen Marktplatz', lat: null, lng: null, address: null }] })
renderSheet({}, {}, [{ id: 203, name: 'Bremen Marktplatz', lat: null, lng: null, address: null }] as unknown as Place[])
const tile = screen.getByRole('button', { name: /^Navigation/ })
expect(tile).toHaveTextContent('OpenStreetMap')
fireEvent.click(tile)
@@ -324,7 +334,7 @@ describe('MRtStopSheet', () => {
})
it('FE-MOB-RTSTOP-023: no reachable map app at all drops the tile instead of leaving a dead one', () => {
renderSheet({ places: [{ id: 203, name: '', lat: null, lng: null, address: null }] })
renderSheet({}, {}, [{ id: 203, name: '', lat: null, lng: null, address: null }] as unknown as Place[])
expect(screen.queryByRole('button', { name: /Navigation/ })).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: /^Stay/ })).toBeInTheDocument()
})
@@ -358,4 +368,90 @@ describe('MRtStopSheet', () => {
renderSheet({}, { sheet: { id: 'rtstop', payload: { dayId: 11, assignmentId: 102 } } })
expect(screen.queryByTestId('charging-info')).not.toBeInTheDocument()
})
// jsdom has no layout, so the two header tests pin the class contract rather than pixels.
it('FE-MOB-RTSTOP-028: the header centres the name on the disc instead of hanging it from the top', () => {
renderSheet()
const heading = screen.getByRole('heading', { name: 'Bremen Marktplatz' })
const header = heading.parentElement
expect(header).toHaveClass('items-center')
expect(header).not.toHaveClass('items-start')
// Disc, name and buttons are one row, so they share that one cross-axis alignment.
expect(heading.previousElementSibling).toHaveTextContent('2')
const buttons = heading.nextElementSibling
expect(buttons).toHaveClass('items-center')
expect(buttons).toContainElement(screen.getByRole('button', { name: 'Close' }))
expect(buttons).toContainElement(screen.getByRole('button', { name: 'Edit' }))
})
it('FE-MOB-RTSTOP-029: a service stop with a long name centres the same way and wraps rather than truncating', () => {
const longName = 'Aral Tankstelle an der Autobahnausfahrt Hamburg Dammtor Nord'
renderSheet(
{ roadtripRoutes: { days: [{ ...DAY_A, stops: [HAMBURG, { ...ARAL, name: longName }, BREMEN] }, DAY_B] } },
{ sheet: { id: 'rtstop', payload: { dayId: 11, assignmentId: 102 } } },
)
const heading = screen.getByRole('heading', { name: longName })
expect(heading.parentElement).toHaveClass('items-center')
expect(heading).toHaveClass('line-clamp-2')
expect(heading).not.toHaveClass('truncate')
expect(heading.previousElementSibling?.querySelector('svg')).not.toBeNull()
})
it('FE-MOB-RTSTOP-030: the pencil opens the place editor on this very visit and closes the sheet', () => {
const { planner, shell } = renderSheet()
const edit = screen.getByRole('button', { name: 'Edit' })
// Before the way out, so the close button keeps the corner it has on every sheet.
expect(edit.compareDocumentPosition(screen.getByRole('button', { name: 'Close' })) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
fireEvent.click(edit)
expect(planner.openPlaceEditor).toHaveBeenCalledTimes(1)
expect(planner.openPlaceEditor).toHaveBeenCalledWith(expect.objectContaining({ id: 203, address: 'Am Markt' }), 103)
expect(shell.closeSheet).toHaveBeenCalledTimes(1)
// The stop sheet does not hand over to a stay or a map on the way.
expect(shell.openSheet).not.toHaveBeenCalled()
})
it('FE-MOB-RTSTOP-031: somebody who may not edit places gets no pencil at all', () => {
// Every right but place_edit, so it is that one right the pencil answers to.
const { planner } = renderSheet({ can: vi.fn((action: string) => action !== 'place_edit') })
// Absent rather than disabled, the same rule as every other write on this sheet.
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument()
// The night switch answers to day_edit and stays, so no other right took the pencil away.
expect(screen.getByRole('switch', { name: 'End the day here' })).toBeInTheDocument()
expect(planner.can).toHaveBeenCalledWith('place_edit', planner.trip)
})
it('FE-MOB-RTSTOP-032: a pump hidden from the day lists is still editable from the stage', () => {
// The planner's filtered list lacks the pump, the store still holds it.
const pump = { id: 202, name: 'Aral Dammtor', lat: 53.56, lng: 9.99, stop_type: 'fuel' } as unknown as Place
const { planner } = renderSheet(
{ places: PLACES },
{ sheet: { id: 'rtstop', payload: { dayId: 11, assignmentId: 102 } } },
[...PLACES, pump],
)
fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
expect(planner.openPlaceEditor).toHaveBeenCalledWith(expect.objectContaining({ id: 202 }), 102)
})
it('FE-MOB-RTSTOP-033: a stop still being saved under its optimistic id offers no pencil yet', () => {
const saving = stop({ assignmentId: -5, placeId: 203, name: 'Bremen Marktplatz', ownerIndex: 0, dwellMinutes: 90 })
const day = {
...DAY_A,
stops: [saving],
schedule: { entries: [{ arrival: '13:05', departure: '14:35', anchored: false, dayOffset: 0 }], warnings: [] },
driveWarnings: [],
} as unknown as RoadtripDay
const { planner } = renderSheet({ roadtripRoutes: { days: [day] } }, { sheet: { id: 'rtstop', payload: { dayId: 11, assignmentId: -5 } } })
expect(screen.getByRole('dialog', { name: 'Bremen Marktplatz' })).toBeInTheDocument()
// Neither the temporary id nor a null the planner would resolve back to that same row.
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument()
expect(planner.openPlaceEditor).not.toHaveBeenCalled()
})
it('FE-MOB-RTSTOP-034: a stop whose place row is not in the trip store offers no pencil', () => {
// The editor needs the whole row; the stop's name and position are enough for directions only.
renderSheet({}, {}, [])
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Navigation' })).toBeInTheDocument()
})
})