import type { PlaceActivity, PlaceActivityCandidate, PlaceHistoryEntry, PlaceLibraryActivitySource, PlaceMediaFile, PlaceMediaImage, PlaceMediaJourneyPhoto, } from '@trek/shared'; import { vi } from 'vitest'; import type { usePlaceActivities } from '../../src/components/Collections/usePlaceActivities'; import type { usePlaceHistory } from '../../src/components/Collections/usePlaceHistory'; import type { usePlaceMedia } from '../../src/components/Collections/usePlaceMedia'; /* * Builders for the extras of a place of All places: its tours and bookings * (PLC-18), its change history (PLC-14) and its pictures and files (PLC-19, * PLC-20). A booking of trip 5 "Rome 2026" on trip place 42 unless told otherwise. */ export function activityCandidate(over: Partial = {}): PlaceActivityCandidate { return { key: 'reservation:7', type: 'booking', origin: { kind: 'trip', trip_id: 5, trip_title: 'Rome 2026' }, target: { kind: 'reservation', trip_id: 5, reservation_id: 7 }, title: 'Colosseum tickets', booking_type: 'tour', booking_status: 'confirmed', tour_type: null, starts_at: null, ends_at: null, date: null, day_number: null, ...over, }; } export function placeActivity(over: Partial = {}): PlaceActivity { return { ...activityCandidate(), source: { kind: 'trip', trip_id: 5, place_id: 42 }, explicit: true, implicit_via: null, can_unlink: true, ...over, }; } /** A tour kept in list 9 "Favourites", linked to saved place 900. */ export function listTour(over: Partial = {}): PlaceActivity { return placeActivity({ key: 'collection_tour:3', type: 'tour', origin: { kind: 'list', collection_id: 9, collection_name: 'Favourites' }, target: { kind: 'collection_tour', collection_id: 9, collection_tour_id: 3 }, source: { kind: 'list', collection_id: 9, collection_place_id: 900 }, title: 'Old town walk', booking_type: null, booking_status: null, tour_type: 'walk', ...over, }); } export function tripSource(over: Partial = {}): PlaceLibraryActivitySource { return { source: { kind: 'trip', trip_id: 5, place_id: 42 }, origin: { kind: 'trip', trip_id: 5, trip_title: 'Rome 2026' }, can_link: true, ...over, }; } export function listSource(over: Partial = {}): PlaceLibraryActivitySource { return { source: { kind: 'list', collection_id: 9, collection_place_id: 900 }, origin: { kind: 'list', collection_id: 9, collection_name: 'Favourites' }, can_link: true, ...over, }; } export function historyEntry(over: Partial = {}): PlaceHistoryEntry { return { id: 1, origin: { kind: 'trip', trip_id: 5, trip_title: 'Rome 2026', place_id: 42 }, field: 'name', old_value: 'Colosseo', new_value: 'Colosseum', editor: { id: 2, username: 'anna', avatar_url: null }, automatic: false, changed_at: '2026-12-02 14:30:00', ...over, }; } /** `count` changes with the ids 1..count. */ export function historyEntries(count: number, from = 1): PlaceHistoryEntry[] { return Array.from({ length: count }, (_, i) => historyEntry({ id: from + i, new_value: `Name ${from + i}`, old_value: null }) ); } export function mediaImage(url: string, kind: 'trip' | 'list' = 'trip'): PlaceMediaImage { return kind === 'trip' ? { kind: 'trip', image_url: url, trip_id: 5, trip_title: 'Rome 2026', place_id: 42 } : { kind: 'list', image_url: url, collection_id: 9, collection_name: 'Favourites', collection_place_id: 900 }; } export function journeyPhoto(over: Partial = {}): PlaceMediaJourneyPhoto { return { journey_id: 3, journey_title: 'Italy journey', entry_id: 11, entry_date: '2026-12-02', journey_photo_id: 70, photo_id: 700, provider: 'local', asset_id: null, owner_id: 2, file_path: null, thumbnail_path: null, width: 800, height: 600, media_type: 'image', caption: null, taken_at: null, ...over, }; } export function mediaFile(over: Partial = {}): PlaceMediaFile { return { file_id: 31, trip_id: 5, trip_title: 'Rome 2026', place_id: 42, original_name: 'tickets.pdf', mime_type: 'application/pdf', file_size: 1200, created_at: null, url: '/trips/5/files?file=31', ...over, }; } /** What the activities hook hands a view, with spies for its handlers. */ export function activitiesState( over: Partial> = {} ): ReturnType { return { activities: [], canLink: false, picking: null, closePicker: vi.fn(), openPicker: vi.fn().mockResolvedValue(undefined), link: vi.fn().mockResolvedValue(undefined), unlink: vi.fn().mockResolvedValue(undefined), busy: false, ...over, }; } /** What the history hook hands a view. */ export function historyState( over: Partial> = {} ): ReturnType { return { entries: [], hasMore: false, loadingMore: false, more: vi.fn().mockResolvedValue(undefined), ...over }; } /** What the media hook hands a view. */ export function mediaState(over: Partial> = {}): ReturnType { return { cover: null, canCover: vi.fn(() => false), setCover: vi.fn().mockResolvedValue(undefined), photos: [], files: [], open: null, setOpen: vi.fn(), close: vi.fn(), targets: [], choosing: false, setChoosing: vi.fn(), upload: vi.fn().mockResolvedValue(undefined), uploading: false, ...over, }; } /** `count` pictures as the media hook hands them out. */ export function photos(count: number): ReturnType['photos'] { return Array.from({ length: count }, (_, i) => ({ id: `img:/p${i}.jpg`, src: `/p${i}.jpg`, thumbSrc: `/p${i}.jpg`, caption: `Photo ${i}`, })); }