Files
TREK/client/src/pages/tripPlanner/tripPlannerModel.test.ts
T
Maurice 5f4fb5dae7 feat(mobile): the tour editor as a tab of its own on an iPad and an unfolded foldable
On the wide and split size classes the touch shell no longer sends the tours tab back to the plan. It gets the desktop's tour editor, wired over the shell's own planner (useTripPlannerPageOf): on split the trip's tours and the editor share a pane beside the map, on wide the pane and the map take turns. A phone keeps its tours in the places browser.
2026-11-08 09:58:33 +01:00

74 lines
3.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { placesForDays, resolvePoolAssignmentId, tourPlannerTabOf } from './tripPlannerModel'
import { buildAssignment, buildPlace } from '../../../tests/helpers/factories'
describe('resolvePoolAssignmentId', () => {
it('returns the lone assignment id when the place is assigned to exactly one day', () => {
const place = buildPlace({ id: 7 })
const assignment = buildAssignment({ id: 42, day_id: 3, place })
const assignments = { 3: [assignment], 4: [buildAssignment({ id: 99, day_id: 4 })] }
expect(resolvePoolAssignmentId(assignments, 7)).toBe(42)
})
it('returns null when the place is not assigned to any day', () => {
const assignments = { 3: [buildAssignment({ id: 99, day_id: 3 })] }
expect(resolvePoolAssignmentId(assignments, 7)).toBeNull()
})
it('returns null when the place is assigned to multiple days (ambiguous time)', () => {
const assignments = {
3: [buildAssignment({ id: 1, day_id: 3, place: buildPlace({ id: 7 }) })],
4: [buildAssignment({ id: 2, day_id: 4, place: buildPlace({ id: 7 }) })],
}
expect(resolvePoolAssignmentId(assignments, 7)).toBeNull()
})
})
describe('placesForDays', () => {
const town = buildPlace({ id: 1, stop_type: null })
const hotel = buildPlace({ id: 2, stop_type: 'hotel' })
const pump = buildPlace({ id: 3, stop_type: 'fuel' })
const brauhaus = buildPlace({ id: 4, stop_type: 'restaurant' })
const campsite = buildPlace({ id: 5, stop_type: 'campsite' })
const all = [town, hotel, pump, brauhaus, campsite]
const none = { accommodations: [], reservations: [] }
it('FE-TP-MODEL-001: hands the list back untouched while road trip stops show in Days', () => {
expect(placesForDays(all, false, none)).toBe(all)
})
it('FE-TP-MODEL-002: leaves out every road trip stop nobody booked, but never a lodging', () => {
// The hotel's booking may be gone; the 'hotel' type it stamped on the place is not.
expect(placesForDays(all, true, none).map(p => p.id)).toEqual([1, 2])
})
it('FE-TP-MODEL-003: keeps the place a stay is at, whatever type it carries', () => {
const kept = placesForDays(all, true, { accommodations: [{ place_id: 5 }, { place_id: null }], reservations: [] })
expect(kept.map(p => p.id)).toEqual([1, 2, 5])
})
it('FE-TP-MODEL-004: keeps the place a booking names, directly or through its stay', () => {
const kept = placesForDays(all, true, {
accommodations: [],
reservations: [{ place_id: 4 }, { accommodation_place_id: 5 }, { place_id: null, accommodation_place_id: null }],
})
expect(kept.map(p => p.id)).toEqual([1, 2, 4, 5])
})
})
describe('tourPlannerTabOf', () => {
it('offers the editor on the desktop, as a desktop-only tab', () => {
expect(tourPlannerTabOf(true, false, false)).toEqual({ desktopOnly: true })
})
it('offers it in the touch shell of a large screen, where the rail shows it', () => {
expect(tourPlannerTabOf(true, true, true)).toEqual({ desktopOnly: false })
})
it('offers no tab on a phone, nor anywhere while the addon is off', () => {
expect(tourPlannerTabOf(true, true, false)).toBeNull()
expect(tourPlannerTabOf(false, false, false)).toBeNull()
expect(tourPlannerTabOf(false, true, true)).toBeNull()
})
})