mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
fix(planner): treat the trip opened before as still loading when another one opens
The store kept the previous trip until loadTrip ran after the first render, so the desktop planner mounted with that trip under the new id for a frame.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-TP-TABLINK-001
|
||||
// FE-TP-TABLINK-001, FE-TP-OPEN-001
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
@@ -108,3 +108,16 @@ describe('useTripPlanner — ?tab= while the planner is open', () => {
|
||||
expect(sessionStorage.getItem('trip-tab-42')).toBe('collab');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useTripPlanner: opening another trip', () => {
|
||||
it('FE-TP-OPEN-001: the trip still held from the one opened before counts as loading, not as this one', async () => {
|
||||
useTripStore.setState({ trip: buildTrip({ id: 7, title: 'Rome' }), isLoading: false });
|
||||
const { result } = renderHook(() => useTripPlanner(), { wrapper });
|
||||
expect(result.current.isLoading).toBe(true);
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
act(() => useTripStore.setState({ trip: buildTrip({ id: 42, title: 'Kyoto' }) }));
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -724,10 +724,14 @@ export function useTripPlanner() {
|
||||
return () => clearTimeout(timer)
|
||||
}, [isLoading])
|
||||
|
||||
// The store still holds the trip opened before until loadTrip runs after the first
|
||||
// render, so that trip counts as loading too rather than showing under this one's id.
|
||||
const opening = isLoading || (trip != null && trip.id !== tripId)
|
||||
|
||||
return {
|
||||
tripId, navigate, toast, t, language, locale, settings, placesPhotosEnabled,
|
||||
trip, days, places, assignments, storedAssignments, packingItems, todoItems, categories, reservations, budgetItems, files,
|
||||
selectedDayId, isLoading, tripActions, can, canUploadFiles,
|
||||
selectedDayId, isLoading: opening, tripActions, can, canUploadFiles,
|
||||
pushUndo, undo, canUndo, lastActionLabel, handleUndo,
|
||||
enabledAddons, collabFeatures, journalId: journal.openJournalId, tripAccommodations, setTripAccommodations,
|
||||
roadtripMode, toggleRoadtripMode, roadtripActive, roadtripFeedActive, roadtripRoutes, roadtripLineColors, roadtripMapLines, roadtripMapPlaces, collapsedRoadtripDays, toggleRoadtripDay, roadtripCorridor,
|
||||
|
||||
Reference in New Issue
Block a user