mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
merge: update Tours branch with current Places filters
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-TP-HOOK-001 to FE-TP-HOOK-175
|
||||
// FE-TP-HOOK-001 to FE-TP-HOOK-177
|
||||
import React from 'react'
|
||||
import { renderHook, act, waitFor } from '@testing-library/react'
|
||||
import { TranslationProvider } from '../../i18n/TranslationContext'
|
||||
@@ -646,6 +646,47 @@ describe('useTripPlanner — map derivations', () => {
|
||||
expect(result.current.mapPlaces.map(p => p.id)).toEqual([2])
|
||||
})
|
||||
|
||||
it('FE-TP-HOOK-177: losing the last track moves the "Tracks" filter back to all', async () => {
|
||||
// The phone map has no places list mounted, so this hook is what keeps the
|
||||
// filter from pointing at a pool no control offers any more.
|
||||
seedTrip({
|
||||
places: [geo(1), geo(2, { route_geometry: '[[1,2]]' })],
|
||||
placesFilter: 'tracks',
|
||||
})
|
||||
|
||||
const { result } = await renderPlanner()
|
||||
expect(useTripStore.getState().placesFilter).toBe('tracks')
|
||||
|
||||
act(() => { useTripStore.setState({ places: [geo(1)] }) })
|
||||
|
||||
await waitFor(() => expect(useTripStore.getState().placesFilter).toBe('all'))
|
||||
expect(result.current.mapPlaces.map(p => p.id)).toEqual([1])
|
||||
})
|
||||
|
||||
it('Tours enabled clears a stale Tracks filter even while track geometry remains', async () => {
|
||||
const tour: TourListItem = {
|
||||
place_id: 7, name: 'Ridge walk', tour_type: 'hike', distance: 4, elevation_gain: 100,
|
||||
elevation_loss: 80, duration: null, difficulty: null, wanderer_ref: null, match_confidence: 1,
|
||||
tour_group_id: null, max_hiking_difficulty: 2, planned: false, caution: false,
|
||||
}
|
||||
useAddonStore.setState({ addons: [{ id: 'tours', enabled: true } as never], loaded: true })
|
||||
vi.mocked(addonsApi.enabled).mockResolvedValue({ addons: [{ id: 'tours' }] })
|
||||
vi.spyOn(toursApi, 'list').mockResolvedValue({ tours: [tour] })
|
||||
seedTrip({
|
||||
places: [
|
||||
buildPlace({ id: 7, lat: 1, lng: 2, tour_place_id: 7, route_geometry: '[[1,2],[3,4]]' }),
|
||||
buildPlace({ id: 8, lat: 3, lng: 4, route_geometry: '[[5,6],[7,8]]' }),
|
||||
],
|
||||
placesFilter: 'tracks',
|
||||
})
|
||||
|
||||
const { result } = await renderPlanner()
|
||||
await waitFor(() => expect(useTripStore.getState().placesFilter).toBe('all'))
|
||||
|
||||
expect(result.current.enabledAddons.tours).toBe(true)
|
||||
expect(result.current.mapPlaces.map(place => place.id)).toEqual([7, 8])
|
||||
})
|
||||
|
||||
it('FE-TP-HOOK-027: the category filter honours the uncategorized bucket', async () => {
|
||||
seedTrip({
|
||||
places: [geo(1, { category_id: 3 }), geo(2, { category_id: null })],
|
||||
@@ -660,6 +701,20 @@ describe('useTripPlanner — map derivations', () => {
|
||||
expect(result.current.mapPlaces.map(p => p.id)).toEqual([1])
|
||||
})
|
||||
|
||||
it('FE-TP-HOOK-176: the rating floor the lists set also thins the markers', async () => {
|
||||
seedTrip({
|
||||
places: [geo(1, { rating_avg: 4.5 }), geo(2, { rating_avg: 3 }), geo(3, { rating_avg: null })],
|
||||
placesRatingFilter: 4,
|
||||
})
|
||||
|
||||
const { result } = await renderPlanner()
|
||||
|
||||
expect(result.current.mapPlaces.map(p => p.id)).toEqual([1])
|
||||
|
||||
act(() => { useTripStore.getState().setPlacesRatingFilter('all') })
|
||||
expect(result.current.mapPlaces.map(p => p.id)).toEqual([1, 2, 3])
|
||||
})
|
||||
|
||||
it('FE-TP-HOOK-028: the unplanned filter drops places that sit on a day', async () => {
|
||||
const planned = geo(1)
|
||||
seedTrip({
|
||||
|
||||
@@ -83,6 +83,7 @@ import {
|
||||
} from '../../utils/connectionsVisibility'
|
||||
import { usePlaceLanguage } from '../../hooks/usePlaceLanguage'
|
||||
import { plannedPlaceIds, plannedPlaceIdsForDay } from '../../utils/plannedPlaces'
|
||||
import { matchesPlacesFilter } from '../../utils/placesFilter'
|
||||
import { pendingStayPlaceIds } from '../../utils/pendingStays'
|
||||
import { useDayDelete } from './useDayDelete'
|
||||
import { useDayAdd } from './useDayAdd'
|
||||
@@ -733,6 +734,7 @@ export function useTripPlanner() {
|
||||
// switches can't desync the marker set from the filter UI (#1541).
|
||||
const placesFilter = useTripStore((s) => s.placesFilter)
|
||||
const placesCategoryFilter = useTripStore((s) => s.placesCategoryFilter)
|
||||
const placesRatingFilter = useTripStore((s) => s.placesRatingFilter)
|
||||
|
||||
const [expandedDayIds, setExpandedDayIds] = useState<Set<number> | null>(null)
|
||||
|
||||
@@ -771,28 +773,33 @@ export function useTripPlanner() {
|
||||
|
||||
const compactIds = compactUnplanned ? plannedPlaceIds({ assignments, accommodations: tripAccommodations, reservations }) : null
|
||||
const pendingIds = pendingStayPlaceIds(tripAccommodations, reservations)
|
||||
const filterState = { filter: placesFilter, categoryFilters: placesCategoryFilter, ratingFilter: placesRatingFilter }
|
||||
return places.filter(p => {
|
||||
if (!p.lat || !p.lng) return false
|
||||
if (placesFilter === 'tracks' && !p.route_geometry) return false
|
||||
if (placesCategoryFilter.size > 0) {
|
||||
if (p.category_id == null) {
|
||||
if (!placesCategoryFilter.has('uncategorized')) return false
|
||||
} else if (!placesCategoryFilter.has(String(p.category_id))) return false
|
||||
}
|
||||
// Collapsed-day declutter hides a day's stops on every filter EXCEPT 'planned':
|
||||
// there the user asked to see the whole plan on the map, so a collapsed day
|
||||
// must not drop its planned places.
|
||||
if (placesFilter !== 'planned' && hiddenPlaceIds.has(p.id)) return false
|
||||
if (placesFilter === 'unplanned' && plannedIds && plannedIds.has(p.id)) return false
|
||||
if (placesFilter === 'planned' && plannedIds && !plannedIds.has(p.id)) return false
|
||||
return true
|
||||
// Pool, categories and rating floor: the very matcher the lists use (#1541).
|
||||
return matchesPlacesFilter(p, filterState, { plannedIds })
|
||||
}).map(p => {
|
||||
// How the map tells a place apart (#2024, #2281); untouched places keep their identity.
|
||||
const compact = !!compactIds && !compactIds.has(p.id)
|
||||
const pending = pendingIds.has(p.id)
|
||||
return compact || pending ? { ...p, _compact: compact, _pending: pending } : p
|
||||
})
|
||||
}, [places, placesCategoryFilter, placesFilter, assignments, expandedDayIds, selectedDayId, days, tripAccommodations, reservations, compactUnplanned])
|
||||
}, [places, placesCategoryFilter, placesFilter, placesRatingFilter, assignments, expandedDayIds, selectedDayId, days, tripAccommodations, reservations, compactUnplanned])
|
||||
|
||||
// The "Tracks" pool is only offered while a place carries a track. When the last
|
||||
// one goes (deleted here or by a collaborator), fall back to "all" — here, because
|
||||
// this hook is mounted whatever is on screen: the lists that used to do it are not
|
||||
// mounted while the phone map is in front, and the map would sit empty under a
|
||||
// "Tracks" filter no control offers any more.
|
||||
const setPlacesFilter = useTripStore((s) => s.setPlacesFilter)
|
||||
const hasTracks = useMemo(() => !toursEnabled && places.some(p => p.route_geometry), [places, toursEnabled])
|
||||
useEffect(() => {
|
||||
if (placesFilter === 'tracks' && !hasTracks) setPlacesFilter('all')
|
||||
}, [placesFilter, hasTracks, setPlacesFilter])
|
||||
|
||||
const { route, routeWalking, routeSegments, routeVias, routeInfo, setRoute, setRouteInfo, updateRouteForDay } = useRouteCalculation({ assignments } as any, selectedDayId, routeShown, routeProfile, tripAccommodations)
|
||||
// Road trip mode already draws the whole trip its own way, so the overview stands
|
||||
|
||||
Reference in New Issue
Block a user