// 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) => 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(); 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(); 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); }); }); describe('TransitLegChips', () => { it('FE-PLANNER-TRANSITDISPLAY-005: a long badge fits within the chip row', () => { const line = 'Skybus Melbourne Airport Express'; const { container } = render(); expect(container.firstElementChild).toHaveStyle({ minInlineSize: '0px', maxInlineSize: '100%' }); const label = screen.getByText(line); expect(label).toHaveClass('truncate'); expect(label).toHaveAttribute('title', line); }); });