mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
7104fa6dd4
Imports the picture icon the media sections draw for "use as the place picture", narrows the types the type check refused, moves the dropdown open state and the media lightbox into one module each for both views, replaces an await in a loop, and lowers the ratchet baselines to the counts the run measured. The tests follow the place view: the vote route of a trip place lives with the votes now, the history holds an entry per copy that followed an edit, the rate_library_place tool has its broadcast case, and the row tags of a list are dots behind the name.
294 lines
8.0 KiB
TypeScript
294 lines
8.0 KiB
TypeScript
import type {
|
|
PlacesLibraryDetail,
|
|
PlacesLibraryDetailResponse,
|
|
PlacesLibraryDuplicate,
|
|
PlacesLibraryDuplicateSide,
|
|
PlacesLibraryEntry,
|
|
PlacesLibraryInfo,
|
|
PlacesLibraryListDetail,
|
|
PlacesLibraryListOrigin,
|
|
PlacesLibraryPageResponse,
|
|
PlacesLibraryTripDetail,
|
|
PlacesLibraryTripOrigin,
|
|
} from '@trek/shared';
|
|
import { vi } from 'vitest';
|
|
|
|
import type { PlaceEditState } from '../../src/components/Collections/usePlaceEdit';
|
|
import type { PlaceSheetState } from '../../src/components/Collections/usePlaceSheet';
|
|
import type { usePlacesLibrary } from '../../src/components/Collections/usePlacesLibrary';
|
|
import type { PlaceTagsState } from '../../src/components/Collections/usePlaceTags';
|
|
|
|
/*
|
|
* Builders for "All places" (PLC-07, PLC-08): an entry with its origins, a page of
|
|
* them, and what each origin keeps of a place. One trip place 42 in "Rome 2026"
|
|
* and one saved place 900 in "Favourites", both the Colosseum, unless told otherwise.
|
|
*/
|
|
|
|
export function tripOrigin(over: Partial<PlacesLibraryTripOrigin> = {}): PlacesLibraryTripOrigin {
|
|
return {
|
|
kind: 'trip',
|
|
trip_id: 5,
|
|
trip_title: 'Rome 2026',
|
|
trip_start: null,
|
|
trip_end: null,
|
|
place_id: 42,
|
|
can_edit: true,
|
|
read_only: false,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function listOrigin(over: Partial<PlacesLibraryListOrigin> = {}): PlacesLibraryListOrigin {
|
|
return {
|
|
kind: 'list',
|
|
collection_id: 9,
|
|
collection_name: 'Favourites',
|
|
collection_place_id: 900,
|
|
status: 'want',
|
|
can_edit: true,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function libraryInfo(over: Partial<PlacesLibraryInfo> = {}): PlacesLibraryInfo {
|
|
return {
|
|
name: 'Colosseum',
|
|
address: 'Piazza del Colosseo',
|
|
lat: 41.89,
|
|
lng: 12.49,
|
|
description: null,
|
|
website: null,
|
|
phone: null,
|
|
image_url: null,
|
|
category: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function tripDetail(over: Partial<PlacesLibraryTripDetail> = {}): PlacesLibraryTripDetail {
|
|
return {
|
|
kind: 'trip',
|
|
place_id: 42,
|
|
info: libraryInfo(),
|
|
notes: null,
|
|
tags: [],
|
|
available_tags: [],
|
|
can_edit_tags: true,
|
|
rating: { average: null, count: 0, mine: null },
|
|
days: [],
|
|
has_accommodation: false,
|
|
has_reservation: false,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function listDetail(over: Partial<PlacesLibraryListDetail> = {}): PlacesLibraryListDetail {
|
|
return {
|
|
kind: 'list',
|
|
collection_place_id: 900,
|
|
info: libraryInfo(),
|
|
notes: null,
|
|
labels: [],
|
|
tags: [],
|
|
available_tags: [],
|
|
can_edit_tags: true,
|
|
rating: { average: null, count: 0, mine: null },
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function libraryEntry(over: Partial<PlacesLibraryEntry> = {}): PlacesLibraryEntry {
|
|
return {
|
|
key: 'trip:42',
|
|
name: 'Colosseum',
|
|
address: 'Piazza del Colosseo',
|
|
lat: 41.89,
|
|
lng: 12.49,
|
|
category: null,
|
|
image_url: null,
|
|
updated_at: null,
|
|
origins: [tripOrigin()],
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function libraryPage(
|
|
entries: PlacesLibraryEntry[],
|
|
over: Partial<PlacesLibraryPageResponse> = {}
|
|
): PlacesLibraryPageResponse {
|
|
return {
|
|
entries,
|
|
total: entries.length,
|
|
counts: { all: entries.length, trip: entries.length, list: 0 },
|
|
next_cursor: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** An entry with one detail per origin, in the order of its origins. */
|
|
export function libraryDetail(entry: PlacesLibraryEntry, details: PlacesLibraryDetail[]): PlacesLibraryDetailResponse {
|
|
return { entry, details };
|
|
}
|
|
|
|
/** The Colosseum in the trip and in a list, with what both keep of it. */
|
|
export function bothOrigins(over: Partial<PlacesLibraryEntry> = {}): PlacesLibraryDetailResponse {
|
|
const entry = libraryEntry({ origins: [tripOrigin(), listOrigin()], ...over });
|
|
return libraryDetail(entry, [tripDetail(), listDetail()]);
|
|
}
|
|
|
|
/** What usePlacesLibrary hands a view, for the view tests that mock the hook. */
|
|
export type PlacesLibraryState = ReturnType<typeof usePlacesLibrary>;
|
|
|
|
/** An idle "All places" with nothing loaded, every setter and action a mock. */
|
|
export function libraryState(over: Partial<PlacesLibraryState> = {}): PlacesLibraryState {
|
|
return {
|
|
search: '',
|
|
setSearch: vi.fn(),
|
|
kind: 'all',
|
|
setKind: vi.fn(),
|
|
categoryId: 'all',
|
|
setCategoryId: vi.fn(),
|
|
sort: 'name',
|
|
setSort: vi.fn(),
|
|
status: 'all',
|
|
setStatus: vi.fn(),
|
|
tagNames: [],
|
|
toggleTagName: vi.fn(),
|
|
minRating: 'all',
|
|
setMinRating: vi.fn(),
|
|
filtered: false,
|
|
resetFilters: vi.fn(),
|
|
entries: [],
|
|
mappable: [],
|
|
tagOptions: [],
|
|
total: 0,
|
|
counts: { all: 0, trip: 0, list: 0 },
|
|
hasMore: false,
|
|
loading: false,
|
|
loadingMore: false,
|
|
loadMore: vi.fn(() => Promise.resolve()),
|
|
error: null,
|
|
offline: false,
|
|
reload: vi.fn(),
|
|
selectedKey: null,
|
|
open: vi.fn(),
|
|
show: vi.fn(),
|
|
close: vi.fn(),
|
|
detail: null,
|
|
detailLoading: false,
|
|
cover: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** Three places: two in trips with a position, one saved without. */
|
|
export function threeEntries(): PlacesLibraryEntry[] {
|
|
return [
|
|
libraryEntry({
|
|
key: 'trip:1',
|
|
name: 'Pantheon',
|
|
address: 'Piazza della Rotonda',
|
|
origins: [tripOrigin({ place_id: 1 })],
|
|
}),
|
|
libraryEntry({
|
|
key: 'trip:2',
|
|
name: 'Trevi Fountain',
|
|
address: null,
|
|
origins: [tripOrigin({ place_id: 2 }), listOrigin({ collection_place_id: 20 })],
|
|
}),
|
|
libraryEntry({
|
|
key: 'list:30',
|
|
name: 'Secret garden',
|
|
address: null,
|
|
lat: null,
|
|
lng: null,
|
|
origins: [listOrigin({ collection_place_id: 30, collection_name: 'Wishlist' })],
|
|
}),
|
|
];
|
|
}
|
|
|
|
/** One side of a suggested pair: the Colosseum as one trip place, with its provider ids unset. */
|
|
export function duplicateSide(over: Partial<PlacesLibraryDuplicateSide> = {}): PlacesLibraryDuplicateSide {
|
|
return {
|
|
key: 'trip:42',
|
|
identity_id: null,
|
|
name: 'Colosseum',
|
|
address: 'Piazza del Colosseo',
|
|
lat: 41.89,
|
|
lng: 12.49,
|
|
category: null,
|
|
google_place_id: null,
|
|
google_ftid: null,
|
|
osm_id: null,
|
|
origins: [tripOrigin()],
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** A suggested pair: the trip's Colosseum and a saved "Colosseo", the same name nearby, mergeable. */
|
|
export function duplicatePair(over: Partial<PlacesLibraryDuplicate> = {}): PlacesLibraryDuplicate {
|
|
return {
|
|
a: duplicateSide(),
|
|
b: duplicateSide({ key: 'list:900', name: 'Colosseo', origins: [listOrigin()] }),
|
|
reasons: ['name_nearby'],
|
|
differing: ['name'],
|
|
can_merge: true,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* What usePlaceSheet hands the place views, on its overview with nothing in any
|
|
* tab. The parts are tokens only: the views that read them are mocked where this is used.
|
|
*/
|
|
export function placeSheetState(over: Partial<PlaceSheetState> = {}): PlaceSheetState {
|
|
const part = <K extends keyof PlaceSheetState>(name: K) => ({ part: name }) as unknown as PlaceSheetState[K];
|
|
return {
|
|
entry: libraryEntry(),
|
|
tab: 'overview',
|
|
setTab: vi.fn(),
|
|
counts: { overview: 0, notes: 0, activities: 0, media: 0, history: 0 },
|
|
empty: { overview: false, notes: false, activities: false, media: false, history: false },
|
|
visits: part('visits'),
|
|
notes: part('notes'),
|
|
activities: part('activities'),
|
|
history: part('history'),
|
|
media: part('media'),
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** What usePlaceTags hands the tag cards: no group and no picker open, every action a mock. */
|
|
export function placeTagsState(over: Partial<PlaceTagsState> = {}): PlaceTagsState {
|
|
return {
|
|
groups: [],
|
|
total: 0,
|
|
openKey: null,
|
|
openPicker: vi.fn(),
|
|
query: '',
|
|
setQuery: vi.fn(),
|
|
matches: [],
|
|
canCreate: false,
|
|
toggle: vi.fn(() => Promise.resolve()),
|
|
createAndAdd: vi.fn(() => Promise.resolve()),
|
|
busy: false,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** What usePlaceEdit hands the edit forms: not editing, nothing to edit, every action a mock. */
|
|
export function placeEditState(over: Partial<PlaceEditState> = {}): PlaceEditState {
|
|
return {
|
|
canEdit: false,
|
|
target: null,
|
|
editing: false,
|
|
draft: null,
|
|
set: vi.fn(),
|
|
start: vi.fn(),
|
|
cancel: vi.fn(),
|
|
save: vi.fn(() => Promise.resolve()),
|
|
saving: false,
|
|
...over,
|
|
};
|
|
}
|