Files
TREK/client/src/pages/TripPlannerPage.wiring.fixture.ts
T
Maurice bafb74f872 feat(tours): put a multi-day tour on a day whole or a stage a day from it on
Putting a multi-day tour on a day through any of the usual ways put the
whole tour on that one day. Now the way it goes on is a choice: the whole
tour on this day, or stage 1 on this day and each next stage on the next
day of the trip.

The day menu of the tour lists and the detail's "Add to day" ask in the
same menu, as a second step after the day; a tour dragged onto a day, or
added from a place where no menu asked, gets a small dialog on the desktop
and a card on the phone. Only the trip's days are used: when fewer days
are left than stages, the menu says up to which stage fits and the rest
stay without a day. A stage already on a day moves to its new day, the
whole tour comes off the days it was on, and a stage the route no longer
has comes off too. The writes run in order through the store, the repo
and the mutation queue, so they work offline, and one undo takes the
spread back, the whole tour onto its day again.

The plan lives in stageSpread.ts, the writes and the question in
useTourDayChoice, which every way onto a day now passes through on both
the desktop and the phone.
2026-10-20 22:17:20 +02:00

333 lines
11 KiB
TypeScript

// The useTripPlanner fixture the TripPlannerPage wiring tests render against:
// every field the page reads, set to the plain Plan-tab state, so a test only
// overrides what it is about. Shared by TripPlannerPage.wiring.test.tsx and
// TripPlannerPage.tours.wiring.test.tsx.
import { vi } from 'vitest';
import { buildAssignment, buildDay, buildPlace, buildTrip } from '../../tests/helpers/factories';
import type { Day, Place } from '../types';
export const trip = buildTrip({ id: 42, title: 'Kyoto', currency: 'JPY' });
export const day: Day = buildDay({ id: 7, trip_id: 42 });
export const place: Place = buildPlace({ id: 1, name: 'Kiyomizu', lat: 34.9, lng: 135.7 });
export type HookState = Record<string, unknown>;
/** The plain Plan-tab state of every field the page reads from useTripPlanner. */
export function baseState(): HookState {
return { ...tripDataState(), ...roadtripState(), ...layoutState(), ...dialogState(), ...mapState() };
}
/** The trip, its data and the rights and addons around it. */
function tripDataState(): HookState {
return {
tripId: 42,
navigate: vi.fn(),
toast: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() },
t: (key: string) => key,
language: 'en',
placesPhotosEnabled: true,
trip,
days: [day],
places: [place],
assignments: { '7': [buildAssignment({ id: 10, day_id: 7, place, order_index: 0 })] },
packingItems: [],
todoItems: [],
categories: [],
reservations: [],
budgetItems: [],
files: [],
selectedDayId: 7,
isLoading: false,
tripActions: {
addFile: vi.fn(async () => undefined),
deleteFile: vi.fn(async () => undefined),
loadFiles: vi.fn(async () => undefined),
updatePlace: vi.fn(async () => undefined),
uploadPlaceImage: vi.fn(async () => undefined),
ratePlace: vi.fn(async () => undefined),
updateReservation: vi.fn(async () => undefined),
updateTrip: vi.fn(async () => undefined),
setSelectedDay: vi.fn(() => undefined),
addCategory: vi.fn(async () => undefined),
},
can: vi.fn(() => true),
canUploadFiles: true,
pushUndo: vi.fn(() => undefined),
undo: vi.fn(async () => undefined),
canUndo: false,
lastActionLabel: null,
handleUndo: vi.fn(async () => undefined),
enabledAddons: { packing: true, budget: true, documents: true, collab: true },
collabFeatures: { chat: true, notes: true, polls: true, whatsnext: true },
tripAccommodations: [],
setTripAccommodations: vi.fn(),
};
}
function roadtripState(): HookState {
return {
// Road trip mode off, which is the state every wiring test reads: the page keeps
// its ordinary map, sidebar and route wiring, and the road-trip branches stay unmounted.
// The shapes still have to be here, because the page reaches into routeAlternatives.open,
// roadtripRoutes.lines and roadtripVias.byDay before it ever checks whether the mode is on.
roadtripMode: false,
toggleRoadtripMode: vi.fn(),
roadtripActive: false,
roadtripRoutes: { lines: [], segments: [], days: [], loading: false, totalStops: 0 },
roadtripCorridor: {
visible: [],
day: null,
dayId: '',
setDayId: vi.fn(),
categories: [],
toggleCategory: vi.fn(),
widthKm: 5,
setWidthKm: vi.fn(),
search: vi.fn(),
nameFilter: '',
setNameFilter: vi.fn(),
insertIndexFor: vi.fn(),
},
refuel: { openFor: null, loading: false, outcome: null, results: [], offered: [], ask: vi.fn(), close: vi.fn() },
askRefuel: vi.fn(),
acceptRefuel: vi.fn(),
followTrack: {
dayId: null,
open: vi.fn(),
close: vi.fn(),
tracks: [],
busy: false,
round: 0,
error: null,
outcome: null,
apply: vi.fn(),
clear: vi.fn(),
viaCount: 0,
available: false,
},
// The recorded-route overlay (#2279). Off and empty: the page reads
// `dawarichTrail.track` unconditionally, so the fixture has to carry the
// shape the hook returns even when the addon is not in play.
dawarichEnabled: false,
dawarichTrailShown: false,
toggleDawarichTrail: vi.fn(),
dawarichTrail: { track: null, status: 'idle', reload: vi.fn() },
roadtripViaCounts: {},
stopDraft: null,
setStopDraft: vi.fn(),
saveStopDraft: vi.fn(async () => undefined),
stopDraftToForm: vi.fn(),
stopDraftDuplicate: null,
reorderRoadtripStop: vi.fn(async () => undefined),
roadtripVias: { byDay: {}, refresh: vi.fn(async () => undefined) },
addRoadtripVia: vi.fn(async () => undefined),
moveRoadtripVia: vi.fn(async () => undefined),
removeRoadtripVia: vi.fn(async () => undefined),
routeAlternatives: { open: null, close: vi.fn(), loading: false, ask: vi.fn(async () => undefined) },
askRouteAlternatives: vi.fn(async () => undefined),
chooseRouteAlternative: vi.fn(async () => undefined),
alternativeOverlays: [],
alternativeFocusPoints: [],
stayDraft: null,
setStayDraft: vi.fn(),
setRoadtripStay: vi.fn(async () => undefined),
highlightedAlternative: null,
setHighlightedAlternative: vi.fn(),
moveRoadtripStopToDay: vi.fn(async () => undefined),
dropPoiOnRoute: vi.fn(async () => undefined),
};
}
/** Tabs, side panels and the selection. */
function layoutState(): HookState {
return {
allowedFileTypes: 'pdf',
tripMembers: [],
setTripMembers: vi.fn(),
refreshMembers: vi.fn(),
loadAccommodations: vi.fn(),
TRANSPORT_TYPES: new Set(['flight', 'train']),
TRIP_TABS: [
{ id: 'plan', label: 'Plan' },
{ id: 'transports', label: 'Transports' },
{ id: 'buchungen', label: 'Bookings', shortLabel: 'Book' },
{ id: 'listen', label: 'Lists' },
{ id: 'finanzplan', label: 'Costs' },
{ id: 'dateien', label: 'Files' },
{ id: 'collab', label: 'Collab' },
],
activeTab: 'plan',
setActiveTab: vi.fn(),
handleTabChange: vi.fn(),
leftWidth: 320,
rightWidth: 320,
leftCollapsed: false,
rightCollapsed: false,
setLeftCollapsed: vi.fn(),
setRightCollapsed: vi.fn(),
leftHidden: false,
rightHidden: false,
toggleLeft: vi.fn(),
toggleRight: vi.fn(),
narrowPanels: false,
startResizeLeft: vi.fn(),
startResizeRight: vi.fn(),
nudgeLeft: vi.fn(),
nudgeRight: vi.fn(),
resizeMin: 200,
resizeMax: 520,
selectedPlaceId: null,
selectedAssignmentId: null,
setSelectedPlaceId: vi.fn(),
selectAssignment: vi.fn(),
showDayDetail: null,
setShowDayDetail: vi.fn(),
dayDetailCollapsed: false,
setDayDetailCollapsed: vi.fn(),
showPlaceForm: false,
setShowPlaceForm: vi.fn(),
setPlaceFormDayId: vi.fn(),
editingPlace: null,
setEditingPlace: vi.fn(),
prefillCoords: null,
setPrefillCoords: vi.fn(),
editingAssignmentId: null,
setEditingAssignmentId: vi.fn(),
serviceStopMode: null,
setServiceStopForm: vi.fn(),
openManualRoadtripStop: vi.fn(),
};
}
/** The modals, the booking flows and the delete confirmations. */
function dialogState(): HookState {
return {
showTripForm: false,
setShowTripForm: vi.fn(),
showMembersModal: false,
setShowMembersModal: vi.fn(),
showReservationModal: false,
setShowReservationModal: vi.fn(),
editingReservation: null,
setEditingReservation: vi.fn(),
showBookingImport: false,
setShowBookingImport: vi.fn(),
bookingImportKind: 'bookings' as const,
setBookingImportKind: vi.fn(),
bookingImportAvailable: true,
airTrailAvailable: true,
showAirTrailImport: false,
setShowAirTrailImport: vi.fn(),
bookingForAssignmentId: null,
setBookingForAssignmentId: vi.fn(),
showTransportModal: false,
setShowTransportModal: vi.fn(),
editingTransport: null,
setEditingTransport: vi.fn(),
transportModalDayId: null,
setTransportModalDayId: vi.fn(),
transportModalAutomated: false,
setTransportModalAutomated: vi.fn(),
transitPrefill: null,
setTransitPrefill: vi.fn(),
transitJourney: null,
setTransitJourney: vi.fn(),
openTransportEditor: vi.fn(),
changeTransitRoute: vi.fn(),
bookingDetail: null,
openBookingDetail: vi.fn(),
openBookingFromDayList: vi.fn(),
closeBookingDetail: vi.fn(),
bookingDetailEditor: undefined,
bookingDetailChangeRoute: undefined,
showBookingOnMap: vi.fn(),
isBookingOnMap: vi.fn(() => false),
reservationPrefill: null,
transportPrefill: null,
importReviewActive: false,
advanceImportReview: vi.fn(),
routeShown: false,
setRouteShown: vi.fn(),
transitRoutesShown: false,
routeProfile: 'driving',
setRouteProfile: vi.fn(),
routeVias: [],
fitKey: 0,
setFitKey: vi.fn(),
mobileSidebarOpen: null,
setMobileSidebarOpen: vi.fn(),
mobilePlanScrollTopRef: { current: 0 },
mobilePlacesScrollTopRef: { current: 0 },
deletePlaceId: null,
setDeletePlaceId: vi.fn(),
deletePlaceIds: null,
setDeletePlaceIds: vi.fn(),
stayRelease: null,
setStayRelease: vi.fn(),
confirmStayRelease: vi.fn(async () => undefined),
visibleConnections: [],
toggleConnection: vi.fn(),
allConnectionsShown: false,
toggleAllConnections: vi.fn(),
mapTransportDetail: null,
setMapTransportDetail: vi.fn(),
};
}
/** The map, the route and the hook handlers, plus Tours. */
function mapState(): HookState {
return {
isMobile: false,
isTouch: false,
expandedDayIds: null,
setExpandedDayIds: vi.fn(),
mapPlaces: [place],
route: null,
routeSegments: [],
routeInfo: null,
setRoute: vi.fn(),
setRouteInfo: vi.fn(),
updateRouteForDay: vi.fn(),
handleSelectDay: vi.fn(),
handlePlaceClick: vi.fn(),
handleMarkerClick: vi.fn(),
handleMapClick: vi.fn(),
handleMapContextMenu: vi.fn(),
openAddPlaceFromPoi: vi.fn(),
handleSavePlace: vi.fn(async () => undefined),
openPlaceEditor: vi.fn(),
handleDeletePlace: vi.fn(),
handleDeleteTour: vi.fn(),
confirmDeletePlace: vi.fn(async () => undefined),
confirmDeletePlaces: vi.fn(async () => undefined),
confirmChangeCategory: vi.fn(async () => undefined),
handleAssignToDay: vi.fn(async () => undefined),
tourDayQuestion: null,
answerTourDay: vi.fn(),
handleRemoveAssignment: vi.fn(async () => undefined),
handleReorder: vi.fn(),
handleReorderDays: vi.fn(),
handleAddDay: vi.fn(),
handleUpdateDayTitle: vi.fn(async () => undefined),
handleSaveReservation: vi.fn(async () => ({ id: 1 })),
handleSaveTransport: vi.fn(async () => ({ id: 2 })),
handleDeleteReservation: vi.fn(async () => undefined),
selectedPlace: null,
dayOrderMap: {},
dayPlaces: [],
toursEnabled: false,
toursMode: true,
setToursMode: vi.fn(),
tours: [],
toursLoading: false,
tourDataReady: true,
tourPlaceIds: new Set<number>(),
reloadTourPlaceIds: vi.fn(async () => undefined),
upsertTour: vi.fn(),
selectedTour: null,
mapTileUrl: 'https://tiles/{z}/{x}/{y}.png',
fontStyle: { fontFamily: 'var(--font-system)' },
splashDone: true,
};
}