fix(client): lint, theme and size ratchets of the quick-win round, and the tests that followed the features

New warnings fixed at their source (refs written in effects, typed tile
options, no stray imports, smaller functions and components), the payer and
split heads hold their switch instead of letting it overhang, the baselines
lowered where the round removed warnings, and the tests updated to the
solo trip, the shares view and the revisit status.
This commit is contained in:
Maurice
2026-11-13 12:40:17 +01:00
parent 75aeba29ed
commit c2ba78253d
33 changed files with 278 additions and 194 deletions
@@ -418,12 +418,16 @@ describe('TourDetailDialog', () => {
fireEvent.click(screen.getByRole('button', { name: 'Open the route in a map app' }))
const menu = screen.getByRole('menu')
// Only the apps that take a route: Waze and geo: lead to the start, which Navigation already does.
expect(Array.from(menu.querySelectorAll('[role="menuitem"]')).map(item => item.textContent)).toEqual(['Google Maps', 'CoMaps'])
// Only the apps that follow a whole route: Waze and geo: lead to the start, which Navigation
// already does, and CoMaps would get the stops between as unrouted pins.
const names = Array.from(menu.querySelectorAll('[role="menuitem"]')).map(item => item.textContent)
expect(names).toContain('Google Maps')
expect(names).not.toContain('CoMaps')
expect(names).not.toContain('Waze')
fireEvent.click(screen.getByRole('menuitem', { name: 'CoMaps' }))
// Three points along the line go as pins; the start carries the tour's name.
expect(open).toHaveBeenCalledWith(expect.stringContaining('https://comaps.at/map?v=1&ll=48,11&n=Ridge%20walk'), '_blank', 'noopener,noreferrer')
fireEvent.click(screen.getByRole('menuitem', { name: 'Google Maps' }))
// The ride goes by bike, with the stops along the line between its ends.
expect(open).toHaveBeenCalledWith(expect.stringContaining('&travelmode=bicycling'), '_blank', 'noopener,noreferrer')
})
it('#2812: a paddle tour is not handed to a map app, which would route it by road', () => {
@@ -15,7 +15,6 @@ import {
FileImage,
FileText,
Loader2,
MapPinned,
Minus,
Navigation,
Pencil,
@@ -49,6 +48,7 @@ import TrackColorPicker from '../shared/TrackColorPicker';
import { markdownLinkComponents } from '../shared/markdownLink';
import { TourDayRowAvatar } from './TourDayRowFacts';
import { TourGpxExportButton } from './TourGpxExportButton';
import { TourRouteAppsButton } from './TourRouteAppsButton';
import { TourTypeSections } from './TourTypeSections';
import TourActivitySection from './activity/TourActivitySection';
import type { PlanValues } from './activity/planComparison';
@@ -74,7 +74,6 @@ import {
tourWebsitePresentation,
type TourPlannedTimes,
} from './tourPresentation';
import { tourRouteTargets } from './tourRouteApps';
import { tourShareFactsOf } from './tourShareText';
import { useTourDayAssignment } from './useTourDayAssignment';
import { useTourPermissions, type TourPermissionProps } from './useTourPermissions';
@@ -542,8 +541,6 @@ export default function TourDetailDialog({
const [colorOpen, setColorOpen] = useState(false);
const [navigationOpen, setNavigationOpen] = useState(false);
const navigationAnchorRef = useRef<HTMLSpanElement>(null);
const [routeAppsOpen, setRouteAppsOpen] = useState(false);
const routeAppsAnchorRef = useRef<HTMLSpanElement>(null);
useDesktopEscape(desktopNonModal, onClose, desktopFocusReturnTarget);
const heightsHidden = heightsUnknown(tour);
@@ -559,11 +556,6 @@ export default function TourDetailDialog({
const navigationTargets = getNavigationTargets(place);
const navigationLabel =
navigationTargets.length === 1 ? navigationTargetLabel(navigationTargets[0], t) : t('inspector.navigation');
// #2812: the whole route, not only the way to its start, in the apps that follow one.
const routeTargets = useMemo(
() => (analysis ? tourRouteTargets(tour.tour_type, analysis.routeCoordinates, place.name) : []),
[analysis, tour.tour_type, place.name]
);
const description = tour.description !== undefined ? tour.description : place.description;
const website = tourWebsitePresentation(tour.website !== undefined ? tour.website : place.website);
const times = tourPlannedTimes(tour);
@@ -672,31 +664,7 @@ export default function TourDetailDialog({
)}
</>
)}
{routeTargets.length > 0 && (
<>
<Tooltip label={t('tours.detail.openRoute')}>
<span ref={routeAppsAnchorRef} className="inline-flex">
<DialogButton
onClick={() => setRouteAppsOpen((open) => !open)}
aria-label={t('tours.detail.openRoute')}
aria-haspopup="menu"
aria-expanded={routeAppsOpen}
data-testid="tour-route-apps"
icon={<MapPinned size={14} strokeWidth={2} />}
>
<span className="max-sm:hidden">{t('tours.detail.mapsShort')}</span>
</DialogButton>
</span>
</Tooltip>
{routeAppsOpen && (
<NavigationMenu
targets={routeTargets}
anchor={routeAppsAnchorRef.current}
onClose={() => setRouteAppsOpen(false)}
/>
)}
</>
)}
<TourRouteAppsButton type={tour.tour_type} line={analysis?.routeCoordinates} name={place.name} />
{website && (
<Tooltip label={website.domain}>
<span className="inline-flex">
@@ -0,0 +1,49 @@
import type { TourTypeKey } from '@trek/shared';
import { MapPinned } from 'lucide-react';
import { useMemo, useState } from 'react';
import { useTranslation } from '../../i18n';
import { DialogButton } from '../shared/DialogShell';
import { NavigationMenu } from '../shared/NavigationMenu';
import { Tooltip } from '../shared/Tooltip';
import { tourRouteTargets } from './tourRouteApps';
/**
* The tour's whole route, not only the way to its start, in the map apps that
* follow one (#2812). Nothing when no app can take the tour.
*/
export function TourRouteAppsButton({
type,
line,
name,
}: {
type: TourTypeKey;
line: ReadonlyArray<readonly [number, number]> | undefined;
name: string;
}) {
const { t } = useTranslation();
const targets = useMemo(() => (line ? tourRouteTargets(type, line, name) : []), [type, line, name]);
const [open, setOpen] = useState(false);
// State, not a ref: the menu reads its anchor while rendering.
const [anchor, setAnchor] = useState<HTMLSpanElement | null>(null);
if (targets.length === 0) return null;
return (
<>
<Tooltip label={t('tours.detail.openRoute')}>
<span ref={setAnchor} className="inline-flex">
<DialogButton
onClick={() => setOpen((o) => !o)}
aria-label={t('tours.detail.openRoute')}
aria-haspopup="menu"
aria-expanded={open}
data-testid="tour-route-apps"
icon={<MapPinned size={14} strokeWidth={2} />}
>
<span className="max-sm:hidden">{t('tours.detail.mapsShort')}</span>
</DialogButton>
</span>
</Tooltip>
{open && <NavigationMenu targets={targets} anchor={anchor} onClose={() => setOpen(false)} />}
</>
);
}
@@ -37,7 +37,9 @@ describe('tourRouteApps (#2812)', () => {
it('FE-TOUR-ROUTEAPPS-004: only the apps that take the whole route, with the mode the tour is routed in', () => {
const targets = tourRouteTargets('bike', line(2), 'Ride');
expect(targets.map((target) => target.id)).toEqual(['google', 'comaps']);
// Apple Maps joins them where the device has it (the test browser counts as one).
expect(targets.map((target) => target.id)).toEqual(expect.arrayContaining(['google', 'comaps']));
expect(targets.some((target) => target.id === 'waze' || target.id === 'geo')).toBe(false);
expect(targets.find((target) => target.id === 'comaps')?.url).toContain('type=bicycle');
expect(targets.find((target) => target.id === 'google')?.url).toBe(
'https://www.google.com/maps/dir/?api=1&origin=0,0&destination=0,0.01&travelmode=bicycling'
@@ -46,8 +48,9 @@ describe('tourRouteApps (#2812)', () => {
it('FE-TOUR-ROUTEAPPS-005: a longer tour goes to Google on foot with its stops between, and not to CoMaps', () => {
const targets = tourRouteTargets('hike', line(5), 'Ridge');
expect(targets.map((target) => target.id)).toEqual(['google']);
const url = targets[0].url;
expect(targets.map((target) => target.id)).toContain('google');
expect(targets.map((target) => target.id)).not.toContain('comaps');
const url = targets.find((target) => target.id === 'google')?.url ?? '';
expect(url).toContain('&travelmode=walking');
expect(url).toContain('&waypoints=0%2C0.01%7C0%2C0.02%7C0%2C0.03');
});