@flighthq/geolocation 0.4.0-next.1903.50bfa67 → 0.4.0-next.1908.751021c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/geolocation",
3
- "version": "0.4.0-next.1903.50bfa67",
3
+ "version": "0.4.0-next.1908.751021c",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/types": "0.4.0-next.1903.50bfa67"
41
+ "@flighthq/types": "0.4.0-next.1908.751021c"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "^5.3.0"
@@ -18,6 +18,10 @@ import {
18
18
  requestGeolocationPermission,
19
19
  setGeolocationBackend,
20
20
  watchGeolocationPosition,
21
+ explainGeolocationBackend,
22
+ installGeolocationHostBackend,
23
+ observeGeolocationHostResult,
24
+ resetGeolocationBackendForTest,
21
25
  } from './geolocation';
22
26
 
23
27
  function fakeBackend(): GeolocationBackend & { cleared: number[]; lastWatch: number } {
@@ -157,6 +161,34 @@ describe('createWebGeolocationBackend', () => {
157
161
  });
158
162
  });
159
163
 
164
+ describe('explainGeolocationBackend', () => {
165
+ afterEach(() => resetGeolocationBackendForTest());
166
+
167
+ it('reports host-not-enabled when no backend is installed', () => {
168
+ resetGeolocationBackendForTest();
169
+ const explanation = explainGeolocationBackend();
170
+ expect(explanation.layer).toBe('host-not-enabled');
171
+ expect(explanation.conflict).toBe(false);
172
+ expect(explanation.viability).toBe('unobserved');
173
+ });
174
+
175
+ it('reports custom layer when a custom backend is set', () => {
176
+ setGeolocationBackend(fakeBackend());
177
+ expect(explainGeolocationBackend().layer).toBe('custom');
178
+ });
179
+
180
+ it('reports host layer when a host backend is installed', () => {
181
+ installGeolocationHostBackend(fakeBackend());
182
+ expect(explainGeolocationBackend().layer).toBe('host');
183
+ });
184
+
185
+ it('reports conflict when two different host backends are installed', () => {
186
+ installGeolocationHostBackend(fakeBackend());
187
+ installGeolocationHostBackend(fakeBackend());
188
+ expect(explainGeolocationBackend().conflict).toBe(true);
189
+ });
190
+ });
191
+
160
192
  describe('getCurrentGeoPosition', () => {
161
193
  it('returns the backend position', async () => {
162
194
  setGeolocationBackend(fakeBackend());
@@ -206,6 +238,25 @@ describe('getGeolocationPermission', () => {
206
238
  });
207
239
  });
208
240
 
241
+ describe('installGeolocationHostBackend', () => {
242
+ afterEach(() => resetGeolocationBackendForTest());
243
+
244
+ it('installs a host backend that getGeolocationBackend returns', () => {
245
+ const backend = fakeBackend();
246
+ installGeolocationHostBackend(backend);
247
+ expect(getGeolocationBackend()).toBe(backend);
248
+ });
249
+
250
+ it('is first-host-wins: a second different backend sets conflict', () => {
251
+ const first = fakeBackend();
252
+ const second = fakeBackend();
253
+ installGeolocationHostBackend(first);
254
+ installGeolocationHostBackend(second);
255
+ expect(getGeolocationBackend()).toBe(first);
256
+ expect(explainGeolocationBackend().conflict).toBe(true);
257
+ });
258
+ });
259
+
209
260
  describe('isGeolocationAvailable', () => {
210
261
  it('returns a boolean', () => {
211
262
  expect(typeof isGeolocationAvailable()).toBe('boolean');
@@ -217,6 +268,24 @@ describe('isGeolocationAvailable', () => {
217
268
  });
218
269
  });
219
270
 
271
+ describe('observeGeolocationHostResult', () => {
272
+ afterEach(() => resetGeolocationBackendForTest());
273
+
274
+ it('records a successful observation', () => {
275
+ installGeolocationHostBackend(fakeBackend());
276
+ observeGeolocationHostResult('clearWatch', true);
277
+ const explanation = explainGeolocationBackend();
278
+ expect(explanation.operation).toBe('clearWatch');
279
+ expect(explanation.viability).toBe('available');
280
+ });
281
+
282
+ it('records a failed observation', () => {
283
+ installGeolocationHostBackend(fakeBackend());
284
+ observeGeolocationHostResult('clearWatch', false);
285
+ expect(explainGeolocationBackend().viability).toBe('runtime-api-unavailable');
286
+ });
287
+ });
288
+
220
289
  describe('onGeolocationPermissionChange', () => {
221
290
  it('returns an unsubscribe function', () => {
222
291
  const unsubscribe = onGeolocationPermissionChange(() => {});
@@ -253,6 +322,18 @@ describe('requestGeolocationPermission', () => {
253
322
  });
254
323
  });
255
324
 
325
+ describe('resetGeolocationBackendForTest', () => {
326
+ it('clears all backend slots', () => {
327
+ setGeolocationBackend(fakeBackend());
328
+ installGeolocationHostBackend(fakeBackend());
329
+ observeGeolocationHostResult('clearWatch', true);
330
+ resetGeolocationBackendForTest();
331
+ expect(explainGeolocationBackend().layer).toBe('host-not-enabled');
332
+ expect(explainGeolocationBackend().conflict).toBe(false);
333
+ expect(explainGeolocationBackend().viability).toBe('unobserved');
334
+ });
335
+ });
336
+
256
337
  describe('setGeolocationBackend', () => {
257
338
  it('clears back to the web fallback when passed null', () => {
258
339
  setGeolocationBackend(fakeBackend());