Files
TREK/client/tests/helpers/atlasGlobeState.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

117 lines
3.4 KiB
TypeScript

import { vi } from 'vitest';
import type { AtlasGlobeState } from '../../src/pages/atlas/useAtlasGlobe';
import { buildAtlasData } from './atlas';
/**
* A stand-in for what useAtlasGlobe hands the phone Atlas: every field the
* mobile globe, its sheets and the hub tabs read, with spies for the actions.
* `t` echoes the key, followed by the parameter values, so a test names the
* contract rather than a locale string.
*/
export const echoT = (key: string, params?: Record<string, unknown>): string =>
params ? `${key}:${Object.values(params).join(',')}` : key;
/** A country's name as the fake resolves it: Iceland by its name, the rest as name-XX. */
export const fakeResolveName = (a2: string): string => (a2 === 'IS' ? 'Iceland' : `name-${a2}`);
export function buildBucketState(over: Record<string, unknown> = {}): Record<string, unknown> {
return {
bucketList: [],
setBucketList: vi.fn(),
showBucketAdd: false,
setShowBucketAdd: vi.fn(),
bucketForm: { name: '', notes: '', lat: '', lng: '', target_date: '' },
setBucketForm: vi.fn(),
bucketPoiYear: 0,
setBucketPoiYear: vi.fn(),
bucketPoiMonth: 0,
setBucketPoiMonth: vi.fn(),
resetBucketAdd: vi.fn(),
handleSelectBucketPoi: vi.fn(),
handleAddBucketItem: vi.fn(async () => undefined),
handleDeleteBucketItem: vi.fn(async () => undefined),
handleClearBucketVisit: vi.fn(async () => undefined),
...over,
};
}
export function buildGlobeState(over: Record<string, unknown> = {}): AtlasGlobeState {
const base: Record<string, unknown> = {
t: echoT,
language: 'en',
placeLang: 'en',
data: buildAtlasData(),
setData: vi.fn(),
totals: { countries: 1, continents: 1, regions: 0 },
badges: [],
resolveName: fakeResolveName,
// the hub
passportOpen: false,
setPassportOpen: vi.fn(),
passportTab: 'overview',
setPassportTab: vi.fn(),
openPassport: vi.fn(),
// dawarich
dawarichEnabled: false,
dawarichSub: 'wishes',
openDawarich: vi.fn(),
reload: vi.fn(async () => undefined),
// travellers
compareEnabled: false,
loadPeople: vi.fn(),
people: null,
ranking: null,
me: null,
hidden: false,
setHidden: vi.fn(),
profile: null,
setProfileId: vi.fn(),
startCompare: vi.fn(),
compareWith: null,
gaps: false,
setGaps: vi.fn(),
stopCompare: vi.fn(),
// the wishlist
bucketState: buildBucketState(),
bucket: [],
setBucket: vi.fn(),
handleDeleteBucketItem: vi.fn(async () => undefined),
flyToPoint: vi.fn(),
// country dialogs
confirmAction: null,
setConfirmAction: vi.fn(),
executeConfirmAction: vi.fn(async () => undefined),
closeDialogs: vi.fn(),
regions: {},
setRegions: vi.fn(),
detail: null,
progress: null,
askUnmarkDetail: vi.fn(),
// layers
showPlanned: false,
setShowPlanned: vi.fn(),
regionView: false,
setRegionView: vi.fn(),
flights: null,
showFlights: false,
setShowFlights: vi.fn(),
pluginLayers: [],
hiddenPluginLayers: new Set<string>(),
togglePluginLayer: vi.fn(),
colorMode: 'country',
setColorMode: vi.fn(),
// the globe itself
fetchJson: vi.fn(),
labelFor: vi.fn(),
labelRegionsOf: vi.fn(),
paint: vi.fn(),
paintKey: 'k',
onSelect: vi.fn(),
onReady: vi.fn(),
setError: vi.fn(),
pins: [],
};
return { ...base, ...over } as unknown as AtlasGlobeState;
}