mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 06:26:26 +00:00
fix(tours): restrict permanent deletion to tours workspace
This commit is contained in:
@@ -78,6 +78,21 @@ describe('useTourPlaceIds', () => {
|
||||
expect(result.current.tours).toEqual([edited, tour])
|
||||
})
|
||||
|
||||
it('removes a deleted Tour from the visible list before the refresh completes', async () => {
|
||||
const { result } = renderHook(() => useTourPlaceIds(7, true))
|
||||
await waitFor(() => expect(result.current.tours).toEqual([tour]))
|
||||
const refresh = deferred<{ tours: TourListItem[] }>()
|
||||
vi.mocked(toursApi.list).mockReturnValueOnce(refresh.promise)
|
||||
|
||||
act(() => result.current.invalidateTourPlaceIds({ removedPlaceIds: [tour.place_id] }))
|
||||
|
||||
expect(result.current.tours).toEqual([])
|
||||
expect(result.current.tourPlaceIds.size).toBe(0)
|
||||
await act(async () => refresh.resolve({ tours: [] }))
|
||||
await waitFor(() => expect(result.current.toursLoading).toBe(false))
|
||||
expect(result.current.tourLoadError).toBe(false)
|
||||
})
|
||||
|
||||
it('shows only the new trip Tours after a successful trip switch', async () => {
|
||||
const tripTwoTour = tourFor(84, 'Trip two tour')
|
||||
vi.mocked(toursApi.list).mockImplementation(async tripId => ({
|
||||
|
||||
@@ -54,6 +54,11 @@ export function useTourPlaceIds(tripId: number, enabled: boolean) {
|
||||
|| !activeRequestRef.current.enabled) return
|
||||
const added = change?.placeIds ?? []
|
||||
const removed = change?.removedPlaceIds ?? []
|
||||
if (removed.length) {
|
||||
setTourData(current => current?.tripId === tripId
|
||||
? { tripId, tours: current.tours.filter(tour => !removed.includes(tour.place_id)) }
|
||||
: current)
|
||||
}
|
||||
if (added.length || removed.length) {
|
||||
setPendingPlaceIds(current => {
|
||||
const ids = new Set(current?.tripId === tripId ? current.ids : [])
|
||||
|
||||
Reference in New Issue
Block a user