Files
TREK/client/tests/helpers/atlasGlobeViews.ts
T
Maurice 14443a17be feat(atlas): a regions view, and visited regions that stand out
A traveller who visited only Alberta saw all of Canada colored on the zoomed-out globe. A new layer switch, Regions instead of countries, keeps the coarse regions of every country with a visited region on screen at every zoom: the engine loads and holds them (setPinnedRegions), the renderer draws them at full strength with faint inner borders, and the country itself only tints faintly beneath them once they are drawn. The switch is remembered per device, on the desktop layers dialog and the phone sheet, in all 28 languages.

Also without the switch, a country with visited regions now steps far back once its regions fade in (to about a fifth instead of two thirds), so the regions really visited stand out from the rest of the country.
2026-11-29 11:53:46 +01:00

125 lines
3.4 KiB
TypeScript

import type { Badge } from '@trek/shared';
import { vi } from 'vitest';
import type { AtlasGlobeState } from '../../src/pages/atlas/useAtlasGlobe';
/**
* Fakes for the hub tabs, dialogs and overlays of the globe Atlas. Each view
* reads a few fields of the one state object useAtlasGlobe returns, so a test
* builds it here with neutral values and fresh spies, and overrides only the
* fields it is about.
*/
/** t() that shows its params, so a test can see which key was asked with what. */
export function viewT(key: string, params?: Record<string, unknown>): string {
if (!params) return key;
return `${key}[${Object.entries(params)
.map(([k, v]) => `${k}=${String(v)}`)
.join(',')}]`;
}
export interface ViewBucketForm {
name: string;
notes: string;
lat: string;
lng: string;
target_date: string;
address?: string;
}
export function viewBadge(over: Partial<Badge> = {}): 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,
};
}
export function viewBucket(over: Record<string, unknown> = {}): Record<string, unknown> {
return {
bucketForm: { name: '', notes: '', lat: '', lng: '', target_date: '' } as ViewBucketForm,
setBucketForm: vi.fn(),
bucketPoiYear: 0,
setBucketPoiYear: vi.fn(),
bucketPoiMonth: 0,
setBucketPoiMonth: vi.fn(),
handleSelectBucketPoi: vi.fn(),
handleAddBucketItem: vi.fn(async () => undefined),
resetBucketAdd: vi.fn(),
...over,
};
}
export function viewState(over: Record<string, unknown> = {}): AtlasGlobeState {
const base: Record<string, unknown> = {
t: viewT,
language: 'en',
placeLang: 'en',
data: null,
manifest: null,
error: null,
retryLoad: vi.fn(),
totals: { countries: 0, continents: 0, regions: 0, trips: 0, firstYear: null, perYear: new Map<number, number>() },
year: null,
setYear: vi.fn(),
timelineOpen: false,
setTimelineOpen: vi.fn(),
bucketState: viewBucket(),
bucket: [],
setBucket: vi.fn(),
regions: {},
setRegions: vi.fn(),
setData: vi.fn(),
confirmAction: null,
setConfirmAction: vi.fn(),
executeConfirmAction: vi.fn(async () => undefined),
bucketMonth: 0,
setBucketMonth: vi.fn(),
bucketYear: 0,
setBucketYear: vi.fn(),
handleDeleteBucketItem: vi.fn(async () => undefined),
askUnmarkDetail: vi.fn(),
detail: null,
progress: null,
closeDialogs: vi.fn(),
resolveName: (code: string) => `name-${code}`,
showPlanned: false,
setShowPlanned: vi.fn(),
regionView: false,
setRegionView: vi.fn(),
flights: null,
showFlights: false,
setShowFlights: vi.fn(),
colorMode: 'country',
setColorMode: vi.fn(),
pluginLayers: [],
hiddenPluginLayers: new Set<string>(),
togglePluginLayer: vi.fn(),
badges: [] as Badge[],
passportOpen: false,
setPassportOpen: vi.fn(),
passportTab: 'overview',
setPassportTab: vi.fn(),
openPassport: vi.fn(),
profile: null,
profileId: null,
setProfileId: vi.fn(),
startCompare: vi.fn(),
dawarichEnabled: false,
compareEnabled: false,
openDawarich: vi.fn(),
loadPeople: vi.fn(),
ranking: null,
me: null,
hidden: false,
setHidden: vi.fn(),
};
return { ...base, ...over } as unknown as AtlasGlobeState;
}