mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(tours): the lint the paddle work grew, back to the baseline
The region load and obstacle helpers move out of their component files (paddleRegionLoad.ts, paddleObstaclePlace.ts), so those files export components only (react-refresh). TourPlannerMapStage takes the take-from-card rule out into paddlePlaceFromCard and works out the cards' end inset once (complexity 24, back under 20). The tour tests reach list items through at() and must() instead of non-null assertions, a position change in the shaping test is voided rather than left floating, and PLOAD-004 seeds its regions with Promise.all.
This commit is contained in:
@@ -10,6 +10,13 @@ import type { PaddleTourRoute } from './paddleRouting';
|
||||
import TourWaypointList from './TourWaypointList';
|
||||
import type { TourPlannerController } from './useTourPlanner';
|
||||
|
||||
/** The item at `i`, or a failure that names the index instead of a later undefined. */
|
||||
function at<T>(list: readonly T[], i: number): T {
|
||||
const item = list[i];
|
||||
if (item === undefined) throw new Error(`nothing at ${i}`);
|
||||
return item;
|
||||
}
|
||||
|
||||
vi.mock('./useWaypointPlaceNames', () => ({ useWaypointPlaceNames: () => ({}) }));
|
||||
|
||||
const START = { id: 'a', lat: 49.1, lng: 12.1, role: 'start' as const };
|
||||
@@ -67,7 +74,7 @@ describe('TourWaypointList', () => {
|
||||
render(<TourWaypointList planner={planner()} canEdit isSaving={false} />);
|
||||
const rows = screen.getAllByTestId('tour-planner-waypoint-row');
|
||||
expect(rows).toHaveLength(4);
|
||||
expect(within(rows[1]!).getByLabelText('Shaping point')).toHaveAttribute('data-waypoint-shaping', 'true');
|
||||
expect(within(at(rows, 1)).getByLabelText('Shaping point')).toHaveAttribute('data-waypoint-shaping', 'true');
|
||||
expect(
|
||||
[...document.querySelectorAll('[data-waypoint-number]')].map((el) => el.getAttribute('data-waypoint-number'))
|
||||
).toEqual(['1', '2', '3']);
|
||||
@@ -77,7 +84,7 @@ describe('TourWaypointList', () => {
|
||||
it('FE-TOUR-WAYPOINT-LIST-002: the menu plans a routed leg again, draws it by hand, and turns a stop into a shaping point', async () => {
|
||||
const controller = planner({ selectedWaypointId: 'b' });
|
||||
render(<TourWaypointList planner={controller} canEdit isSaving={false} />);
|
||||
const row = screen.getAllByTestId('tour-planner-waypoint-row')[2]!;
|
||||
const row = at(screen.getAllByTestId('tour-planner-waypoint-row'), 2);
|
||||
await userEvent.click(within(row).getByRole('button', { name: 'More actions' }));
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Plan the next leg again' }));
|
||||
expect(controller.recomputeLeg).toHaveBeenCalledWith('b');
|
||||
@@ -95,14 +102,14 @@ describe('TourWaypointList', () => {
|
||||
const controller = planner({ selectedWaypointId: 's' });
|
||||
const { rerender } = render(<TourWaypointList planner={controller} canEdit isSaving={false} />);
|
||||
await userEvent.click(
|
||||
within(screen.getAllByTestId('tour-planner-waypoint-row')[1]!).getByRole('button', { name: 'More actions' })
|
||||
within(at(screen.getAllByTestId('tour-planner-waypoint-row'), 1)).getByRole('button', { name: 'More actions' })
|
||||
);
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Make it a stop' }));
|
||||
expect(controller.setWaypointShaping).toHaveBeenCalledWith('s', false);
|
||||
|
||||
rerender(<TourWaypointList planner={planner({ selectedWaypointId: 'a' })} canEdit isSaving={false} />);
|
||||
await userEvent.click(
|
||||
within(screen.getAllByTestId('tour-planner-waypoint-row')[0]!).getByRole('button', { name: 'More actions' })
|
||||
within(at(screen.getAllByTestId('tour-planner-waypoint-row'), 0)).getByRole('button', { name: 'More actions' })
|
||||
);
|
||||
expect(screen.queryByRole('button', { name: 'Make it a shaping point' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -37,7 +37,8 @@ import { fs } from '../../shared/DialogShell';
|
||||
import { Tooltip } from '../../shared/Tooltip';
|
||||
import { LockIcon, PortageIcon } from '../paddle/PaddleGlyph';
|
||||
import { AutoPointPill, PaddleLegFailureRow, PaddleLegNotes } from '../paddle/PaddleLegParts';
|
||||
import { isRegionLoadPending, PaddleRegionLoadRow, regionLoadFailure } from '../paddle/PaddleRegionLoadRow';
|
||||
import { isRegionLoadPending, regionLoadFailure } from '../paddle/paddleRegionLoad';
|
||||
import { PaddleRegionLoadRow } from '../paddle/PaddleRegionLoadRow';
|
||||
import { LockRow, PaddleRolePill, PendingPortageRow, PortageLegRow } from '../paddle/PaddleWaypointParts';
|
||||
import { usePaddleRegionLoad } from '../paddle/usePaddleRegionLoad';
|
||||
import { usePaddleWaypointActions } from '../paddle/usePaddleWaypointActions';
|
||||
|
||||
@@ -11,6 +11,13 @@ import {
|
||||
type PaddlePoint,
|
||||
} from './paddleRouting';
|
||||
|
||||
/** The item at `i`, or a failure that names the index instead of a later undefined. */
|
||||
function at<T>(list: readonly T[], i: number): T {
|
||||
const item = list[i];
|
||||
if (item === undefined) throw new Error(`nothing at ${i}`);
|
||||
return item;
|
||||
}
|
||||
|
||||
vi.mock('../../../repo/paddleRouteRepo', () => ({ paddleRouteRepo: { plan: vi.fn(), forget: vi.fn() } }));
|
||||
|
||||
const KAYAK = { boat: 'kayak' as const, lakeStyle: 'direct' as const };
|
||||
@@ -83,7 +90,7 @@ describe('routePaddleTour', () => {
|
||||
[false, false],
|
||||
]);
|
||||
expect(route.legLengths[1]).toBe(5500);
|
||||
expect(route.distanceMeters).toBeCloseTo(route.legLengths[0]! + 5500);
|
||||
expect(route.distanceMeters).toBeCloseTo(at(route.legLengths, 0) + 5500);
|
||||
expect(route.coordinates[0]).toEqual([A.lat, A.lng]);
|
||||
expect(route.coordinates[route.coordinates.length - 1]).toEqual([C.lat, C.lng]);
|
||||
});
|
||||
@@ -171,7 +178,7 @@ describe('automatic points', () => {
|
||||
expect(pruneAutoPoints(points)).toEqual(points);
|
||||
const moved = points.map((point) => (point.id === 'b' ? { ...point, lat: point.lat + 0.01 } : point));
|
||||
expect(pruneAutoPoints(moved).map((point) => point.id)).toEqual(['a', 'b', 'c']);
|
||||
const shaped = [points[0]!, { id: 's', lat: 49.095, lng: 12.105, shaping: true }, ...points.slice(1)];
|
||||
const shaped = [at(points, 0), { id: 's', lat: 49.095, lng: 12.105, shaping: true }, ...points.slice(1)];
|
||||
expect(pruneAutoPoints(shaped).map((point) => point.id)).toEqual(['a', 's', 'b', 'c']);
|
||||
});
|
||||
|
||||
|
||||
@@ -24,6 +24,12 @@ vi.mock('../useTourPermissions', () => ({
|
||||
|
||||
import { useTourPlanner } from './useTourPlanner';
|
||||
|
||||
/** The value, or a failure saying it is missing instead of a later undefined. */
|
||||
function must<T>(value: T | null | undefined): T {
|
||||
if (value === null || value === undefined) throw new Error('expected a value');
|
||||
return value;
|
||||
}
|
||||
|
||||
const routed = {
|
||||
coordinates: [
|
||||
[48, 11],
|
||||
@@ -393,17 +399,17 @@ describe('useTourPlanner route tools', () => {
|
||||
const [start, end] = result.current.waypoints;
|
||||
let id: string | null = null;
|
||||
act(() => {
|
||||
id = result.current.insertShapingPoint(start!.id, 48.01, 11.005);
|
||||
id = result.current.insertShapingPoint(must(start).id, 48.01, 11.005);
|
||||
});
|
||||
expect(result.current.waypoints.map((point) => !!point.shaping)).toEqual([false, true, false]);
|
||||
expect(result.current.waypoints[1]?.id).toBe(id);
|
||||
act(() => {
|
||||
expect(result.current.insertShapingPoint(end!.id, 48.03, 11.03)).toBeNull();
|
||||
expect(result.current.insertShapingPoint(start!.id, Number.NaN, 11)).toBeNull();
|
||||
expect(result.current.insertShapingPoint(must(end).id, 48.03, 11.03)).toBeNull();
|
||||
expect(result.current.insertShapingPoint(must(start).id, Number.NaN, 11)).toBeNull();
|
||||
});
|
||||
act(() => result.current.setWaypointShaping(id!, false));
|
||||
act(() => result.current.setWaypointShaping(must(id), false));
|
||||
expect(result.current.waypoints[1]).not.toHaveProperty('shaping');
|
||||
act(() => result.current.setWaypointShaping(start!.id, true));
|
||||
act(() => result.current.setWaypointShaping(must(start).id, true));
|
||||
expect(result.current.waypoints[0]).not.toHaveProperty('shaping');
|
||||
// One undo takes back one change.
|
||||
act(() => result.current.undo());
|
||||
@@ -425,11 +431,11 @@ describe('useTourPlanner route tools', () => {
|
||||
await settle();
|
||||
expect(paddlePlan).toHaveBeenCalledTimes(1);
|
||||
const [start, end] = result.current.waypoints;
|
||||
act(() => result.current.recomputeLeg(start!.id));
|
||||
act(() => result.current.recomputeLeg(must(start).id));
|
||||
expect(paddleForget).toHaveBeenCalledWith(31, start, end, { boat: 'kayak', lakeStyle: 'direct' });
|
||||
await settle();
|
||||
expect(paddlePlan).toHaveBeenCalledTimes(2);
|
||||
act(() => result.current.recomputeLeg(end!.id));
|
||||
act(() => result.current.recomputeLeg(must(end).id));
|
||||
expect(paddleForget).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -502,7 +508,9 @@ describe('useTourPlanner route tools', () => {
|
||||
await settle();
|
||||
await settle();
|
||||
const end = result.current.waypoints[result.current.waypoints.length - 1];
|
||||
act(() => result.current.setWaypointPosition(end.id, 48.2, 11));
|
||||
act(() => {
|
||||
void result.current.setWaypointPosition(end.id, 48.2, 11);
|
||||
});
|
||||
await settle();
|
||||
expect(result.current.waypoints.filter((point) => point.auto).every((point) => point.auto?.to.lat === 48.2)).toBe(
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user