mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
82165855c7
- A list keeps its own order: drag a place by its grip (desktop and phone) or move it with the arrow keys. Reordering is off while a search or filter hides places and the list says why. New PUT /collections/:id/places/reorder and the MCP tool reorder_collection_places; new places go to the end. Client and server now order ties the same way (sort_order, oldest first, id). - Copying saved places into a trip no longer takes their notes and tags along unasked. The picker offers both; a tag taken along becomes a trip tag (a trip tag of the same name is reused), never someone's personal tag. - The source trip and place a saved place names are only kept when the user can open that trip and the place belongs to it. - A KML or KMZ map can be read into a list: the dialog lists every placemark to keep or leave out and says which entries were skipped and why (POST /collections/map/read writes nothing; the import does). - A saved place without coordinates says so and can be looked up on the map from its edit form, on the phone too, where a missing position could not be added at all. A typed address without a pick says it will not be on the map. - The trip map can show the place names beside the pins (desktop and phone, both renderers). Names that would cover another pin or a control give way, the selected place and the planned stops first.
94 lines
3.9 KiB
TypeScript
94 lines
3.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { mapsApi } from '../api/client';
|
|
import { isEffectivelyOffline } from '../sync/networkMode';
|
|
import { findOnMap, searchMapSpots, stayQueries } from './mapMatchRepo';
|
|
|
|
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn(() => false) }));
|
|
vi.mock('../api/client', () => ({ mapsApi: { search: vi.fn() } }));
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(isEffectivelyOffline).mockReturnValue(false);
|
|
vi.mocked(mapsApi.search).mockResolvedValue({ places: [] } as never);
|
|
});
|
|
|
|
describe('finding a stay on the map', () => {
|
|
it('FE-MAP-MATCH-001: asks name and address together, then the name, then the address, each once', () => {
|
|
expect(stayQueries('Hotel Gracery', '1-19-1 Kabukicho, Shinjuku')).toEqual([
|
|
'Hotel Gracery 1-19-1 Kabukicho, Shinjuku',
|
|
'Hotel Gracery',
|
|
'1-19-1 Kabukicho, Shinjuku',
|
|
]);
|
|
expect(stayQueries(' Hut ', null)).toEqual(['Hut']);
|
|
expect(stayQueries('', 'Main 1')).toEqual(['Main 1']);
|
|
expect(stayQueries('Inn', 'Inn')).toEqual(['Inn Inn', 'Inn']);
|
|
expect(stayQueries('', ' ')).toEqual([]);
|
|
});
|
|
|
|
it('FE-MAP-MATCH-002: a romanized address that finds nothing falls back to the hotel name', async () => {
|
|
vi.mocked(mapsApi.search).mockImplementation(async (query: string) =>
|
|
query === 'Hotel Gracery'
|
|
? ({
|
|
places: [{ name: 'Hotel Gracery Shinjuku', address: 'Kabukicho, Tokyo', lat: 35.69, lng: 139.7 }],
|
|
} as never)
|
|
: ({ places: [] } as never)
|
|
);
|
|
await expect(findOnMap(stayQueries('Hotel Gracery', '1-19-1 Kabukicho'), 'en')).resolves.toEqual({
|
|
lat: 35.69,
|
|
lng: 139.7,
|
|
label: 'Hotel Gracery Shinjuku, Kabukicho, Tokyo',
|
|
address: 'Kabukicho, Tokyo',
|
|
});
|
|
expect(vi.mocked(mapsApi.search).mock.calls.map(([q]) => q)).toEqual([
|
|
'Hotel Gracery 1-19-1 Kabukicho',
|
|
'Hotel Gracery',
|
|
]);
|
|
expect(mapsApi.search).toHaveBeenLastCalledWith('Hotel Gracery', 'en');
|
|
});
|
|
|
|
it('FE-MAP-MATCH-003: a row without coordinates is no match, and without a language the search is asked as before', async () => {
|
|
vi.mocked(mapsApi.search).mockResolvedValueOnce({
|
|
places: [
|
|
{ name: 'Nowhere', lat: null, lng: 2 },
|
|
{ name: 'Inn', lat: 1, lng: 2 },
|
|
],
|
|
} as never);
|
|
await expect(findOnMap(['Inn'])).resolves.toEqual({ lat: 1, lng: 2, label: 'Inn' });
|
|
expect(mapsApi.search).toHaveBeenCalledWith('Inn');
|
|
|
|
vi.mocked(mapsApi.search).mockResolvedValueOnce(undefined as never);
|
|
await expect(findOnMap(['Gone'])).resolves.toBeNull();
|
|
});
|
|
|
|
it('FE-MAP-MATCH-004: offline there is nothing to ask', async () => {
|
|
vi.mocked(isEffectivelyOffline).mockReturnValue(true);
|
|
await expect(findOnMap(['Hotel'])).resolves.toBeNull();
|
|
expect(mapsApi.search).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('searching spots to pick from', () => {
|
|
it('FE-MAP-MATCH-101: lists every hit with coordinates and leaves the others out', async () => {
|
|
vi.mocked(mapsApi.search).mockResolvedValue({
|
|
places: [
|
|
{ name: 'Kissa Sakaiki', address: 'Shibuya, Tokyo', lat: 35.66, lng: 139.7 },
|
|
{ name: 'No position', address: 'Somewhere' },
|
|
{ name: 'Null Island', lat: 0, lng: 0 },
|
|
],
|
|
} as never);
|
|
await expect(searchMapSpots(' kissa ', 'ja')).resolves.toEqual([
|
|
{ lat: 35.66, lng: 139.7, label: 'Kissa Sakaiki, Shibuya, Tokyo', address: 'Shibuya, Tokyo' },
|
|
{ lat: 0, lng: 0, label: 'Null Island' },
|
|
]);
|
|
expect(mapsApi.search).toHaveBeenCalledWith('kissa', 'ja');
|
|
});
|
|
|
|
it('FE-MAP-MATCH-102: a blank query or no connection asks nothing', async () => {
|
|
await expect(searchMapSpots(' ')).resolves.toEqual([]);
|
|
vi.mocked(isEffectivelyOffline).mockReturnValue(true);
|
|
await expect(searchMapSpots('Tokyo')).resolves.toEqual([]);
|
|
expect(mapsApi.search).not.toHaveBeenCalled();
|
|
});
|
|
});
|