mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 14:36:31 +00:00
8e2a2725f0
ServiceStop, RouteViaStop and Stop leave RoadtripSidebar.tsx for their own module and are imported back by name; effectiveFill goes with them unexported, and the imports only they used leave the sidebar. The badge row under a stop's name was written out twice, once in each stop shape. It is now the local StopBadgeRow, which both render in its place. It returns the same span with nothing around it, so the markup is unchanged, and it reads the fill setting and the vehicle the two shapes used to read themselves. Those are plain store reads, so moving them one component down changes nothing either. The code moves as it was otherwise. The note on the stop kind table now sits at the lookup it describes, the comment on the two settings says where they are read now, and the dashes in the moved comments become colons, commas and full stops; each theme-lint-disable stays on the line of its style. Nothing renders differently. New tests render the rows on their own: a plugin halt with and without its name and stay, the kind picker on a pause and on a numbered stop by click, Enter and Space, the drive findings and the walk from the road on both shapes, including the range and unknown findings the rail never draws, and the fill badge with the traveller's default.
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
import { act, fireEvent, screen } from '@testing-library/react'
|
|
import { vi } from 'vitest'
|
|
import type { RoadtripPreferences } from '@trek/shared'
|
|
import { useAuthStore } from '../../src/store/authStore'
|
|
import { useRoadtripPreferencesStore } from '../../src/store/roadtripPreferencesStore'
|
|
import { useSettingsStore } from '../../src/store/settingsStore'
|
|
import { useTripStore } from '../../src/store/tripStore'
|
|
|
|
/** Scaffolding for the tests of the road trip rail's parts, each rendered on its own. */
|
|
|
|
/**
|
|
* What the tooltip says once the pointer has rested on the element long enough.
|
|
*
|
|
* The pointer leaves again and the real clock is back before it returns, so a case can
|
|
* read one tooltip after another and render on with real timers.
|
|
*/
|
|
export function tooltipOf(el: Element): string {
|
|
vi.useFakeTimers()
|
|
fireEvent.mouseEnter(el)
|
|
act(() => { vi.advanceTimersByTime(300) })
|
|
const text = screen.getByRole('tooltip').textContent ?? ''
|
|
fireEvent.mouseLeave(el)
|
|
vi.useRealTimers()
|
|
return text
|
|
}
|
|
|
|
const USER_ID = 7
|
|
const TRIP_ID = 4
|
|
|
|
/** The traveller's road trip settings for the trip on screen. */
|
|
export function preferences(p: RoadtripPreferences): void {
|
|
useAuthStore.setState({ user: { id: USER_ID } } as never)
|
|
useTripStore.setState({ trip: { id: TRIP_ID } } as never)
|
|
useRoadtripPreferencesStore.setState({ byTrip: { [`${USER_ID}:${TRIP_ID}`]: p } })
|
|
}
|
|
|
|
/** Metric distances on a 24-hour clock, the settings each case starts from. */
|
|
export function seedRailSettings(): void {
|
|
useSettingsStore.setState({ settings: { distance_unit: 'metric', time_format: '24h' } as never })
|
|
}
|
|
|
|
/** The real clock, and no road trip settings, trip or user, once a case is done. */
|
|
export function resetRailStores(): void {
|
|
vi.useRealTimers()
|
|
useRoadtripPreferencesStore.setState({ byTrip: {} })
|
|
useTripStore.setState({ trip: null } as never)
|
|
useAuthStore.setState({ user: null } as never)
|
|
}
|