mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
test(tours): fix client test expectations and mocks
The type order puts run before kayak, the import button reads Import GPX or KML, and the mocks gain what the components now read: routeRun, packing items and links, the map's zoom, the translation provider and the compare store's map flag.
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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(<TourDetailDialog {...defaultProps} desktopNonModal />)
|
||||
|
||||
const distance = await screen.findByTestId('tour-activity-compare-distance')
|
||||
|
||||
@@ -371,7 +371,7 @@ describe('ToursSidebar', () => {
|
||||
<ToursSidebar tripId={1} days={[]} tours={[]} canEdit={true} onAssignToDay={vi.fn()} onSelectTour={vi.fn()} />
|
||||
)
|
||||
const file = new File(['<gpx/>'], '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', () => {
|
||||
<ToursSidebar tripId={1} days={[]} tours={[]} canEdit={true} onAssignToDay={vi.fn()} onSelectTour={vi.fn()} />
|
||||
)
|
||||
const file = new File(['<gpx/>'], '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', () => {
|
||||
<ToursSidebar tripId={1} days={[]} tours={[]} canEdit={true} onAssignToDay={vi.fn()} onSelectTour={vi.fn()} />
|
||||
)
|
||||
const file = new File(['<gpx/>'], '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'))
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ function Stateful({
|
||||
return (
|
||||
<>
|
||||
<RunFields planner={planner} locked={false} />
|
||||
<output data-testid="pace">{pace === null ? 'none' : String(pace)}</output>
|
||||
<span data-testid="pace">{pace === null ? 'none' : String(pace)}</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ function Stateful({ initial = NO_SKI_CHOICE }: { initial?: SkiChoice }) {
|
||||
return (
|
||||
<>
|
||||
<SkiClassificationFields choice={choice} onChange={setChoice} />
|
||||
<output data-testid="choice">{`${choice.discipline ?? 'none'}/${choice.technique ?? 'none'}`}</output>
|
||||
<span data-testid="choice">{`${choice.discipline ?? 'none'}/${choice.technique ?? 'none'}`}</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<undefined>((resolve) => (finish = () => resolve(undefined))));
|
||||
assignPlaceToDay.mockImplementationOnce(
|
||||
() => new Promise<undefined>((resolve) => (finish = () => resolve(undefined)))
|
||||
);
|
||||
const { result } = render();
|
||||
let first: Promise<boolean> = Promise.resolve(false);
|
||||
let second: Promise<boolean> = Promise.resolve(false);
|
||||
|
||||
@@ -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() }) }))
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user