The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
import React from 'react'
import { afterEach, describe, it, expect, vi } from 'vitest'
import { render, screen, within, fireEvent } from '@testing-library/react'
import { TranslationProvider } from '../../i18n'
// jsdom reports every element as zero by side, so the panel width that decides whether the
// heading and the two actions keep their words can only be driven from here. Zero is what
// the component reads as "not measured yet", which is also the default below.
const { panelWidth } = vi.hoisted(() => ({ panelWidth: { value: 0 } }))
vi.mock('../../hooks/useElementSize', () => ({
useElementSize: () => ({ ref: () => {}, width: panelWidth.value, height: 0 }),
}))
afterEach(() => { panelWidth.value = 0 })
import RoadtripCorridorPanel from './RoadtripCorridorPanel'
import type { CorridorPoi } from './useCorridorPois'
import type { RoadtripCorridor } from './useRoadtripCorridor'
import type { RoadtripDay, RoadtripRoutes, RoadtripStop } from './useRoadtripRoutes'
const wrap = (ui: React.ReactElement) => render(<TranslationProvider>{ui}</TranslationProvider>)
const stop = (id: number, name: string): RoadtripStop => ({
assignmentId: id,
ownerDayId: 1,
ownerIndex: id - 1,
placeId: id * 10,
name,
lat: 53.5,
lng: 9.9,
time: null,
dwellMinutes: null,
legMode: null,
incomingLegMode: null,
stopType: null,
})
const day = (dayId: number, dayNumber: number): RoadtripDay => ({
dayId,
dayNumber,
date: null,
title: null,
stops: [stop(dayId * 10 + 1, 'Hamburg'), stop(dayId * 10 + 2, 'Berlin')],
legs: [],
schedule: { entries: [], warnings: [] },
legVias: [], driveWarnings: [], dayWarning: null,
// Routed. Searching before the day has a geometry builds the corridor from the
// straight line between the stops, and the routing answer landing a second
// later clears the search mid-flight — so the button waits for this.
geometry: [[53.55, 9.99], [52.52, 13.4]] as [number, number][],
distance: 0,
duration: 0,
})
const routes = (days: RoadtripDay[]): RoadtripRoutes => ({
days,
lines: [], lineDays: [], lineJoins: [],
accessLines: [],
vias: [],
segments: [],
totalDistance: 0,
totalDuration: 0,
totalStops: days.length * 2,
quietDays: [],
loading: false,
})
function poi(over: Partial<CorridorPoi> & { osm_id: string; name: string }): CorridorPoi {
return {
lat: 53.5,
lng: 9.9,
category: 'fuel',
poi_type: 'amenity=fuel',
address: null,
website: null,
phone: null,
opening_hours: null,
cuisine: null,
source: 'openstreetmap',
offRouteKm: 1.2,
alongKm: 40,
...over,
} as CorridorPoi
}
function corridor(over: Partial<RoadtripCorridor> = {}, search: Partial<RoadtripCorridor['search']> = {}): RoadtripCorridor {
const days = over.day ? [over.day] : [day(1, 1)]
const searchState: RoadtripCorridor['search'] = {
results: [],
progress: { done: 0, total: 0 },
loading: false,
capped: false,
failedAreas: 0,
truncatedAreas: 0,
error: false,
spine: [],
search: vi.fn(),
clear: vi.fn(),
...search,
}
return {
dayId: String(days[0].dayId),
setDayId: vi.fn(),
day: days[0],
categories: ['fuel'],
toggleCategory: vi.fn(),
widthKm: 5,
setWidthKm: vi.fn(),
nameFilter: '',
anchors: [],
section: null,
setSection: vi.fn(),
sectionKm: 50,
setSectionKm: vi.fn(),
socketFilter: '',
setSocketFilter: vi.fn(),
minKw: 0,
setMinKw: vi.fn(),
setNameFilter: vi.fn(),
// Same as the hook with an empty filter: everything found is on show.
visible: searchState.results,
insertIndexFor: vi.fn(() => 1),
stopsAlongKm: [0, 100],
clear: vi.fn(),
...over,
search: searchState,
}
}
/**
* The buttons of the "what to look for" card's last row, in order.
*
* By position rather than by label: which half is which is the point of the row, and a
* label is a translation that would make this a test about wording.
*/
const searchRow = (): HTMLButtonElement[] => {
const searchButton = screen.getByRole('button', { name: 'Search' })
return [...(searchButton.parentElement?.querySelectorAll('button') ?? [])] as HTMLButtonElement[]
}
describe('RoadtripCorridorPanel', () => {
it('FE-ROADTRIP-PANEL-036: the day sits beside what is looked for, not in the header, and picking one moves the search', () => {
const c = corridor()
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1), day(2, 2)])} />)
const dayTrigger = screen.getByText('Day 1').closest('button')!
expect(dayTrigger.closest('header, h2')).toBeNull()
// One line: the kinds and the day share the row under "Looking for".
const row = dayTrigger.parentElement!.parentElement!
expect(row.querySelector('[aria-haspopup="listbox"]')).not.toBe(dayTrigger)
expect(row.querySelectorAll('[aria-haspopup="listbox"]')).toHaveLength(2)
fireEvent.click(dayTrigger)
fireEvent.click(screen.getByRole('option', { name: /Day 2/ }))
expect(c.setDayId).toHaveBeenCalledWith('2')
})
it('FE-ROADTRIP-PANEL-037: a trip of one day offers no day to pick', () => {
wrap(<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1)])} />)
expect(screen.queryByText('Day 1')).toBeNull()
})
it('FE-ROADTRIP-PANEL-001: searching is a button, never a side effect of opening the panel', () => {
const c = corridor()
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(c.search.search).not.toHaveBeenCalled()
fireEvent.click(screen.getByRole('button', { name: /search/i }))
expect(c.search.search).toHaveBeenCalledTimes(1)
})
it('FE-ROADTRIP-PANEL-004: a day that has not routed yet cannot be searched along', () => {
// Until the day routes, the corridor is the straight line between the stops,
// so the boxes march across whatever lies between them instead of along the
// roads driven. Worse, the routing answer landing a second later changes the
// line, which clears the search mid-flight and drops every result with no
// error and no explanation. Routing runs one day at a time, about a second
// apart, so on a long trip that window is wide open.
const unrouted = { ...day(1, 1), geometry: [] as [number, number][] }
const c = corridor({ day: unrouted })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([unrouted])} />)
expect(screen.getByRole('button', { name: /search/i })).toBeDisabled()
})
it('FE-ROADTRIP-PANEL-005: nor while the routing is still running', () => {
const c = corridor()
wrap(<RoadtripCorridorPanel corridor={c} routes={{ ...routes([day(1, 1)]), loading: true }} />)
expect(screen.getByRole('button', { name: /search/i })).toBeDisabled()
})
it('FE-ROADTRIP-PANEL-002: nothing selected means nothing to search for', () => {
const c = corridor({ categories: [] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByRole('button', { name: /search/i })).toBeDisabled()
})
it('FE-ROADTRIP-PANEL-003: a day with a single stop has no drive to search along', () => {
const lonely = { ...day(1, 1), stops: [stop(11, 'Hamburg')] }
const c = corridor({ day: lonely })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([lonely])} />)
expect(screen.getByRole('button', { name: /search/i })).toBeDisabled()
})
it('FE-ROADTRIP-PANEL-004: toggling a kind reports which one', () => {
const c = corridor()
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
// Six kinds used to be six pills wrapped over three lines; they are one dropdown now,
// so the options only exist once it is open.
fireEvent.click(screen.getByRole('button', { expanded: false }))
fireEvent.click(screen.getByRole('option', { name: /campsite/i }))
expect(c.toggleCategory).toHaveBeenCalledWith('campsite')
// What is already selected reads as selected rather than only looking different.
expect(screen.getByRole('option', { name: /fuel/i })).toHaveAttribute('aria-selected', 'true')
})
it('FE-ROADTRIP-PANEL-005: the corridor width is a choice, and the current one is marked', () => {
const c = corridor()
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
const five = screen.getByRole('button', { name: '5 km' })
expect(five).toHaveAttribute('aria-pressed', 'true')
fireEvent.click(screen.getByRole('button', { name: '10 km' }))
expect(c.setWidthKm).toHaveBeenCalledWith(10)
})
it('FE-ROADTRIP-PANEL-006: the day picker only appears once there is more than one drive', () => {
const one = corridor()
const { unmount } = wrap(<RoadtripCorridorPanel corridor={one} routes={routes([day(1, 1)])} />)
expect(screen.queryByText('Day 1')).not.toBeInTheDocument()
unmount()
wrap(<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1), day(2, 2)])} />)
expect(screen.getByText('Day 1')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-007: groups the hits by kind and counts each group', () => {
const c = corridor({ categories: ['fuel', 'campsite'] }, {
results: [
poi({ osm_id: 'a', name: 'Aral', alongKm: 10 }),
poi({ osm_id: 'b', name: 'Shell', alongKm: 20 }),
poi({ osm_id: 'c', name: 'Camping Elbe', category: 'campsite', alongKm: 30 }),
],
})
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
// "Fuel" also names an option in the kind picker; the group header is the one that
// folds its list, so it is the button.
const fuelGroup = screen.getAllByText('Fuel').map(el => el.closest('button')).find(Boolean)!
expect(within(fuelGroup).getByText('2 on the way')).toBeInTheDocument()
expect(screen.getByText('Camping Elbe')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-008: each hit says how far off the route and how far along it is', () => {
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral', offRouteKm: 1.2, alongKm: 40 })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
const row = screen.getByText('Aral').closest('li')!
expect(within(row).getByText(/1\.2 km/)).toBeInTheDocument()
expect(within(row).getByText(/40 km/)).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-009: a hit right at the start says so instead of "0 km along"', () => {
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral', alongKm: 0.1 })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByText('Aral').closest('li')!.textContent).not.toContain('0 km along')
})
it('FE-ROADTRIP-PANEL-010: a chain gets its category icon, never its own logo', () => {
// A corridor is mostly chains, and their marks turned a list of petrol stations into
// an advertisement — while a brand with no logo on file fell back to a different
// picture, so no two rows looked alike. The category's icon is also what the rail and
// the map draw for the same stop.
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral', brand_wikidata: 'Q565734' } as Partial<CorridorPoi> & { osm_id: string; name: string })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
const row = screen.getByText('Aral').closest('li')!
expect(row.querySelector('img')).toBeNull()
expect(row.querySelector('svg.lucide-fuel')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-012: adding a hit puts it on the day that was searched', () => {
const onAddPoi = vi.fn()
const c = corridor({}, { results: [poi({ osm_id: 'node:9', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} onAddPoi={onAddPoi} />)
fireEvent.click(screen.getByRole('button', { name: /add/i }))
// Day and position both: a fuel stop belongs where it is driven past, not at the end.
expect(onAddPoi).toHaveBeenCalledWith(expect.objectContaining({ osm_id: 'node:9' }), 1, 1)
})
it('FE-ROADTRIP-PANEL-023: the position offered is the one worked out for that very hit', () => {
const onAddPoi = vi.fn()
const hit = poi({ osm_id: 'node:9', name: 'Aral', alongKm: 120 })
const insertIndexFor = vi.fn(() => 3)
const c = corridor({ insertIndexFor }, { results: [hit] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} onAddPoi={onAddPoi} />)
fireEvent.click(screen.getByRole('button', { name: /add/i }))
expect(insertIndexFor).toHaveBeenCalledWith(hit)
expect(onAddPoi).toHaveBeenCalledWith(expect.objectContaining({ osm_id: 'node:9' }), 1, 3)
})
it('FE-ROADTRIP-PANEL-013: while searching it reports progress rather than sitting still', () => {
panelWidth.value = 320
const c = corridor({}, { loading: true, progress: { done: 3, total: 12 } })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
// The sentence and the share belong to the row of their own, once. The button used
// to restate them, which made the longest label in the panel and was the one being
// cut off; it keeps its word, and the spinner in front of it says the run is on.
const bar = screen.getByRole('progressbar')
expect(bar).toHaveAttribute('aria-valuenow', '25')
expect(bar).toHaveTextContent('Searching 3 of 12')
const [searchButton] = searchRow()
expect(searchButton).toHaveTextContent('Search')
expect(within(searchButton).queryByText(/Searching/)).toBeNull()
expect(searchButton).toBeDisabled()
})
it('FE-ROADTRIP-PANEL-014: a partial answer says which stretches nobody looked at', () => {
const c = corridor({}, { failedAreas: 2, results: [poi({ osm_id: 'a', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
// The difference between "no fuel here" and "nobody looked here".
expect(screen.getByText('2 stretches could not be searched. The place search did not answer.')).toBeInTheDocument()
expect(screen.getByText('Aral')).toBeInTheDocument()
})
it('shows the plugin source and failed providers beside remaining hits', () => {
const c = corridor({}, { failedSources: ['plugin:unavailable'], results: [poi({ osm_id: 'plugin:stations:one', name: 'Plugin Station', pluginId: 'stations' })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByText('Plugin Station')).toBeInTheDocument()
expect(screen.getByText('stations')).toBeInTheDocument()
expect(screen.getByText('Error: plugin:unavailable')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-015: a total outage reads as a failure, not as an empty road', () => {
const c = corridor({}, { error: true, failedAreas: 4 })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByText('The place search is not answering right now.')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-016: a drive longer than the budget admits the tail went unsearched', () => {
const c = corridor({}, { capped: true })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByText('The route is long — only the first stretch was searched.')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-017: a stretch the server cut short is not reported as a fault', () => {
// It used to say so, and it said so on nearly every search of a long day: the ceiling
// is per box and a busy corridor reaches it as a matter of course. That made a
// permanent complaint about a search that had worked, and its advice — narrow the
// corridor — makes the answer smaller rather than better. The warnings that remain
// are the ones about a search that did not happen.
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral' })], truncatedAreas: 2 })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.queryByText(/had more than fits in one answer/)).not.toBeInTheDocument()
expect(screen.getByText('Aral')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-018: the filter appears only once there is something to narrow', () => {
const empty = corridor()
const { unmount } = wrap(<RoadtripCorridorPanel corridor={empty} routes={routes([day(1, 1)])} />)
expect(screen.queryByLabelText('Filter by name')).not.toBeInTheDocument()
unmount()
const found = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={found} routes={routes([day(1, 1)])} />)
expect(screen.getByLabelText('Filter by name')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-019: typing in the filter reports the term rather than searching again', () => {
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
fireEvent.change(screen.getByLabelText('Filter by name'), { target: { value: 'shell' } })
expect(c.setNameFilter).toHaveBeenCalledWith('shell')
// The filter must never trigger another round of Overpass requests.
expect(c.search.search).not.toHaveBeenCalled()
})
it('FE-ROADTRIP-PANEL-020: the list shows what is visible, and counts it against the whole', () => {
const hits = [poi({ osm_id: 'a', name: 'Aral' }), poi({ osm_id: 'b', name: 'Shell' })]
const c = corridor({ nameFilter: 'shell', visible: [hits[1]] }, { results: hits })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByText('Shell')).toBeInTheDocument()
expect(screen.queryByText('Aral')).not.toBeInTheDocument()
expect(screen.getByText('1 of 2 on the way')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-021: filtering everything away says so instead of looking unsearched', () => {
const c = corridor(
{ nameFilter: 'esso', visible: [] },
{ results: [poi({ osm_id: 'a', name: 'Aral' })] },
)
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.getByText(/Nothing on the way matches/)).toBeInTheDocument()
expect(screen.queryByText('Pick what you need and search.')).not.toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-024: what was found carries the way to throw it away', () => {
const nothing = corridor()
const { unmount } = wrap(<RoadtripCorridorPanel corridor={nothing} routes={routes([day(1, 1)])} />)
// Before a search there is nothing to count and nothing to clear, and a dead control
// is worse than none.
expect(screen.queryByText(/on the way/)).not.toBeInTheDocument()
unmount()
// Two fuel hits and a campsite, so the total over the filters is a different
// sentence from any one group's count and can anchor the query on its own.
const c = corridor({ categories: ['fuel', 'campsite'] }, {
results: [
poi({ osm_id: 'a', name: 'Aral' }),
poi({ osm_id: 'b', name: 'Shell' }),
poi({ osm_id: 'c', name: 'Camping Elbe', category: 'campsite' }),
],
})
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
const header = screen.getByText('3 on the way').closest('div')!
fireEvent.click(within(header).getByRole('button'))
expect(c.clear).toHaveBeenCalledTimes(1)
// Clearing asks the place search for nothing at all.
expect(c.search.search).not.toHaveBeenCalled()
})
it('FE-ROADTRIP-PANEL-025: the search shares its row with a manual add, and only where one may add', () => {
const reader = corridor()
const { unmount } = wrap(<RoadtripCorridorPanel corridor={reader} routes={routes([day(1, 1)])} />)
expect(searchRow()).toHaveLength(1)
unmount()
const onAddManual = vi.fn()
const c = corridor()
wrap(
<RoadtripCorridorPanel
corridor={c}
routes={routes([day(1, 1)])}
onAddPoi={vi.fn()}
onAddManual={onAddManual}
/>,
)
// One row, two halves of it, not a second button under the first.
const [searchButton, manual] = searchRow()
expect(manual).toBeDefined()
expect(searchButton.className).toContain('flex-1')
expect(manual.className).toContain('flex-1')
// It opens the place form, which is the planner's to open: the panel asks, and
// nothing is added until a place has been found and saved in there.
fireEvent.click(manual)
expect(onAddManual).toHaveBeenCalledTimes(1)
// The kind, never the MouseEvent: the categories above the button are the answer to
// what is being added, and a form that ignored them opened every manual stop on fuel.
expect(onAddManual).toHaveBeenCalledWith('fuel')
})
it('FE-ROADTRIP-PANEL-035: the manual add opens on what the panel is looking for', () => {
const open = (categories: string[]): unknown => {
const onAddManual = vi.fn()
const { unmount } = wrap(
<RoadtripCorridorPanel
corridor={corridor({ categories })}
routes={routes([day(1, 1)])}
onAddPoi={vi.fn()}
onAddManual={onAddManual}
/>,
)
fireEvent.click(searchRow()[1])
unmount()
return onAddManual.mock.calls[0][0]
}
// An electric car seeds the panel to charging, and this is the case the fault was
// reported on: the panel said Charging and the form opened on Fuel.
expect(open(['charging'])).toBe('charging')
expect(open(['restaurant'])).toBe('restaurant')
// Multi-select: the first the panel LISTS wins, rather than a kind nobody switched on.
expect(open(['sights', 'rest_area'])).toBe('rest_area')
// Nothing selected is no answer, and the form falls back on its own.
expect(open([])).toBeNull()
})
it('FE-ROADTRIP-PANEL-026: with no drive on the trip there is nowhere to add one by hand', () => {
const dayless = corridor({ day: undefined })
wrap(<RoadtripCorridorPanel corridor={dayless} routes={routes([])} onAddPoi={vi.fn()} onAddManual={vi.fn()} />)
expect(searchRow()).toHaveLength(1)
})
it('FE-ROADTRIP-PANEL-029: a roomy row keeps both words, and the manual one is the short form', () => {
panelWidth.value = 320
wrap(
<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1)])} onAddPoi={vi.fn()} onAddManual={vi.fn()} />,
)
const [searchButton, manual] = searchRow()
expect(searchButton).toHaveTextContent('Search')
// The face of the button is the one word that fits beside it; the sentence stays
// as the name a reader and a tooltip get.
expect(manual).toHaveTextContent('Manual')
expect(manual).toHaveAttribute('aria-label', 'Add manually')
})
it('FE-ROADTRIP-PANEL-030: a narrow row drops the words rather than cutting them short', () => {
// "Add manu…" is neither the label nor a shape anybody recognises. Below the
// threshold both actions are their icon, and both keep their full names.
panelWidth.value = 150
wrap(
<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1)])} onAddPoi={vi.fn()} onAddManual={vi.fn()} />,
)
const [searchButton, manual] = searchRow()
expect(searchButton).toHaveTextContent('')
expect(manual).toHaveTextContent('')
expect(searchButton).toHaveAttribute('aria-label', 'Search')
expect(manual).toHaveAttribute('aria-label', 'Add manually')
// Still one row of two halves, not a stack.
expect(searchButton.className).toContain('flex-1')
expect(manual.className).toContain('flex-1')
})
it('FE-ROADTRIP-PANEL-032: a narrow panel gives the heading up before it gives up a control', () => {
// The heading repeats what the column already is; the controls are what somebody came
// here to change.
panelWidth.value = 320
const { unmount } = wrap(<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1), day(2, 2)])} />)
expect(screen.getByRole('heading', { name: 'Along the route' })).toBeInTheDocument()
unmount()
panelWidth.value = 150
wrap(<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1), day(2, 2)])} />)
expect(screen.queryByRole('heading', { name: 'Along the route' })).toBeNull()
// The day is still pickable, which is the whole point of freeing the room.
expect(screen.getByText('Day 1')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-033: a narrow panel drops the prompt but keeps every real answer', () => {
panelWidth.value = 150
const { unmount } = wrap(<RoadtripCorridorPanel corridor={corridor()} routes={routes([day(1, 1)])} />)
// Telling somebody to press the button they are looking at is not worth three
// wrapped lines; the mascot says the same thing.
expect(screen.queryByText('Pick what you need and search.')).toBeNull()
unmount()
// An answer to something the reader did stays, however narrow the column is.
const filtered = corridor({ nameFilter: 'Shell', visible: [] }, { results: [poi({ osm_id: 'a', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={filtered} routes={routes([day(1, 1)])} />)
expect(screen.getByText('Nothing on the way matches “Shell”.')).toBeInTheDocument()
})
it('FE-ROADTRIP-PANEL-031: a narrow row loses the words even while a search is running', () => {
// The spinner replaces the magnifier, and there is still no text to cut off.
panelWidth.value = 150
const c = corridor({}, { loading: true, progress: { done: 3, total: 12 } })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} onAddPoi={vi.fn()} onAddManual={vi.fn()} />)
const [searchButton, manual] = searchRow()
expect(searchButton).toHaveTextContent('')
expect(manual).toHaveTextContent('')
expect(searchButton).toHaveAttribute('aria-label', 'Search')
// The progress row is where the sentence lives, whatever the panel's width.
expect(screen.getByRole('progressbar')).toHaveTextContent('Searching 3 of 12')
})
it('FE-ROADTRIP-PANEL-027: clicking a row brings that hit into view, and adding it does not', () => {
const onFocusPoint = vi.fn()
const onAddPoi = vi.fn()
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral', lat: 53.14, lng: 9.82 })] })
wrap(
<RoadtripCorridorPanel
corridor={c}
routes={routes([day(1, 1)])}
onAddPoi={onAddPoi}
onFocusPoint={onFocusPoint}
/>,
)
fireEvent.click(screen.getByText('Aral'))
expect(onFocusPoint).toHaveBeenCalledWith(53.14, 9.82)
expect(onAddPoi).not.toHaveBeenCalled()
// The Add button is the row's sibling and not a button inside a button, so adding a
// stop does not also move the camera out from under the list.
onFocusPoint.mockClear()
fireEvent.click(screen.getByRole('button', { name: 'Add' }))
expect(onAddPoi).toHaveBeenCalledTimes(1)
expect(onFocusPoint).not.toHaveBeenCalled()
})
it('FE-ROADTRIP-PANEL-028: a row is inert where there is no map to move', () => {
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
// No handler, no button: a control that does nothing is one a keyboard user reaches
// for and finds empty.
expect(screen.getByText('Aral').closest('button')).toBeNull()
})
it('FE-ROADTRIP-PANEL-022: without permission to add, no hit offers an Add button', () => {
const c = corridor({}, { results: [poi({ osm_id: 'a', name: 'Aral' })] })
wrap(<RoadtripCorridorPanel corridor={c} routes={routes([day(1, 1)])} />)
expect(screen.queryByText('Add')).not.toBeInTheDocument()
})
})