Files
TREK/client/src/components/Roadtrip/stopKinds.test.ts
T
Maurice 95c173a8a8 fix(roadtrip): put a driving finding on the stop it arrives at, not the one it leaves
Reported from a real trip: Hamburg, A1, HEM, Berlin. HEM to Berlin is 244.7 km,
and the badge on Berlin said 121 — which is the length of the NEXT leg, Berlin
to Sanssouci. The finding was anchored to the stop the leg departs from while
its wording ("since the last fill-up") is a running total, so the number never
matched what anyone adds up off the drive bands above it.

Both findings are true on arrival, so that is where they belong. The same trip
now reads 125 at HEM (21.5 + 103.4) and 245 at Berlin, which is exactly what you
get counting the bands.

A service stop carries them too. A charging halt is a stop like any other as far
as the tank is concerned, and HEM was the very stop whose figure went missing.

The corridor's empty state gets the mascot the rest of TREK uses: searching,
idle, and a confused look when a filter left nothing standing, so the picture
says which of the three it is before the sentence is read.
2026-09-07 18:36:54 +02:00

84 lines
3.8 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { roadtripStopTypeSchema } from '@trek/shared'
import { SERVICE_STOP_TYPES, SERVICE_COLORS } from './roadtripModel'
import {
STOP_KINDS, STOP_KIND_BY_KEY, CORRIDOR_CATEGORIES, CORRIDOR_CATEGORY_BY_KEY, CORRIDOR_CATEGORY_KEYS,
SERVICE_KIND_KEYS, REFUELLING_STOP_TYPES, isOvernightCategory,
} from './stopKinds'
/**
* The table exists to stop nine lists from drifting apart, and these are the assertions
* that make that true rather than intended. Each one pins the table against a list that
* cannot import it: the Zod enum lives in `@trek/shared` and must not depend on the
* client, and `SERVICE_STOP_TYPES` lives in the React-free model.
*/
describe('stop kinds', () => {
it('FE-STOPKIND-001: covers exactly the kinds the shared enum allows', () => {
const fromSchema = [...roadtripStopTypeSchema.options].sort()
const fromTable = STOP_KINDS.map(k => k.key).sort()
expect(fromTable).toEqual(fromSchema)
})
it('FE-STOPKIND-002: agrees with the model about which kinds interrupt a drive', () => {
expect([...SERVICE_KIND_KEYS].sort()).toEqual([...SERVICE_STOP_TYPES].sort())
})
it('FE-STOPKIND-003: every kind carries the colour the model gives it', () => {
for (const kind of STOP_KINDS) expect(kind.color).toBe(SERVICE_COLORS[kind.key])
})
it('FE-STOPKIND-004: a refuelling kind is a kind, so a range budget cannot reset on a typo', () => {
for (const key of REFUELLING_STOP_TYPES) expect(STOP_KIND_BY_KEY[key]).toBeDefined()
})
it('FE-STOPKIND-005: the corridor offers every category in a stable order', () => {
// Sleeping sits next to sleeping: hotel follows campsite rather than landing wherever
// the stop-kind table happens to end.
expect(CORRIDOR_CATEGORY_KEYS).toEqual(['fuel', 'charging', 'rest_area', 'campsite', 'hotel', 'restaurant', 'sights'])
})
it('FE-STOPKIND-008: a hotel is a category without being a stop kind', () => {
// The whole reason the two lists are separate. Sleeping somewhere ends the day rather
// than interrupting the drive, so a hotel keeps its number in the chain and never
// becomes a stop_type.
expect(CORRIDOR_CATEGORY_BY_KEY.hotel.stopKind).toBeNull()
expect(STOP_KIND_BY_KEY.hotel).toBeUndefined()
expect(SERVICE_KIND_KEYS).not.toContain('hotel')
})
it('FE-STOPKIND-009: a night can be booked at a campsite too, so the popup asks', () => {
expect(isOvernightCategory('hotel')).toBe(true)
expect(isOvernightCategory('campsite')).toBe(true)
expect(isOvernightCategory('fuel')).toBe(false)
expect(isOvernightCategory(null)).toBe(false)
})
it('FE-STOPKIND-010: every category that is a stop kind names the kind it creates', () => {
for (const category of CORRIDOR_CATEGORIES) {
if (category.stopKind === null) continue
expect(category.stopKind).toBe(category.key)
expect(STOP_KIND_BY_KEY[category.key]).toBeDefined()
}
})
it('FE-STOPKIND-006: two kinds are named under a key of their own, and that is on purpose', () => {
// Spelled out rather than derived: the corridor calls a rest area rest_area and names
// it under rest, a restaurant restaurant and names it under food. A derived label key
// would silently ask for two translations that do not exist.
expect(STOP_KIND_BY_KEY.rest_area.labelKey).toBe('roadtrip.poi.rest')
expect(STOP_KIND_BY_KEY.restaurant.labelKey).toBe('roadtrip.poi.food')
for (const kind of STOP_KINDS) {
if (kind.key !== 'rest_area' && kind.key !== 'restaurant') {
expect(kind.labelKey).toBe(`roadtrip.poi.${kind.key}`)
}
}
})
it('FE-STOPKIND-007: every kind offers a dwell the popup can pre-fill', () => {
for (const kind of STOP_KINDS) {
expect(kind.defaultMinutes).toBeGreaterThan(0)
expect(Number.isInteger(kind.defaultMinutes)).toBe(true)
}
})
})