import type { Badge } from '@trek/shared'; import { vi } from 'vitest'; import type { AtlasGlobeState } from '../../src/pages/atlas/useAtlasGlobe'; import { buildAtlasData } from './atlas'; /** * Fakes for the desktop globe Atlas surfaces (view, search, badges, wishlist, * Dawarich tab, badge unlock). They all read one big state object from * useAtlasGlobe; a test builds only the slice its surface reads, with fresh * spies every call (the suite keeps mock history between tests). */ /** A translator that shows the key and its named params, so a test can read both. */ export function viewT(key: string, params?: Record): string { const parts = Object.entries(params ?? {}).map(([k, v]) => `${k}=${String(v)}`); if (!parts.length) return key; return `${key}(${parts.join(',')})`; } const NAMES: Record = { FR: 'France', JP: 'Japan', DE: 'Germany', IT: 'Italy', US: 'United States' }; export function buildViewBadge(over: Partial = {}): Badge { return { id: 'countries-5', category: 'countries', motif: 'countries', tier: 'bronze', titleKey: 'atlas.badge.countries.title', descKey: 'atlas.badge.countries.desc', earned: false, current: 2, target: 5, ...over, }; } /** The globe state with harmless defaults; `over` replaces any field. */ export function buildViewState(over: Record = {}): AtlasGlobeState { const base: Record = { t: vi.fn(viewT), language: 'en', data: buildAtlasData(), manifest: { countries: [], attribution: [] }, regions: {}, badges: [] as Badge[], me: { id: 7 }, people: null, compareEnabled: false, loadPeople: vi.fn(), resolveName: vi.fn((a2: string) => NAMES[a2] ?? ''), // search query: '', setQuery: vi.fn(), results: [], pickResult: vi.fn(), placeHits: [], placesLoading: false, pickPlace: vi.fn(async () => undefined), loadRegionSearch: vi.fn(), // wishlist / dawarich bucketState: { bucketList: [], showBucketAdd: false, setShowBucketAdd: vi.fn(), handleClearBucketVisit: vi.fn(async () => undefined), handleDeleteBucketItem: vi.fn(async () => undefined), }, dawarichEnabled: false, dawarichSub: 'wishes', openDawarich: vi.fn(), reload: vi.fn(async () => undefined), flyToPoint: vi.fn(), // globe view pins: [], hover: null, compareWith: null, gaps: false, setGaps: vi.fn(), stopCompare: vi.fn(), setError: vi.fn(), zoomIn: vi.fn(), zoomOut: vi.fn(), fetchJson: vi.fn(), labelFor: vi.fn(), labelRegionsOf: vi.fn(), paint: vi.fn(), paintKey: 'k', onHover: vi.fn(), onSelect: vi.fn(), onReady: vi.fn(), }; return { ...base, ...over } as unknown as AtlasGlobeState; }