mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
4f8c3f045e
The Atlas page is now the globe. Everything the classic map offered carries over: visited countries and regions, planned countries, the wishlist with places and target dates, Dawarich, tours, plugin layers and the place search. New: - regions on the globe, with how much of a country has been seen (#2675, #316, #487) - flight arcs (#1369, #2642) - a hub with statistics, badges, wishlist, Dawarich, tours and travellers - an instance ranking, traveller profiles and a compare overlay - a timeline that plays back how the map grew - phone layouts of their own: sheets, chips and swipe actions The classic Leaflet Atlas and its phone screen are removed.
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
import { vi } from 'vitest';
|
|
import type { VisitStatus } from '@trek/shared';
|
|
import type { AtlasData, BucketItem } from '../../src/pages/atlas/atlasModel';
|
|
import type { AtlasCountryActionsOptions } from '../../src/pages/atlas/useAtlasCountryActions';
|
|
|
|
/**
|
|
* Fixtures for the atlas surfaces. The phone country popup takes the country
|
|
* actions' state and setters as one object, so tests build it here instead of
|
|
* mounting the globe behind it.
|
|
*
|
|
* The state setters are spies that also write the new value back onto the
|
|
* object (including updater callbacks), so a test can assert both "the
|
|
* setter was called" and "this is the state it produced".
|
|
*/
|
|
|
|
/** What the country popup reads: the country actions' options, the confirm step and the atlas data. */
|
|
export type AtlasPopupState = AtlasCountryActionsOptions & {
|
|
executeConfirmAction: () => void | Promise<void>;
|
|
data: AtlasData | null;
|
|
};
|
|
|
|
export type VisitedRegions = Record<
|
|
string,
|
|
{ code: string; name: string; placeCount: number; manuallyMarked?: boolean; status?: VisitStatus }[]
|
|
>;
|
|
|
|
const echoT = (key: string, params?: Record<string, string | number>): string =>
|
|
params ? `${key}:${Object.values(params).join(',')}` : key;
|
|
|
|
export function buildAtlasData(over: Partial<AtlasData> = {}): AtlasData {
|
|
return {
|
|
countries: [{ code: 'FR', tripCount: 2, placeCount: 5, firstVisit: '2023-01-01', lastVisit: '2024-06-01', status: 'visited' }],
|
|
stats: { totalTrips: 3, totalPlaces: 10, totalCountries: 1, totalDays: 14, totalCities: 3, totalCountriesPlanned: 0, totalCountriesIdea: 0 },
|
|
mostVisited: null,
|
|
continents: { Europe: 1 },
|
|
continentsPlanned: {},
|
|
lastTrip: { id: 7, title: 'Paris Trip', countryCode: 'FR' },
|
|
nextTrip: null,
|
|
streak: 2,
|
|
firstYear: 2022,
|
|
tripsThisYear: 1,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function buildBucketItem(over: Partial<BucketItem> = {}): BucketItem {
|
|
return {
|
|
id: 1,
|
|
name: 'Kyoto',
|
|
lat: null,
|
|
lng: null,
|
|
country_code: 'JP',
|
|
notes: null,
|
|
target_date: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** state field → its setter. */
|
|
const SETTERS: Record<string, string> = {
|
|
data: 'setData',
|
|
visitedRegions: 'setVisitedRegions',
|
|
bucketList: 'setBucketList',
|
|
confirmAction: 'setConfirmAction',
|
|
};
|
|
|
|
export function buildAtlasController(over: Record<string, unknown> = {}): AtlasPopupState {
|
|
const base: Record<string, unknown> = {
|
|
t: echoT,
|
|
data: buildAtlasData(),
|
|
visitedRegions: {} as VisitedRegions,
|
|
confirmAction: null,
|
|
executeConfirmAction: vi.fn(async () => undefined),
|
|
bucketList: [] as BucketItem[],
|
|
handleDeleteBucketItem: vi.fn(async () => undefined),
|
|
};
|
|
|
|
const ctrl: Record<string, unknown> = { ...base, ...over };
|
|
|
|
for (const [field, setter] of Object.entries(SETTERS)) {
|
|
if (setter in over) continue;
|
|
ctrl[setter] = vi.fn((next: unknown) => {
|
|
ctrl[field] = typeof next === 'function' ? (next as (prev: unknown) => unknown)(ctrl[field]) : next;
|
|
});
|
|
}
|
|
|
|
return ctrl as unknown as AtlasPopupState;
|
|
}
|