mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
fix(tours): list a kept tour with its type's marks, pace and stages
The collection copy keeps the winter, run, ski, bike and stage columns, but its list item only carried the older fields, so a kept ski track lost its discipline mark, a snowshoe hike its winter mark, a run its pace and a multi-day tour its stage count. The item now carries them, and a kept tour's card shows the pace and the stages beside its measures.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import type { CollectionTourItem } from '@trek/shared';
|
||||
import { AlertTriangle, CopyPlus, Route, Trash2, Waypoints, WifiOff } from 'lucide-react';
|
||||
import { AlertTriangle, CopyPlus, Gauge, Moon, Route, Trash2, Waypoints, WifiOff } from 'lucide-react';
|
||||
import { useTranslation } from '../../../i18n';
|
||||
import { WhiteBadge } from '../../Planner/planParts';
|
||||
import ConfirmDialog from '../../shared/ConfirmDialog';
|
||||
import { fs } from '../../shared/DialogShell';
|
||||
import { Tooltip } from '../../shared/Tooltip';
|
||||
import { TourMeasurePills } from '../library/tourPreviewParts';
|
||||
import { runPaceText } from '../run/runPaceText';
|
||||
import { CardAction, TourGradeTile, TourNotice } from '../tourParts';
|
||||
import { CollectionTourTakeOverDialog } from './CollectionTourTakeOverDialog';
|
||||
import { useCollectionTourTakeOver } from './useCollectionTourTakeOver';
|
||||
@@ -17,6 +18,33 @@ function sourceText(tour: CollectionTourItem, t: (key: string, params?: Record<s
|
||||
return tour.saved_by ? `${source}. ${t('tours.collection.keptBy', { name: tour.saved_by })}` : source;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the trip's list shows of a kept tour beyond its measures: a run's pace
|
||||
* and a multi-day tour's stages, each a badge whose tooltip names it.
|
||||
*/
|
||||
function KeptTourTypeBadges({ tour }: { tour: CollectionTourItem }) {
|
||||
const { t } = useTranslation();
|
||||
const pace = runPaceText(tour, t);
|
||||
const stages = tour.stage_count ? t('tours.stages.count', { count: tour.stage_count }) : null;
|
||||
const icon = 'flex-none text-content-faint';
|
||||
return (
|
||||
<>
|
||||
{pace && (
|
||||
<Tooltip label={t('tours.run.pace')}>
|
||||
<span className="inline-flex" data-testid="kept-tour-pace" aria-label={`${t('tours.run.pace')}: ${pace}`}>
|
||||
<WhiteBadge icon={<Gauge size={10} strokeWidth={2.2} className={icon} />}>{pace}</WhiteBadge>
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
{stages && (
|
||||
<span className="inline-flex" data-testid="kept-tour-stages">
|
||||
<WhiteBadge icon={<Moon size={10} strokeWidth={2.2} className={icon} />}>{stages}</WhiteBadge>
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* One kept tour as a card: its grade tile with where it came from, its name
|
||||
* and type, its measures and waypoints as badges, the trip it was saved from,
|
||||
@@ -66,6 +94,7 @@ function KeptTourCard({
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
<TourMeasurePills tour={tour} testPrefix="kept-tour" />
|
||||
<KeptTourTypeBadges tour={tour} />
|
||||
{tour.waypoint_count > 0 && (
|
||||
<Tooltip label={t('tours.collection.points', { count: tour.waypoint_count })}>
|
||||
<span className="inline-flex" aria-label={t('tours.collection.points', { count: tour.waypoint_count })}>
|
||||
|
||||
@@ -17,7 +17,7 @@ import { TourSaveToCollectionBarButton, TourSaveToCollectionButton } from './Tou
|
||||
import { useCollectionTourTakeOver } from './useCollectionTourTakeOver';
|
||||
import { useSaveTourToCollection } from './useSaveTourToCollection';
|
||||
|
||||
// FE-COLLECTION-TOURS-001 to FE-COLLECTION-TOURS-014
|
||||
// FE-COLLECTION-TOURS-001 to FE-COLLECTION-TOURS-015
|
||||
|
||||
vi.mock('../../Map/MapViewAuto', () => ({
|
||||
MapViewAuto: ({ route }: { route: Array<Array<[number, number]>> }) => (
|
||||
@@ -366,6 +366,29 @@ describe('CollectionToursSection', () => {
|
||||
await waitFor(() => expect(screen.queryByTestId('collection-tours')).toBeNull());
|
||||
});
|
||||
|
||||
it('FE-COLLECTION-TOURS-015: a kept tour looks as it did in its trip list: winter mark, run pace and stages', async () => {
|
||||
vi.spyOn(collectionToursRepo, 'list').mockResolvedValue({
|
||||
tours: [
|
||||
kept({ id: 5, winter_activity: 'snowshoe', stage_count: 3 }),
|
||||
kept({
|
||||
id: 6,
|
||||
tour_type: 'run',
|
||||
max_hiking_difficulty: null,
|
||||
run_profile: 'trail',
|
||||
run_pace_seconds_per_km: 360,
|
||||
}),
|
||||
],
|
||||
});
|
||||
render(<CollectionToursSection collectionId={3} canRemove={false} />);
|
||||
const hike = await screen.findByTestId('kept-tour-5');
|
||||
expect(within(hike).getByTestId('tour-winter-mark')).toBeInTheDocument();
|
||||
expect(within(hike).getByTestId('kept-tour-stages')).toHaveTextContent('3 stages');
|
||||
expect(within(hike).queryByTestId('kept-tour-pace')).toBeNull();
|
||||
const run = screen.getByTestId('kept-tour-6');
|
||||
expect(within(run).getByTestId('kept-tour-pace')).toHaveTextContent('6:00');
|
||||
expect(within(run).queryByTestId('kept-tour-stages')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-COLLECTION-TOURS-013: a viewer sees no remove, a failed read says so, and the Tours addon off shows nothing', async () => {
|
||||
const list = vi.spyOn(collectionToursRepo, 'list').mockRejectedValueOnce(new Error('500'));
|
||||
list.mockResolvedValue({ tours: [kept()] });
|
||||
|
||||
Reference in New Issue
Block a user