mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
feat(roadtrip): leave a stop at its End and show the stay that makes
A visit's End could be edited and was shown in road trip mode, but the schedule never read it: the drive always left a stop after its stay, so a traveller who knew when they had to leave but not how long they would stand there had no way to say so. The End is now the time the drive leaves. RoadtripStop.leaveAt is filled from the visit's End (or its place's) on the client by useRoadtripRoutes and on the server by roadtrip-plan.service, so calculate_roadtrip and get_roadtrip_context agree with the planner, and computeSchedule takes it as the departure it already knew how to hold. With Start and End both set the stay is the time between them. With daily travel times on, the stay is the time until then, and an End before the window start starts the day early the way a Start does. Before the first fixed time the chain works backwards through an End as it does through a pinned Start. An End is read against the drive: the last passing of that clock time counts as missed when the drive went past it on the road or earlier the same day, anything else is the next one, so a drive across midnight neither waits a whole day nor pretends to be on time. A drive that gets there after the End leaves on arrival and files a missedLeave finding, shown beside the late badge in the rail and on the phone. The rail's STAY badge, the inspector's Stay tile, the phone stop sheet and the phone chain show the stay the End makes, with an "until 14:00" hint. It is read off the schedule and never written to duration_minutes: the stay belongs to the place, the End to one visit, and a stored copy would go stale as soon as the arrival moved. For such a stop the stay dialog, desktop and phone, shows that stay read only and offers to remove the End, through the visit's time route with an offline path (assignmentRepo.setTimes, setAssignmentTimes). While the road trip is on, the End field in both place forms says the drive leaves at that time. The dead checkoutAt in the plan service is gone. New strings in all 23 locales.
This commit is contained in:
@@ -2,12 +2,15 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import MRtStaySheet from '../../../../src/mobile/screens/trip/roadtrip/MRtStaySheet'
|
||||
import type { MTripShellApi, TripPlanner } from '../../../../src/mobile/screens/trip/MTripShell'
|
||||
import { useSettingsStore } from '../../../../src/store/settingsStore'
|
||||
import { useAuthStore } from '../../../../src/store/authStore'
|
||||
import { usePermissionsStore } from '../../../../src/store/permissionsStore'
|
||||
import { useTripStore } from '../../../../src/store/tripStore'
|
||||
import type { RoadtripDay } from '@trek/shared/roadtrip'
|
||||
import { buildPlanner, buildShell } from '../../../helpers/mobileTrip'
|
||||
import { resetAllStores, seedStore } from '../../../helpers/store'
|
||||
import { fireEvent, render, screen, waitFor } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-RTSTAY-001 to FE-MOB-RTSTAY-018
|
||||
// FE-MOB-RTSTAY-001 to FE-MOB-RTSTAY-025
|
||||
//
|
||||
// The sheet renders inside the real TranslationProvider, so the copy is asserted
|
||||
// in English.
|
||||
@@ -229,4 +232,93 @@ describe('MRtStaySheet', () => {
|
||||
expect(screen.getByRole('dialog', { name: 'Add a stay' })).toBeInTheDocument()
|
||||
expect(screen.queryByText('Arrive')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
describe('a stop left at a set time', () => {
|
||||
// Bremen's End is 23:45, so the stay is whatever the arrival at 22:30 leaves of it,
|
||||
// and there is nothing for the buttons to set.
|
||||
const LEAVING = {
|
||||
...STAGE,
|
||||
stops: [STAGE.stops[0], { ...STAGE.stops[1], leaveAt: '23:45' }],
|
||||
schedule: {
|
||||
entries: [STAGE.schedule.entries[0], { arrival: '22:30', departure: '23:45', anchored: false, dayOffset: 0 }],
|
||||
warnings: [],
|
||||
},
|
||||
} as unknown as RoadtripDay
|
||||
let setAssignmentTimes: ReturnType<typeof vi.fn>
|
||||
|
||||
beforeEach(() => {
|
||||
setAssignmentTimes = vi.fn(async () => undefined)
|
||||
seedStore(useAuthStore, { user: { id: 1, role: 'user' } })
|
||||
seedStore(useTripStore, {
|
||||
trip: { id: 4, user_id: 1 },
|
||||
assignments: { '11': [{ id: 102, day_id: 11, place_id: 202, order_index: 1, assignment_time: '22:00', assignment_end_time: '23:45' }] },
|
||||
})
|
||||
useTripStore.setState({ setAssignmentTimes, refreshDays: vi.fn(async () => undefined) } as never)
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-020: says when the drive leaves and what stay that makes, with nothing to set', () => {
|
||||
renderSheet({ roadtripRoutes: { days: [LEAVING] } })
|
||||
// Named for what it holds, as the desktop dialog is: there is no stay to add here.
|
||||
expect(screen.getByRole('dialog', { name: 'Time at this stop' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Time at this stop')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Add a stay')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('1 h 15 min')).toBeInTheDocument()
|
||||
expect(screen.getByText('This visit has an end time, so the drive leaves at 23:45.')).toBeInTheDocument()
|
||||
expect(screen.getByText('22:30')).toBeInTheDocument()
|
||||
expect(screen.getByText('23:45')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: '5 minutes more' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Save' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-021: taking the end time off keeps the Start and writes through the visit', async () => {
|
||||
const { planner } = renderSheet({ roadtripRoutes: { days: [LEAVING] } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Remove end time' }))
|
||||
await waitFor(() => expect(setAssignmentTimes).toHaveBeenCalledWith(4, 11, 102, { place_time: '22:00', end_time: null }))
|
||||
// The ordinary sheet is back, on the stay the place carries.
|
||||
await waitFor(() => expect(value()).toHaveTextContent('30'))
|
||||
expect(planner.setRoadtripStay).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-022: a traveller who may not change the day is not offered the removal', () => {
|
||||
usePermissionsStore.setState({ permissions: { day_edit: 'trip_owner' } })
|
||||
seedStore(useTripStore, { trip: { id: 4, user_id: 2 } })
|
||||
renderSheet({ roadtripRoutes: { days: [LEAVING] } })
|
||||
expect(screen.getByText('1 h 15 min')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Remove end time' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-024: reached after the time, it says so instead of promising it', () => {
|
||||
const late = {
|
||||
...LEAVING,
|
||||
schedule: {
|
||||
entries: [STAGE.schedule.entries[0], { arrival: '23:55', departure: '23:55', anchored: false, dayOffset: 0 }],
|
||||
warnings: [{ index: 1, code: 'missedLeave', minutes: 10 }],
|
||||
},
|
||||
} as unknown as RoadtripDay
|
||||
renderSheet({ roadtripRoutes: { days: [late] } })
|
||||
expect(screen.getByText('Arrives 10 min after the time you set to leave')).toBeInTheDocument()
|
||||
expect(screen.queryByText('This visit has an end time, so the drive leaves at 23:45.')).not.toBeInTheDocument()
|
||||
expect(screen.getAllByText('23:55')).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-025: travel hours over before the time say so, with no departure beside it', () => {
|
||||
const closed = {
|
||||
...LEAVING,
|
||||
schedule: {
|
||||
entries: [STAGE.schedule.entries[0], { arrival: '17:30', departure: '18:00', anchored: false, dayOffset: 0 }],
|
||||
warnings: [],
|
||||
},
|
||||
} as unknown as RoadtripDay
|
||||
renderSheet({ roadtripRoutes: { days: [closed] } })
|
||||
expect(screen.getByText('The travel day ends before 23:45, so the drive goes on the next morning.')).toBeInTheDocument()
|
||||
expect(screen.queryByText('18:00')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTAY-023: the close in the header writes nothing', () => {
|
||||
const { shell } = renderSheet({ roadtripRoutes: { days: [LEAVING] } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
|
||||
expect(shell.closeSheet).toHaveBeenCalledTimes(1)
|
||||
expect(setAssignmentTimes).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ 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-035
|
||||
// FE-MOB-RTSTOP-001 to FE-MOB-RTSTOP-038
|
||||
//
|
||||
// The sheet renders inside the real TranslationProvider, so the copy is asserted
|
||||
// in English. `planner.t` from the fixture is never consulted here.
|
||||
@@ -511,4 +511,50 @@ describe('MRtStopSheet', () => {
|
||||
expect(shell.closeSheet).toHaveBeenCalledTimes(1)
|
||||
expect(planner.setSelectedPlaceId).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
describe('a stop left at a set time', () => {
|
||||
// Lueneburg carries a stay of 30 min, but its End is two in the afternoon: the drive
|
||||
// gets there at ten and keeps to the End.
|
||||
const LUENEBURG = stop({ assignmentId: 105, placeId: 205, name: 'Lueneburg', dwellMinutes: 30, leaveAt: '14:00' })
|
||||
const leaving = (arrival: string, departure: string, warnings: unknown[] = []) => ({
|
||||
...DAY_A,
|
||||
stops: [HAMBURG, LUENEBURG],
|
||||
schedule: {
|
||||
entries: [
|
||||
{ arrival: '09:00', departure: '09:00', anchored: true, dayOffset: 0 },
|
||||
{ arrival, departure, anchored: false, dayOffset: 0 },
|
||||
],
|
||||
warnings,
|
||||
},
|
||||
driveWarnings: [],
|
||||
}) as unknown as RoadtripDay
|
||||
const open = (day: RoadtripDay) =>
|
||||
renderSheet({ roadtripRoutes: { days: [day] } }, { sheet: { id: 'rtstop', payload: { dayId: 11, assignmentId: 105 } } })
|
||||
|
||||
it('FE-MOB-RTSTOP-036: reads the stay the End makes, and until when, on the finding and the tile', () => {
|
||||
open(leaving('10:00', '14:00'))
|
||||
expect(screen.getAllByText('4 h until 14:00')).toHaveLength(2)
|
||||
expect(screen.queryByText('30 min')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTOP-037: under the two clocks it says the drive leaves at that time', () => {
|
||||
open(leaving('10:00', '14:00'))
|
||||
expect(screen.getByText('14:00')).toBeInTheDocument()
|
||||
expect(screen.getByText('This visit has an end time, so the drive leaves at 14:00.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTOP-038: reached after it, the stop says by how much', () => {
|
||||
open(leaving('14:30', '14:30', [{ index: 1, code: 'missedLeave', minutes: 30 }]))
|
||||
expect(screen.getByText('Arrives 30 min after the time you set to leave')).toBeInTheDocument()
|
||||
expect(screen.getAllByText('0 min until 14:00')).toHaveLength(2)
|
||||
// Left at 14:30, so nothing under the clocks promises 14:00.
|
||||
expect(screen.queryByText('This visit has an end time, so the drive leaves at 14:00.')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-RTSTOP-039: with the travel hours over first, it reads until when and says the drive goes on in the morning', () => {
|
||||
open(leaving('10:00', '12:00'))
|
||||
expect(screen.getAllByText('until 14:00')).toHaveLength(2)
|
||||
expect(screen.getByText('The travel day ends before 14:00, so the drive goes on the next morning.')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import { seedStore } from '../../../helpers/store'
|
||||
import { buildSettings } from '../../../helpers/factories'
|
||||
import { useSettingsStore } from '../../../../src/store/settingsStore'
|
||||
|
||||
// FE-MOB-PLTIME-001 to FE-MOB-PLTIME-013
|
||||
// FE-MOB-PLTIME-001 to FE-MOB-PLTIME-015
|
||||
|
||||
const planner = buildPlanner()
|
||||
|
||||
@@ -151,4 +151,24 @@ describe('PlTimeFields', () => {
|
||||
setup({ endTime: '11:0', dayAssignments: [SELF, assignment(2, 'Park', '10:30', '12:00')] })
|
||||
expect(screen.queryByText(/places.timeCollision/)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-PLTIME-014: opened from the road trip tab, End says the drive leaves at it', () => {
|
||||
render(
|
||||
<PlTimeFields
|
||||
planner={buildPlanner({ activeTab: 'roadtrip' } as never)}
|
||||
startTime="10:00"
|
||||
endTime="14:00"
|
||||
onChange={vi.fn()}
|
||||
assignmentId={1}
|
||||
dayAssignments={[SELF]}
|
||||
hasTimeError={false}
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('roadtrip.stop.endIsLeave')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('FE-MOB-PLTIME-015: from the plan tab End stays a plain label', () => {
|
||||
setup()
|
||||
expect(screen.queryByText('roadtrip.stop.endIsLeave')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -394,6 +394,55 @@ describe('assignmentsSlice', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setAssignmentTimes', () => {
|
||||
// The pool place still carries an End of its own, which the visit shows once its
|
||||
// own override is gone, exactly as a fresh read of the day would.
|
||||
const pool = () => buildPlace({ id: 10, trip_id: 1, place_time: null, end_time: '18:00' });
|
||||
const visit = () => buildAssignment({
|
||||
id: 5, day_id: 1, place_id: 10, assignment_time: '09:00', assignment_end_time: '14:00',
|
||||
place: { ...pool(), place_time: '09:00', end_time: '14:00' },
|
||||
});
|
||||
|
||||
it('FE-ASSIGN-020: clears the End at once, with the place End showing through, and keeps the Start', async () => {
|
||||
seedStore(useTripStore, { places: [pool()], assignments: { '1': [visit()] } });
|
||||
let seen: unknown;
|
||||
server.use(
|
||||
http.put('/api/trips/1/assignments/5/time', async ({ request }) => {
|
||||
seen = await request.json();
|
||||
const mid = useTripStore.getState().assignments['1'][0];
|
||||
expect(mid).toMatchObject({ assignment_end_time: null, place: { end_time: '18:00', place_time: '09:00' } });
|
||||
return HttpResponse.json({ assignment: { ...visit(), assignment_end_time: null, place: { ...pool(), place_time: '09:00' } } });
|
||||
}),
|
||||
);
|
||||
|
||||
await useTripStore.getState().setAssignmentTimes(1, 1, 5, { place_time: '09:00', end_time: null });
|
||||
|
||||
expect(seen).toEqual({ place_time: '09:00', end_time: null });
|
||||
expect(useTripStore.getState().assignments['1'][0]).toMatchObject({
|
||||
assignment_time: '09:00', assignment_end_time: null, place: { end_time: '18:00' },
|
||||
});
|
||||
});
|
||||
|
||||
it('FE-ASSIGN-021: a refused write puts the visit back as it was', async () => {
|
||||
seedStore(useTripStore, { places: [pool()], assignments: { '1': [visit()] } });
|
||||
server.use(http.put('/api/trips/1/assignments/5/time', () => HttpResponse.json({ error: 'no' }, { status: 403 })));
|
||||
|
||||
await expect(useTripStore.getState().setAssignmentTimes(1, 1, 5, { place_time: '09:00', end_time: null })).rejects.toBeTruthy();
|
||||
|
||||
expect(useTripStore.getState().assignments['1'][0]).toMatchObject({ assignment_end_time: '14:00', place: { end_time: '14:00' } });
|
||||
});
|
||||
|
||||
it('FE-ASSIGN-022: a visit it cannot find, or one not yet saved, is left alone', async () => {
|
||||
const unsaved = { ...visit(), id: -3 };
|
||||
seedStore(useTripStore, { places: [pool()], assignments: { '1': [unsaved] } });
|
||||
|
||||
await useTripStore.getState().setAssignmentTimes(1, 1, 5, { place_time: null, end_time: null });
|
||||
await useTripStore.getState().setAssignmentTimes(1, 1, -3, { place_time: null, end_time: null });
|
||||
|
||||
expect(useTripStore.getState().assignments['1'][0]).toEqual(unsaved);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setAssignments', () => {
|
||||
it('FE-ASSIGN-019: replaces the whole assignments map', () => {
|
||||
seedStore(useTripStore, { assignments: { '1': [buildAssignment({ id: 1, day_id: 1 })] } });
|
||||
|
||||
Reference in New Issue
Block a user