diff --git a/client/src/components/Planner/transitDisplay.test.tsx b/client/src/components/Planner/transitDisplay.test.tsx new file mode 100644 index 000000000..0904b1ac6 --- /dev/null +++ b/client/src/components/Planner/transitDisplay.test.tsx @@ -0,0 +1,47 @@ +// FE-PLANNER-TRANSITDISPLAY-001 to FE-PLANNER-TRANSITDISPLAY-003 +import { describe, expect, it } from 'vitest'; +import { render, screen } from '../../../tests/helpers/render'; +import type { TransitLegDisplay } from './transitDisplay'; +import { TransitItineraryInline, TransitWalkDivider } from './transitDisplay'; + +const t = (key: string, params?: Record) => + params ? `${key}:${Object.values(params).join(',')}` : key; + +const ride: TransitLegDisplay = { + mode: 'RAIL', + line: 'XC', + duration: 1260, + from: { name: 'Basingstoke', time: '12:48' }, + to: { name: 'Reading', time: '13:09' }, +}; +const walk: TransitLegDisplay = { mode: 'WALK', duration: 240, to: { name: 'Reading station, Station Approach' } }; + +/** Whether a rendered element clips its text to one line. */ +function clipsToOneLine(el: HTMLElement): boolean { + return el.style.whiteSpace === 'nowrap' || el.style.textOverflow === 'ellipsis'; +} + +describe('TransitItineraryInline (#3139)', () => { + it('FE-PLANNER-TRANSITDISPLAY-001: a ride shows both stop names in full', () => { + render(); + for (const name of ['Basingstoke', 'Reading']) { + const el = screen.getByText(name); + expect(clipsToOneLine(el)).toBe(false); + expect(el.style.overflowWrap).toBe('anywhere'); + } + }); + + it('FE-PLANNER-TRANSITDISPLAY-002: a ride shows its arrival time under its departure', () => { + render(); + expect(screen.getByText('13:09')).toBeInTheDocument(); + expect(screen.getAllByText('12:48')).toHaveLength(2); + }); +}); + +describe('TransitWalkDivider (#3139)', () => { + it('FE-PLANNER-TRANSITDISPLAY-003: the walk target wraps instead of being cut off', () => { + render(); + const text = screen.getByText(/transit\.walkTo:Reading station, Station Approach/); + expect(clipsToOneLine(text)).toBe(false); + }); +}); diff --git a/client/src/components/Planner/transitDisplay.tsx b/client/src/components/Planner/transitDisplay.tsx index 7ed222002..5ab296711 100644 --- a/client/src/components/Planner/transitDisplay.tsx +++ b/client/src/components/Planner/transitDisplay.tsx @@ -41,14 +41,14 @@ export function TransitWalkDivider({ leg, t, size = 'md' }: { background: `linear-gradient(to ${dir}, var(--text-faint), transparent)`, opacity: 0.55, }) - // On phones the minutes lead so a long stop name only ever clips the name. + // On phones the minutes lead, so they stay on the first line when a long stop name wraps. const text = isMobile ? `${mins ? `${t('transit.min', { count: mins })} · ` : ''}${t('transit.walkTo', { name: leg.to?.name || '' })}` : `${t('transit.walkTo', { name: leg.to?.name || '' })}${mins ? ` · ${t('transit.min', { count: mins })}` : ''}` return (
- + {text} @@ -72,8 +72,10 @@ export function TransitItineraryInline({ legs, t }: { const mins = leg.duration ? Math.round(leg.duration / 60) : null return (
- - {leg.from?.time || ''} + {/* Departure beside the stops, arrival under it (#3139). */} + + {leg.from?.time || ''} + {leg.to?.time && {leg.to.time}}
-
- {leg.from?.name} + {/* The folded-out itinerary is where a journey is read in full: stop names wrap (#3139). */} +
+ {leg.from?.name} - {leg.to?.name} + {leg.to?.name}
{[ diff --git a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx index 392dcc909..0c24d35cb 100644 --- a/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx +++ b/client/src/mobile/screens/trip/sheets/MTransportSheet.tsx @@ -238,6 +238,7 @@ export default function MTransportSheet({ planner, shell }: MTripSheetsProps) { icon={} title={{res.title}} sub={subParts.length > 0 ? subParts.join(' · ') : undefined} + subWrap onClose={shell.closeSheet} closeLabel={t('common.close')} />