mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
fix(tours): time a run's stages at its pace and leave a ride's stages untimed
A multi-day run's stages took a share of the foot router's time while the run itself is timed at the runner's pace, so the stages did not add up to the run. A ride has no time at all, so its stages have none either.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
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(() => ({
|
||||
@@ -23,7 +24,7 @@ vi.mock('../useTourPermissions', () => ({
|
||||
import { validDraft } from './tourPlannerDraft';
|
||||
import { useTourPlanner } from './useTourPlanner';
|
||||
|
||||
// FE-TOUR-STAGES-001 to FE-TOUR-STAGES-009 (MDT-01)
|
||||
// FE-TOUR-STAGES-001 to FE-TOUR-STAGES-010 (MDT-01)
|
||||
|
||||
const POINTS: Array<[number, number]> = [
|
||||
[48, 11],
|
||||
@@ -271,4 +272,19 @@ describe('useTourPlanner, multi-day tours (MDT-01)', () => {
|
||||
expect(result.current.stages.lost).toBe(0);
|
||||
expect(result.current.waypoints.find((point) => point.id === stop)?.stageEnd).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-TOUR-STAGES-010: a run times every stage at the runner pace, as the whole run is timed, never by the router (RUN-01)', async () => {
|
||||
const { result } = await plannedHike(71);
|
||||
act(() => result.current.setTourType('run'));
|
||||
await settle();
|
||||
act(() => result.current.stages.toggleStageEnd(result.current.waypoints[1].id));
|
||||
// Without a pace the run has no time, and neither have its stages.
|
||||
expect(result.current.stages.stages.map((stage) => stage.minutes)).toEqual([null, null]);
|
||||
act(() => result.current.runPace.setPace(360));
|
||||
const stages = result.current.stages.stages;
|
||||
expect(stages.every((stage) => (stage.distanceKm ?? 0) > 0)).toBe(true);
|
||||
expect(stages.map((stage) => stage.minutes)).toEqual(
|
||||
stages.map((stage) => runMinutesAtPace(stage.distanceKm ?? 0, 360))
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -552,7 +552,7 @@ export function useTourPlanner({ tripId, active = true, onSaved, canEdit: editPe
|
||||
: null, [effectiveSpeedKmh, isPaddle, paddleSpeedInvalid, portageSpeedKmh, routedLegLengths])
|
||||
const stages = useTourStages({
|
||||
waypoints, line: routeCurrent ? (enrichedGeometry ?? route) : null, tourType, routerSeconds: durationSeconds,
|
||||
paddle: stagePaddle, commit: commitWaypoints, mayEdit: mayEditPoints,
|
||||
paddle: stagePaddle, runPaceSecondsPerKm, commit: commitWaypoints, mayEdit: mayEditPoints,
|
||||
draftKey: `${editingPlaceId ?? 'new'}:${newDraftGeneration}`,
|
||||
lost: stageLoss,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user