mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(planner): undoing a place delete brings the place back whole, or is not offered
The undo wrote a new place from nine of its fields and put it on its days as a bare stop, so notes, website, phone, hours, picture, the visit times, day notes and travellers were gone while the toast said it was undone. It now writes every field the place had and plans each visit again with its times, note, end of day, route flag, travellers and leg modes, and casts the own rating again. The server takes a booked night, its booking and expense, linked expenses, file links, other members' ratings and an uploaded picture down with the place, and writing the place again brings none of that back. Such a delete is no longer offered for undo. Undo steps that name a deleted place are dropped at the delete instead of failing later, and adding a place, moving categories and the phone reorder and optimize now carry their place ids for that. Taking a stop off a day and clearing a day undo with the visit details too. The stays are read again when a deleted place had one, here and for collaborators. Refs #2604
This commit is contained in:
@@ -276,7 +276,8 @@ describe('useMPlanTimeline', () => {
|
||||
const { result } = await renderTimeline(planner)
|
||||
await act(async () => { result.current.moveRow(result.current.merged[0], 'down') })
|
||||
await waitFor(() => expect(planner.tripActions.reorderAssignments).toHaveBeenCalledWith(1, 2, [12, 11, 13]))
|
||||
expect(planner.pushUndo).toHaveBeenCalledWith('undo.reorder', expect.any(Function))
|
||||
// Tied to the day and its places, so deleting either drops a step that could only fail.
|
||||
expect(planner.pushUndo).toHaveBeenCalledWith('undo.reorder', expect.any(Function), [2], expect.arrayContaining([101, 102, 103]))
|
||||
expect(planner.updateRouteForDay).toHaveBeenCalledWith(2)
|
||||
})
|
||||
|
||||
@@ -549,7 +550,7 @@ describe('useMPlanTimeline', () => {
|
||||
const { result } = await renderTimeline(planner)
|
||||
await act(async () => { await result.current.optimize() })
|
||||
expect(planner.tripActions.reorderAssignments).toHaveBeenCalledWith(1, 2, [11, 13, 12])
|
||||
expect(planner.pushUndo).toHaveBeenCalledWith('undo.optimize', expect.any(Function))
|
||||
expect(planner.pushUndo).toHaveBeenCalledWith('undo.optimize', expect.any(Function), [2], expect.arrayContaining([101, 102, 103]))
|
||||
expect(planner.updateRouteForDay).toHaveBeenCalledWith(2)
|
||||
expect(planner.toast.success).toHaveBeenCalledWith('dayplan.toast.routeOptimized')
|
||||
|
||||
|
||||
@@ -516,6 +516,47 @@ describe('assignmentsSlice', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setAssignmentParticipants / setAssignmentLegMode', () => {
|
||||
it('FE-ASSIGN-023: the travellers the server answers with, and a leg mode it took, land on the visit', async () => {
|
||||
const place = buildPlace({ id: 10, trip_id: 1 });
|
||||
seedStore(useTripStore, { assignments: { '2': [buildAssignment({ id: 5, day_id: 2, place_id: 10, place })] } });
|
||||
let participantsBody: unknown;
|
||||
const transportBodies: unknown[] = [];
|
||||
server.use(
|
||||
http.put('/api/trips/1/assignments/5/participants', async ({ request }) => {
|
||||
participantsBody = await request.json();
|
||||
return HttpResponse.json({ participants: [{ user_id: 4, username: 'Lena' }] });
|
||||
}),
|
||||
http.put('/api/trips/1/assignments/5/transport', async ({ request }) => {
|
||||
transportBodies.push(await request.json());
|
||||
return HttpResponse.json({ success: true });
|
||||
}),
|
||||
);
|
||||
|
||||
await useTripStore.getState().setAssignmentParticipants(1, 2, 5, [4]);
|
||||
await useTripStore.getState().setAssignmentLegMode(1, 2, 5, 'driving');
|
||||
await useTripStore.getState().setAssignmentLegMode(1, 2, 5, 'cycling', 'incoming');
|
||||
|
||||
expect(participantsBody).toEqual({ user_ids: [4] });
|
||||
expect(transportBodies).toEqual([{ transport_mode: 'driving' }, { transport_mode: 'cycling', direction: 'incoming' }]);
|
||||
const visit = useTripStore.getState().assignments['2'][0];
|
||||
expect(visit.participants).toEqual([{ user_id: 4, username: 'Lena' }]);
|
||||
expect(visit.leg_transport_mode).toBe('driving');
|
||||
expect(visit.incoming_leg_transport_mode).toBe('cycling');
|
||||
});
|
||||
|
||||
it('FE-ASSIGN-024: a refused write is thrown and leaves the visit as it was', async () => {
|
||||
const place = buildPlace({ id: 10, trip_id: 1 });
|
||||
seedStore(useTripStore, { assignments: { '2': [buildAssignment({ id: 5, day_id: 2, place_id: 10, place })] } });
|
||||
server.use(
|
||||
http.put('/api/trips/1/assignments/5/participants', () => HttpResponse.json({ error: 'nope' }, { status: 400 })),
|
||||
);
|
||||
|
||||
await expect(useTripStore.getState().setAssignmentParticipants(1, 2, 5, [4])).rejects.toBeTruthy();
|
||||
expect(useTripStore.getState().assignments['2'][0].participants).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
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