diff --git a/client/src/components/Atlas/tourActivity/tourActivityStatsModel.test.ts b/client/src/components/Atlas/tourActivity/tourActivityStatsModel.test.ts index 5c1e5cb1f..aed23fbc6 100644 --- a/client/src/components/Atlas/tourActivity/tourActivityStatsModel.test.ts +++ b/client/src/components/Atlas/tourActivity/tourActivityStatsModel.test.ts @@ -59,7 +59,7 @@ describe('tourActivityStatsModel', () => { entry({ tour_type: 'hike' }), entry({ tour_type: 'bike', date: '2026-12-01' }), ]; - expect(typeOptions(entries, TODAY)).toEqual(['all', 'hike', 'kayak', 'run']); + expect(typeOptions(entries, TODAY)).toEqual(['all', 'hike', 'run', 'kayak']); }); it('FE-STA2-MODEL-004: reads the year of a year period only', () => { diff --git a/client/src/components/Tours/TourDetailDialog.test.tsx b/client/src/components/Tours/TourDetailDialog.test.tsx index cb640484d..cc720af2d 100644 --- a/client/src/components/Tours/TourDetailDialog.test.tsx +++ b/client/src/components/Tours/TourDetailDialog.test.tsx @@ -6,6 +6,7 @@ import { buildAssignment, buildDay, buildPlace } from '../../../tests/helpers/fa import { paddleBench } from '../../../tests/helpers/paddleCheck' import { resetAllStores, seedStore } from '../../../tests/helpers/store' import { useSettingsStore } from '../../store/settingsStore' +import { useTourActivityCompareStore } from '../../store/tourActivityCompareStore' import TourDetailDialog from './TourDetailDialog' import { useTripStore } from '../../store/tripStore' import { tourRepo } from '../../repo/tourRepo' @@ -64,6 +65,7 @@ beforeEach(() => { // A repository answer one test stubs never reaches the tests after it. afterEach(() => { vi.restoreAllMocks() + useTourActivityCompareStore.setState({ comparison: null, mapAvailable: false }) }) describe('TourDetailDialog', () => { @@ -346,6 +348,8 @@ describe('TourDetailDialog', () => { ] as [number, number][], } vi.spyOn(tourRepo, 'detail').mockResolvedValue({ tour, waypoints: [], activities: [activity] }) + // The planner map is on screen, so the map detail may offer the switch. + useTourActivityCompareStore.setState({ comparison: null, mapAvailable: true }) const { unmount } = render() const distance = await screen.findByTestId('tour-activity-compare-distance') diff --git a/client/src/components/Tours/ToursSidebar.test.tsx b/client/src/components/Tours/ToursSidebar.test.tsx index e0da3372b..052f01cac 100644 --- a/client/src/components/Tours/ToursSidebar.test.tsx +++ b/client/src/components/Tours/ToursSidebar.test.tsx @@ -371,7 +371,7 @@ describe('ToursSidebar', () => { ) const file = new File([''], 'loipe.gpx', { type: 'application/gpx+xml' }) - pickFiles(screen.getByRole('button', { name: 'Import GPX' }), [file]) + pickFiles(screen.getByRole('button', { name: 'Import GPX or KML' }), [file]) await screen.findByRole('dialog') fireEvent.click(screen.getByTestId('tour-type-select')) @@ -404,7 +404,7 @@ describe('ToursSidebar', () => { ) const file = new File([''], 'laps.gpx', { type: 'application/gpx+xml' }) - pickFiles(screen.getByRole('button', { name: 'Import GPX' }), [file]) + pickFiles(screen.getByRole('button', { name: 'Import GPX or KML' }), [file]) await screen.findByRole('dialog') fireEvent.click(screen.getByTestId('tour-type-select')) @@ -424,7 +424,7 @@ describe('ToursSidebar', () => { ) const file = new File([''], 'ride.gpx', { type: 'application/gpx+xml' }) - pickFiles(screen.getByRole('button', { name: 'Import GPX' }), [file]) + pickFiles(screen.getByRole('button', { name: 'Import GPX or KML' }), [file]) await screen.findByRole('dialog') fireEvent.click(screen.getByTestId('tour-type-select')) fireEvent.click(screen.getByTestId('tour-type-option-horse')) diff --git a/client/src/components/Tours/planner/useTourPlanner.stages.test.tsx b/client/src/components/Tours/planner/useTourPlanner.stages.test.tsx index ab11756ca..4bc0e7570 100644 --- a/client/src/components/Tours/planner/useTourPlanner.stages.test.tsx +++ b/client/src/components/Tours/planner/useTourPlanner.stages.test.tsx @@ -2,16 +2,19 @@ import { act, renderHook } from '@testing-library/react'; import { runMinutesAtPace } from '@trek/shared'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -const { routeWalkingTour, enrichTourElevations, createTour, detailTour, updateTour, paddlePlan } = vi.hoisted(() => ({ - routeWalkingTour: vi.fn(), - enrichTourElevations: vi.fn(), - createTour: vi.fn(), - detailTour: vi.fn(), - updateTour: vi.fn(), - paddlePlan: vi.fn(), -})); +const { routeWalkingTour, routeRun, enrichTourElevations, createTour, detailTour, updateTour, paddlePlan } = vi.hoisted( + () => ({ + routeWalkingTour: vi.fn(), + routeRun: vi.fn(), + enrichTourElevations: vi.fn(), + createTour: vi.fn(), + detailTour: vi.fn(), + updateTour: vi.fn(), + paddlePlan: vi.fn(), + }) +); -vi.mock('./tourRouting', () => ({ routeWalkingTour, enrichTourElevations })); +vi.mock('./tourRouting', () => ({ routeWalkingTour, routeRun, enrichTourElevations })); vi.mock('../../../repo/tourRepo', () => ({ tourRepo: { create: createTour, detail: detailTour, update: updateTour } })); vi.mock('../../../repo/paddleRouteRepo', () => ({ paddleRouteRepo: { plan: paddlePlan, forget: vi.fn() } })); vi.mock('../useTourPermissions', () => ({ @@ -95,6 +98,7 @@ describe('useTourPlanner, multi-day tours (MDT-01)', () => { vi.useFakeTimers(); localStorage.clear(); routeWalkingTour.mockReset().mockResolvedValue(routed); + routeRun.mockReset().mockResolvedValue(routed); enrichTourElevations.mockReset().mockResolvedValue(enriched); createTour.mockReset(); detailTour.mockReset(); @@ -154,7 +158,9 @@ describe('useTourPlanner, multi-day tours (MDT-01)', () => { expect(result.current.waypoints[3].stageEnd).toBeUndefined(); expect(result.current.stages.lost).toBe(1); // A later change that loses nothing clears the notice. - act(() => result.current.setWaypointPosition(result.current.waypoints[1].id, 48.011, 11.021)); + act(() => { + result.current.setWaypointPosition(result.current.waypoints[1].id, 48.011, 11.021); + }); expect(result.current.stages.lost).toBe(0); }); diff --git a/client/src/components/Tours/run/RunFields.test.tsx b/client/src/components/Tours/run/RunFields.test.tsx index 64ac96fbe..a621bfe84 100644 --- a/client/src/components/Tours/run/RunFields.test.tsx +++ b/client/src/components/Tours/run/RunFields.test.tsx @@ -37,7 +37,7 @@ function Stateful({ return ( <> - {pace === null ? 'none' : String(pace)} + {pace === null ? 'none' : String(pace)} ); } diff --git a/client/src/components/Tours/ski/SkiClassificationFields.test.tsx b/client/src/components/Tours/ski/SkiClassificationFields.test.tsx index f8d9e6fac..1a93696c9 100644 --- a/client/src/components/Tours/ski/SkiClassificationFields.test.tsx +++ b/client/src/components/Tours/ski/SkiClassificationFields.test.tsx @@ -14,7 +14,7 @@ function Stateful({ initial = NO_SKI_CHOICE }: { initial?: SkiChoice }) { return ( <> - {`${choice.discipline ?? 'none'}/${choice.technique ?? 'none'}`} + {`${choice.discipline ?? 'none'}/${choice.technique ?? 'none'}`} ); } diff --git a/client/src/components/Tours/stages/useTourStageDays.test.ts b/client/src/components/Tours/stages/useTourStageDays.test.ts index d78d802d3..4b4cb215e 100644 --- a/client/src/components/Tours/stages/useTourStageDays.test.ts +++ b/client/src/components/Tours/stages/useTourStageDays.test.ts @@ -2,6 +2,7 @@ import { act, renderHook } from '@testing-library/react'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { resetAllStores, seedStore } from '../../../../tests/helpers/store'; +import { TranslationProvider } from '../../../i18n/TranslationContext'; import { useTripStore } from '../../../store/tripStore'; import type { AssignmentsMap } from '../../../types'; import { dayHoldsTour, stageDaysOf, useTourStageDays } from './useTourStageDays'; @@ -12,7 +13,10 @@ vi.mock('../../shared/Toast', () => ({ useToast: () => toast })); /** Tour 42: its first stage on day 3, the whole of tour 7 on day 4, day 5 free. */ const assignments = { '3': [{ id: 31, place_id: 42, tour_stage_key: 'stop-start' }], - '4': [{ id: 41, place_id: 7, tour_stage_key: null }, { id: 42, place_id: 42, tour_stage_key: null }], + '4': [ + { id: 41, place_id: 7, tour_stage_key: null }, + { id: 42, place_id: 42, tour_stage_key: null }, + ], '5': [], } as unknown as AssignmentsMap; @@ -26,7 +30,8 @@ beforeEach(() => { seedStore(useTripStore, { assignments, assignPlaceToDay, moveAssignment, removeAssignment }); }); -const render = (canAssign = true) => renderHook(() => useTourStageDays({ tripId: 9, placeId: 42, canAssign })); +const render = (canAssign = true) => + renderHook(() => useTourStageDays({ tripId: 9, placeId: 42, canAssign }), { wrapper: TranslationProvider }); describe('stage days', () => { it('FE-TOUR-STAGE-DAYS-001: reads which day holds which stage, by its starting stop', () => { @@ -84,7 +89,9 @@ describe('stage days', () => { it('FE-TOUR-STAGE-DAYS-006: sends a stage once while it is on its way', async () => { let finish: () => void = () => undefined; - assignPlaceToDay.mockImplementationOnce(() => new Promise((resolve) => (finish = () => resolve(undefined)))); + assignPlaceToDay.mockImplementationOnce( + () => new Promise((resolve) => (finish = () => resolve(undefined))) + ); const { result } = render(); let first: Promise = Promise.resolve(false); let second: Promise = Promise.resolve(false); diff --git a/client/src/components/Tours/toursPermissions.test.tsx b/client/src/components/Tours/toursPermissions.test.tsx index 05853732f..9fd95d062 100644 --- a/client/src/components/Tours/toursPermissions.test.tsx +++ b/client/src/components/Tours/toursPermissions.test.tsx @@ -18,13 +18,16 @@ const state = vi.hoisted(() => ({ detail: vi.fn(), route: vi.fn(), elevation: vi.fn(), + // One array for every render, as the store keeps it: a new one each time would read as a change. + packingItems: [] as never[], })) -vi.mock('../../store/tripStore', () => ({ useTripStore: (selector: (store: unknown) => unknown) => selector({ trip: state.trip, loadTrip: state.loadTrip, refreshPlaces: state.refreshPlaces, places: [] }) })) +vi.mock('../../store/tripStore', () => ({ useTripStore: (selector: (store: unknown) => unknown) => selector({ trip: state.trip, loadTrip: state.loadTrip, refreshPlaces: state.refreshPlaces, places: [], packingItems: state.packingItems }) })) vi.mock('../../store/authStore', () => ({ useAuthStore: (selector: (store: unknown) => unknown) => selector({ user: state.user }) })) vi.mock('../../store/settingsStore', () => ({ useSettingsStore: (selector: (store: unknown) => unknown) => selector({ settings: { distance_unit: 'metric' } }) })) vi.mock('../Map/MapViewAuto', () => ({ MapViewAuto: () => null })) vi.mock('../../repo/tourRepo', () => ({ tourRepo: { importGpx: state.importGpx, previewGpx: state.previewGpx, create: state.create, update: state.update, detail: state.detail } })) +vi.mock('../../repo/tourPackingLinkRepo', () => ({ tourPackingLinkRepo: { read: () => Promise.resolve(null), link: vi.fn(), unlink: vi.fn() } })) vi.mock('./planner/tourRouting', () => ({ routeWalkingTour: state.route, enrichTourElevations: state.elevation })) vi.mock('../../i18n', () => ({ useTranslation: () => ({ t: (key: string) => key, locale: 'en' }), translateApiError: () => 'error' })) vi.mock('../shared/Toast', () => ({ useToast: () => ({ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }) })) diff --git a/client/src/pages/tripPlanner/TourPlannerMapStage.test.tsx b/client/src/pages/tripPlanner/TourPlannerMapStage.test.tsx index ad0e1d13e..7a98649cb 100644 --- a/client/src/pages/tripPlanner/TourPlannerMapStage.test.tsx +++ b/client/src/pages/tripPlanner/TourPlannerMapStage.test.tsx @@ -45,6 +45,7 @@ const stage = vi.hoisted(() => { getNorth: () => 46.6, getEast: () => 11.9, })), + getZoom: vi.fn(() => 12), remove: vi.fn(), fitBounds: vi.fn(), setTerrain: vi.fn(), diff --git a/client/src/pages/tripPlanner/useTourDetailActions.test.ts b/client/src/pages/tripPlanner/useTourDetailActions.test.ts index c409ba9be..c87ad4e78 100644 --- a/client/src/pages/tripPlanner/useTourDetailActions.test.ts +++ b/client/src/pages/tripPlanner/useTourDetailActions.test.ts @@ -27,7 +27,8 @@ describe('useTourDetailActions', () => { sessionStorage.setItem('trip-lists-subtab-5', 'todo'); const lists = renderHook(() => useListsSubTab(5)); expect(lists.result.current[0]).toBe('todo'); - act(() => actions(planner()).onOpenPacking()); + const a = actions(planner()); + act(() => a.onOpenPacking()); expect(lists.result.current[0]).toBe('packing'); }); });