test(places): cover the place sheet sections, tags, trip lists and the visited filter

This commit is contained in:
Maurice
2026-11-29 21:16:39 +01:00
parent d008331e5f
commit c944ef6de5
60 changed files with 4182 additions and 44 deletions
@@ -72,7 +72,7 @@ describe('B4A Places pool', () => {
excludePlaceIds: new Set([1]),
})} />)
expect(sidebar.filtered.map(place => place.id)).toEqual([2, 3, 4])
expect(sidebar.filterCounts).toEqual({ all: 3, unplanned: 1, planned: 1, tracks: 1 })
expect(sidebar.filterCounts).toEqual({ all: 3, unplanned: 1, planned: 1, visited: 0, tracks: 1 })
expect(sidebar.hasTracks).toBe(false)
act(() => sidebar.setPlacesSort('name'))
expect(sidebar.filtered.map(place => place.id)).toEqual([3, 4, 2])
@@ -101,7 +101,7 @@ describe('B4A Places pool', () => {
const { rerender } = render(<Host {...props} />)
act(() => { sidebar.setCategoryFilters(new Set(['7'])); sidebar.setSearch('matching') })
expect(sidebar.filtered.map(place => place.id)).toEqual([2])
expect(sidebar.filterCounts).toEqual({ all: 1, unplanned: 1, planned: 0, tracks: 0 })
expect(sidebar.filterCounts).toEqual({ all: 1, unplanned: 1, planned: 0, visited: 0, tracks: 0 })
rerender(<Host {...props} excludePlaceIds={new Set([1, 2])} />)
expect(sidebar.filtered).toEqual([])
expect(sidebar.filterCounts.all).toBe(0)
@@ -66,6 +66,15 @@ describe('places pool helpers', () => {
]);
expect(placesFilterTabs(t, true).map((tab) => tab.id)).toEqual(['all', 'unplanned', 'planned', 'tracks']);
expect(placesFilterTabs(t, true)[3].label).toBe('places.filterTracks');
// Visited (PLC-23) sits before tracks, once the reader has been somewhere on the trip.
expect(placesFilterTabs(t, true, true).map((tab) => tab.id)).toEqual([
'all',
'unplanned',
'planned',
'visited',
'tracks',
]);
expect(placesFilterTabs(t, false, true)[3].label).toBe('places.filterVisited');
});
it('FE-PLANNER-POOL-003: the category filter toggles ids in the trip store, a new set each time', () => {
@@ -1,4 +1,4 @@
// FE-PLANNER-PSHOOK-001 to FE-PLANNER-PSHOOK-060
// FE-PLANNER-PSHOOK-001 to FE-PLANNER-PSHOOK-061
import { http, HttpResponse } from 'msw';
import userEvent from '@testing-library/user-event';
import { render, screen, fireEvent, act, waitFor } from '../../../tests/helpers/render';
@@ -10,6 +10,7 @@ import { useTripStore } from '../../store/tripStore';
import { usePermissionsStore } from '../../store/permissionsStore';
import { useAddonStore } from '../../store/addonStore';
import { useSaveToCollectionStore } from '../../store/saveToCollectionStore';
import { usePlaceVisitsStore } from '../../store/placeVisitsStore';
import { ContextMenu } from '../shared/ContextMenu';
import type { Place } from '../../types';
import { usePlacesSidebar, type PlacesSidebarProps, type SidebarState } from './usePlacesSidebar';
@@ -201,7 +202,7 @@ describe('usePlacesSidebar filtering', () => {
expect(S.hasTracks).toBe(false);
expect(names()).toEqual(expect.arrayContaining(['Legacy track', 'Ordinary place']));
expect(names()).not.toContain('Tour place');
expect(S.filterCounts).toEqual({ all: 2, unplanned: 2, planned: 0, tracks: 1 });
expect(S.filterCounts).toEqual({ all: 2, unplanned: 2, planned: 0, visited: 0, tracks: 1 });
expect(S.localities).toEqual([{ country: 'Austria', count: 2, regions: [] }]);
act(() => { S.setRatingFilter(4); });
@@ -219,7 +220,7 @@ describe('usePlacesSidebar filtering', () => {
})} />);
expect(S.hasTracks).toBe(true);
expect(S.filterCounts).toEqual({ all: 2, unplanned: 2, planned: 0, tracks: 2 });
expect(S.filterCounts).toEqual({ all: 2, unplanned: 2, planned: 0, visited: 0, tracks: 2 });
act(() => { S.setFilter('tracks'); });
expect(names()).toEqual(expect.arrayContaining(['Legacy track', 'Dormant Tour']));
});
@@ -776,14 +777,14 @@ describe('usePlacesSidebar filter panel', () => {
const other = buildPlace({ id: 3, name: 'Beta', category_id: null });
const assignments = { '9': [buildAssignment({ place: planned, day_id: 9 })] };
render(<Host {...makeProps({ places: [planned, loose, other], assignments })} />);
expect(S.filterCounts).toEqual({ all: 3, unplanned: 2, planned: 1, tracks: 1 });
expect(S.filterCounts).toEqual({ all: 3, unplanned: 2, planned: 1, visited: 0, tracks: 1 });
act(() => { S.setSearch('alpha'); });
act(() => { S.setRatingFilter(5); });
expect(S.filterCounts).toEqual({ all: 2, unplanned: 1, planned: 1, tracks: 1 });
expect(S.filterCounts).toEqual({ all: 2, unplanned: 1, planned: 1, visited: 0, tracks: 1 });
act(() => { S.setCategoryFilters(new Set(['uncategorized'])); });
expect(S.filterCounts).toEqual({ all: 0, unplanned: 0, planned: 0, tracks: 0 });
expect(S.filterCounts).toEqual({ all: 0, unplanned: 0, planned: 0, visited: 0, tracks: 0 });
});
it('FE-PLANNER-PSHOOK-054: while a day is open "planned" counts that day only', () => {
@@ -806,6 +807,23 @@ describe('usePlacesSidebar filter panel', () => {
expect(S.selectedIds.size).toBe(0);
});
it('FE-PLANNER-PSHOOK-061: the places the reader visited are counted, offered and filtered (PLC-23)', async () => {
const userId = useAuthStore.getState().user?.id;
const entry = { placeIds: [2], places: [] };
const loadTripVisited = vi.fn(async () => {
usePlaceVisitsStore.setState({ visited: { [`${userId}:1`]: entry } });
return entry;
});
usePlaceVisitsStore.setState({ visited: {}, loadTripVisited });
render(<Host {...makeProps({ places: [buildPlace({ id: 1, name: 'Alpha' }), buildPlace({ id: 2, name: 'Beta' })] })} />);
expect(S.hasVisited).toBe(false);
await waitFor(() => expect(S.filterCounts.visited).toBe(1));
expect(loadTripVisited).toHaveBeenCalledWith(1);
expect(S.hasVisited).toBe(true);
act(() => { S.pickFilter('visited'); });
expect(names()).toEqual(['Beta']);
});
});
describe('usePlacesSidebar row menu entries', () => {