mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
78366a9024
A ride sends its full line with heights and every horse route section's own line besides, about fifty bytes a point, so a ride along a few thousand points of bridleway hit the API's 100kb body ceiling and the save failed with a 413. Creating and editing a tour are now measured against TOUR_WRITE_MAX_BYTES (2 MB), like the book and list file routes; every other route, the tour copy among them, keeps 100kb. The horse routes kept in memory are now bounded by section points as well as by count (64 answers, 500k points), so panning a dense map can no longer grow the server by hundreds of megabytes. A search that found no connection can be asked again on the view whose routes are shown, and a ride with a recorded time shows the horseshoe beside its riding time instead of footprints.
228 lines
9.9 KiB
TypeScript
228 lines
9.9 KiB
TypeScript
import type { TourListItem } from '@trek/shared';
|
|
import { Bike, Footprints, Mountain, Route } from 'lucide-react';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { paddleBench } from '../../../tests/helpers/paddleCheck';
|
|
import { fireEvent, render, screen } from '../../../tests/helpers/render';
|
|
import { useTourVisitStore } from '../../store/tourVisitStore';
|
|
import TourDayRowFacts, { TourDayRowIcon, TourDayRowPills } from './TourDayRowFacts';
|
|
import { tourDayRowIcon } from './tourDayRowIcon';
|
|
|
|
const tour: TourListItem = {
|
|
place_id: 42,
|
|
name: 'Ridge',
|
|
tour_type: 'hike',
|
|
distance: 4,
|
|
elevation_gain: 100,
|
|
elevation_loss: 80,
|
|
duration: 53,
|
|
break_additional_minutes: 10,
|
|
planned_duration_minutes: null,
|
|
difficulty: null,
|
|
wanderer_ref: null,
|
|
match_confidence: 1,
|
|
max_hiking_difficulty: 2,
|
|
planned: true,
|
|
caution: false,
|
|
};
|
|
|
|
describe('RC-01 Tour day-row facts', () => {
|
|
it('selects controlled type icons without enabling any types', () => {
|
|
expect(tourDayRowIcon('hike')).toBe(Mountain);
|
|
expect(tourDayRowIcon('bike')).toBe(Bike);
|
|
expect(tourDayRowIcon('walk')).toBe(Footprints);
|
|
expect(tourDayRowIcon('unknown')).toBe(Route);
|
|
render(<TourDayRowIcon type="hike" />);
|
|
expect(screen.getByTestId('plan-tour-icon').querySelector('.lucide-mountain')).toBeTruthy();
|
|
});
|
|
|
|
it('HOR-01: a ride with a recorded time shows the horseshoe beside its riding time', () => {
|
|
render(<TourDayRowFacts tour={{ ...tour, tour_type: 'horse', max_hiking_difficulty: null }} />);
|
|
const time = screen.getByTestId('trip-plan-tour-walking-time');
|
|
expect(time.getAttribute('aria-label')).toMatch(/^Riding time/);
|
|
expect(time.querySelector('.lucide-horseshoe')).toBeTruthy();
|
|
expect(time.querySelector('.lucide-footprints')).toBeNull();
|
|
});
|
|
|
|
it.each([false, true])('renders compact facts with accessible meaning (mobile=%s)', (mobile) => {
|
|
render(<TourDayRowFacts tour={tour} mobile={mobile} />);
|
|
expect(screen.getByTestId('plan-tour-distance')).toHaveTextContent('4');
|
|
expect(screen.getByTestId('plan-tour-ascent')).toHaveTextContent('100');
|
|
expect(screen.getByTestId('trip-plan-tour-walking-time')).toHaveAccessibleName('Walking time: 53 min');
|
|
expect(screen.getByTestId('trip-plan-tour-breaks')).toHaveAccessibleName('Breaks / additional time: 10 min');
|
|
expect(screen.getByTestId('trip-plan-tour-planned-duration')).toHaveTextContent('1 h 3 min');
|
|
expect(screen.queryByText('80 m')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it.each([null, 0])('omits missing metrics and empty breaks (%s)', (breaks) => {
|
|
render(
|
|
<TourDayRowFacts tour={{ ...tour, distance: null, elevation_gain: null, break_additional_minutes: breaks }} />
|
|
);
|
|
expect(screen.queryByTestId('plan-tour-distance')).not.toBeInTheDocument();
|
|
expect(screen.queryByTestId('plan-tour-ascent')).not.toBeInTheDocument();
|
|
expect(screen.queryByTestId('trip-plan-tour-breaks')).not.toBeInTheDocument();
|
|
expect(screen.getByTestId('trip-plan-tour-planned-duration')).toHaveTextContent('53 min');
|
|
});
|
|
|
|
it('supports hover, keyboard focus and touch help without opening the containing row', async () => {
|
|
const openRow = vi.fn();
|
|
render(
|
|
<div onClick={openRow}>
|
|
<TourDayRowFacts tour={tour} />
|
|
</div>
|
|
);
|
|
const walking = screen.getByTestId('trip-plan-tour-walking-time');
|
|
fireEvent.mouseEnter(walking);
|
|
expect(await screen.findByRole('tooltip')).toHaveTextContent('Walking time: 53 min');
|
|
fireEvent.mouseLeave(walking);
|
|
const matches = vi.spyOn(walking, 'matches').mockImplementation((selector) => selector === ':focus-visible');
|
|
fireEvent.focus(walking);
|
|
expect(await screen.findByRole('tooltip')).toHaveTextContent('Walking time: 53 min');
|
|
fireEvent.blur(walking);
|
|
matches.mockRestore();
|
|
fireEvent.click(walking);
|
|
expect(screen.getByRole('note')).toHaveTextContent('Walking time: 53 min');
|
|
expect(openRow).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('PAD-09 the check bench on a tour row', () => {
|
|
const kayak: TourListItem = { ...tour, tour_type: 'kayak', paddle_check: paddleBench() };
|
|
|
|
it('PCD-001: a kayak tour with a bench shows one checklist pill, its tooltip saying it is no clearance', () => {
|
|
render(<TourDayRowPills tour={kayak} />);
|
|
const pill = screen.getByTestId('plan-tour-paddle-check');
|
|
expect(pill).toHaveTextContent('1 open');
|
|
expect(pill.getAttribute('aria-label')).toContain('A checklist is no safety or legal clearance.');
|
|
});
|
|
|
|
it('PCD-002: an area without obstacle data shows no pill at all, never a count', () => {
|
|
render(<TourDayRowPills tour={{ ...kayak, paddle_check: paddleBench({ data: 'none', open: 3 }) }} />);
|
|
expect(screen.queryByTestId('plan-tour-paddle-check')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('PCD-002b: data that could not be read still shows, without a count', () => {
|
|
render(<TourDayRowPills tour={{ ...kayak, paddle_check: paddleBench({ data: 'unavailable', open: 3 }) }} />);
|
|
expect(screen.getByTestId('plan-tour-paddle-check')).not.toHaveTextContent('3');
|
|
});
|
|
|
|
it.each([false, true])('PCD-003: the day plan facts name the bench as one more fact (mobile=%s)', (mobile) => {
|
|
render(<TourDayRowFacts tour={kayak} mobile={mobile} />);
|
|
expect(screen.getByTestId('plan-tour-paddle-check')).toHaveAccessibleName('Checklist: 1 open');
|
|
});
|
|
|
|
const without: Array<[string, TourListItem]> = [
|
|
['a hike with a bench', { ...tour, paddle_check: paddleBench() }],
|
|
['a kayak tour without a bench', { ...tour, tour_type: 'kayak' }],
|
|
['a kayak tour whose bench is null', { ...tour, tour_type: 'kayak', paddle_check: null }],
|
|
];
|
|
it.each(without)('PCD-004: %s shows no checklist pill and no checklist fact', (_case, item) => {
|
|
render(
|
|
<>
|
|
<TourDayRowPills tour={item} />
|
|
<TourDayRowFacts tour={item} />
|
|
</>
|
|
);
|
|
expect(screen.queryByTestId('plan-tour-paddle-check')).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("CW-02 a city walk's time on its day row", () => {
|
|
const walk: TourListItem = {
|
|
...tour,
|
|
tour_type: 'walk',
|
|
duration: 45,
|
|
break_additional_minutes: 15,
|
|
max_hiking_difficulty: null,
|
|
station_count: 3,
|
|
station_stay_minutes: 120,
|
|
station_stays_unknown: 0,
|
|
};
|
|
|
|
it('shows the walking time and the stays as the planned total, its breaks left out', () => {
|
|
render(<TourDayRowPills tour={walk} />);
|
|
const time = screen.getByTestId('trip-plan-tour-time');
|
|
expect(time).toHaveTextContent('2 h 45 min');
|
|
expect(time).toHaveAccessibleName('Walking: 45 min, Stays: 2 h, Planned total duration: 2 h 45 min');
|
|
});
|
|
|
|
it('says the total is at least what is known while a stay is not entered', () => {
|
|
render(<TourDayRowPills tour={{ ...walk, station_stay_minutes: 90, station_stays_unknown: 1 }} />);
|
|
const time = screen.getByTestId('trip-plan-tour-time');
|
|
expect(time).toHaveTextContent('≥ 2 h 15 min');
|
|
expect(time).toHaveAccessibleName(
|
|
'Walking: 45 min, Stays: at least 1 h 30 min, Planned total duration: at least 2 h 15 min'
|
|
);
|
|
});
|
|
|
|
it('shows the same total among the facts of a phone row, and no breaks', () => {
|
|
render(<TourDayRowFacts tour={{ ...walk, station_stay_minutes: 90, station_stays_unknown: 1 }} mobile />);
|
|
expect(screen.getByTestId('trip-plan-tour-planned-duration')).toHaveTextContent('≥ 2 h 15 min');
|
|
expect(screen.getByTestId('trip-plan-tour-walking-time')).toHaveAccessibleName('Walking: 45 min');
|
|
expect(screen.queryByTestId('trip-plan-tour-breaks')).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("CW-03 a city walk's progress among the facts of a day row", () => {
|
|
const walk: TourListItem = { ...tour, tour_type: 'walk', max_hiking_difficulty: null, station_count: 5 };
|
|
|
|
beforeEach(() =>
|
|
useTourVisitStore.setState({
|
|
tripId: '4',
|
|
byAssignment: { 9: { 'stop-01': 'visited', 'stop-02': 'skipped' } },
|
|
})
|
|
);
|
|
|
|
it.each([false, true])('shows the stops visited on that day, a tap naming them whole (mobile=%s)', (mobile) => {
|
|
const openRow = vi.fn();
|
|
render(
|
|
<div onClick={openRow}>
|
|
<TourDayRowFacts tour={walk} assignmentId={9} mobile={mobile} />
|
|
</div>
|
|
);
|
|
const progress = screen.getByTestId('plan-walk-progress');
|
|
expect(progress).toHaveTextContent('1/5');
|
|
expect(progress).toHaveAccessibleName('1 of 5 visited');
|
|
fireEvent.click(progress);
|
|
expect(screen.getByRole('note')).toHaveTextContent('1 of 5 visited');
|
|
expect(openRow).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('shows none without a day, or before a stop of that day is marked', () => {
|
|
render(
|
|
<>
|
|
<TourDayRowFacts tour={walk} mobile />
|
|
<TourDayRowFacts tour={walk} assignmentId={10} mobile />
|
|
</>
|
|
);
|
|
expect(screen.queryByTestId('plan-walk-progress')).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('the compact facts of a tour list row', () => {
|
|
const testIds = () =>
|
|
[...document.querySelectorAll('[data-testid^="plan-tour"], [data-testid="trip-plan-tour-time"]')].map((el) =>
|
|
el.getAttribute('data-testid')
|
|
);
|
|
const timed = { ...tour, distance: 4.2, elevation_gain: 478, planned_duration_minutes: 50 };
|
|
|
|
it('PCD-005: a hike keeps time, distance and climbing, in that order', () => {
|
|
render(<TourDayRowPills tour={timed} compact />);
|
|
expect(testIds()).toEqual(['trip-plan-tour-time', 'plan-tour-distance', 'plan-tour-ascent']);
|
|
});
|
|
|
|
it('PCD-006: a paddle tour puts its check bench second and leaves out the climbing', () => {
|
|
render(<TourDayRowPills tour={{ ...timed, tour_type: 'kayak', paddle_check: paddleBench() }} compact />);
|
|
expect(testIds()).toEqual(['trip-plan-tour-time', 'plan-tour-paddle-check', 'plan-tour-distance']);
|
|
});
|
|
|
|
it('PCD-007: the day plan still shows every fact', () => {
|
|
render(<TourDayRowPills tour={{ ...timed, tour_type: 'kayak', paddle_check: paddleBench() }} />);
|
|
expect(testIds()).toEqual([
|
|
'trip-plan-tour-time',
|
|
'plan-tour-distance',
|
|
'plan-tour-ascent',
|
|
'plan-tour-paddle-check',
|
|
]);
|
|
});
|
|
});
|