mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
5ef8bf31f4
The button carried nothing and the form hard-wired the kind, so the categories sitting directly above it had no way through and every manual stop started life as a fuel stop with ten minutes on it. The click now carries what the corridor is looking for, dwell included. The picker is multi-select, so the first kind the panel lists wins rather than a fallback nobody switched on; with nothing selected the form falls back on its own, because a stop without a kind is a numbered destination that counts in every total. This also closes the case it was noticed on: an electric car seeds the panel to charging, so the picker said Charging over a form that said Fuel.
96 lines
4.6 KiB
TypeScript
96 lines
4.6 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, manualStopKindFor,
|
|
} 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: accommodation is a service stop as well as an overnight category', () => {
|
|
expect(CORRIDOR_CATEGORY_BY_KEY.hotel.stopKind).toBe('hotel')
|
|
expect(STOP_KIND_BY_KEY.hotel).toBeDefined()
|
|
expect(SERVICE_KIND_KEYS).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' && kind.key !== 'hotel') {
|
|
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)
|
|
}
|
|
})
|
|
|
|
it('FE-STOPKIND-008: the manual add opens on what the corridor is looking for', () => {
|
|
// A stop added by hand used to open on fuel whatever the panel above it said, which
|
|
// on an electric car meant a picker reading Charging over a form reading Fuel.
|
|
for (const category of CORRIDOR_CATEGORIES) {
|
|
expect(manualStopKindFor([category.key])).toBe(category.stopKind)
|
|
}
|
|
// Multi-select, so the first the panel LISTS wins: falling back would open on a kind
|
|
// that is not among the ones switched on, which is a worse answer than any of them.
|
|
const [first, second] = CORRIDOR_CATEGORY_KEYS
|
|
expect(manualStopKindFor([second, first])).toBe(CORRIDOR_CATEGORY_BY_KEY[first].stopKind)
|
|
// Nothing selected is no answer at all, and the caller decides what to do with that.
|
|
expect(manualStopKindFor([])).toBeNull()
|
|
expect(manualStopKindFor(['not-a-category'])).toBeNull()
|
|
})
|
|
})
|