Files
TREK/client/src/components/Planner/transitDisplay.test.tsx
T
Maurice 67b65a7647 fix(transit): keep stop names readable beside long route names
Line badges could take the width of a transit row and squeeze its stops. Bound badge width across the itinerary views, wrap full labels in details, and keep compact summaries within their container.

Closes #3287
2026-12-01 11:11:53 +01:00

75 lines
3.2 KiB
TypeScript

// FE-PLANNER-TRANSITDISPLAY-001 to FE-PLANNER-TRANSITDISPLAY-005
import { describe, expect, it } from 'vitest';
import { render, screen } from '../../../tests/helpers/render';
import type { TransitLegDisplay } from './transitDisplay';
import { TransitItineraryInline, TransitLegChips, TransitWalkDivider } from './transitDisplay';
const t = (key: string, params?: Record<string, string | number>) =>
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-004: a long line name leaves room for both stops', () => {
const line = 'Skybus - Melbourne Airport - Melbourne City';
const from = 'Skybus Coach Terminal/Spencer St';
const to = 'Melbourne (Tullamarine) Airport';
render(<TransitItineraryInline legs={[{ ...ride, line, from: { name: from }, to: { name: to } }]} t={t} />);
const label = screen.getByText(line);
expect(label.parentElement?.style.maxInlineSize).toBe('40%');
expect(label).toHaveClass('[overflow-wrap:anywhere]');
expect(label).not.toHaveClass('truncate');
expect(label).toHaveAttribute('title', line);
expect(screen.getByText(from)).toBeInTheDocument();
expect(screen.getByText(to)).toBeInTheDocument();
});
it('FE-PLANNER-TRANSITDISPLAY-001: a ride shows both stop names in full', () => {
render(<TransitItineraryInline legs={[ride]} t={t} />);
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(<TransitItineraryInline legs={[ride, { ...ride, to: { name: 'Oxford' } }]} t={t} />);
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(<TransitWalkDivider leg={walk} t={t} size="sm" />);
const text = screen.getByText(/transit\.walkTo:Reading station, Station Approach/);
expect(clipsToOneLine(text)).toBe(false);
});
});
describe('TransitLegChips', () => {
it('FE-PLANNER-TRANSITDISPLAY-005: a long badge fits within the chip row', () => {
const line = 'Skybus Melbourne Airport Express';
const { container } = render(<TransitLegChips legs={[{ ...ride, line }]} t={t} />);
expect(container.firstElementChild).toHaveStyle({ minInlineSize: '0px', maxInlineSize: '100%' });
const label = screen.getByText(line);
expect(label).toHaveClass('truncate');
expect(label).toHaveAttribute('title', line);
});
});