mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
b80fdf27f2
An imported hotel was looked up once, by its name and its address together. A booking site's romanized address (Agoda for a stay in Japan) often matches nothing and sank the hotel's name with it, so the place was created without coordinates and silently never showed on the map. The review now finds the stay right away (name and address, then the name, then the address) and says under the address whether it is on the map and where, or that it is not yet, with a way to search again. Picking an address suggestion sets the spot by hand. The save uses that spot, falls back the same way when there is none, and a stay saved without a spot says so in a toast. Desktop dialog and phone sheet share the lookup through useReservationForm.
70 lines
2.8 KiB
TypeScript
70 lines
2.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { mapsApi } from '../api/client';
|
|
import { isEffectivelyOffline } from '../sync/networkMode';
|
|
import { findOnMap, 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();
|
|
});
|
|
});
|