mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(search): resolve two-dimensional geo URIs offline
This commit is contained in:
1 parent
591f299d11
commit
11bc2ec0ae
7 files changed
+198
-6
No files matched your search
@@ -9,6 +9,7 @@ import assert from 'node:assert/strict';
|
||||
import { createCoordinateGeocoder } from './coordinateGeocoder.js';
|
||||
import { createPresetGeocoder } from './presetGeocoder.js';
|
||||
import { createPlaceSearch } from './placeSearch.js';
|
||||
import { createDefaultPlaceSearch } from './defaults.js';
|
||||
|
||||
const PRESETS = {
|
||||
austin: {
|
||||
@@ -189,3 +190,52 @@ test('a cancelled search stops the offline providers too', async () => {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('default search resolves a geo URI exactly without requesting a geocoder', async () => {
|
||||
const requests = [];
|
||||
const search = createDefaultPlaceSearch({
|
||||
resolveApiKey: () => 'test-key',
|
||||
fetchImpl: async (url) => {
|
||||
requests.push(url);
|
||||
throw new Error('No network request should be needed');
|
||||
},
|
||||
});
|
||||
const { place, fallbackUsed } = await search.geocode(
|
||||
'geo:39.7392,-104.9903;crs=wgs84',
|
||||
);
|
||||
assert.deepEqual(requests, []);
|
||||
assert.equal(fallbackUsed, false);
|
||||
assert.equal(place.lat, 39.7392);
|
||||
assert.equal(place.lng, -104.9903);
|
||||
assert.equal(place.exact, true);
|
||||
assert.deepEqual(place.types, ['coordinate']);
|
||||
assert.ok(place.viewport.southwest.lat < place.lat);
|
||||
assert.ok(place.viewport.northeast.lat > place.lat);
|
||||
assert.ok(place.viewport.southwest.lng < place.lng);
|
||||
assert.ok(place.viewport.northeast.lng > place.lng);
|
||||
});
|
||||
|
||||
test('unsupported geo URIs reach the next search provider unchanged', async () => {
|
||||
const queries = [
|
||||
'geo:39.7392,-104.9903,1600',
|
||||
'geo:39.7392,-104.9903;u=10',
|
||||
'geo:39.7392,-104.9903;crs=unknown',
|
||||
'geo:0,0?q=Denver',
|
||||
];
|
||||
const received = [];
|
||||
const search = createPlaceSearch({
|
||||
providers: [
|
||||
createCoordinateGeocoder(),
|
||||
{
|
||||
async geocode(query) {
|
||||
received.push(query);
|
||||
return { place: null, answered: true };
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
for (const query of queries) {
|
||||
assert.equal((await search.geocode(query)).place, null);
|
||||
}
|
||||
assert.deepEqual(received, queries);
|
||||
});
|
||||
Reference in new issue
Block a user