@flighthq/permissions 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/permissions",
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,8 +38,8 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/log": "0.4.0-next.1903.50bfa67",
42
- "@flighthq/types": "0.4.0-next.1903.50bfa67"
41
+ "@flighthq/log": "0.4.0-next.1908.751021c",
42
+ "@flighthq/types": "0.4.0-next.1908.751021c"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.3.0"
@@ -12,6 +12,8 @@ import {
12
12
  resetPermissionBackendForTest,
13
13
  setPermissionBackend,
14
14
  setPermissionRequestFallbackGuard,
15
+ explainPermissionBackend,
16
+ observePermissionHostResult,
15
17
  } from './permission';
16
18
 
17
19
  // A recording mock backend: relays a fixed state and captures the last name each method saw.
@@ -202,6 +204,34 @@ describe('createWebPermissionBackend', () => {
202
204
  });
203
205
  });
204
206
 
207
+ describe('explainPermissionBackend', () => {
208
+ afterEach(() => resetPermissionBackendForTest());
209
+
210
+ it('reports host-not-enabled when no backend is installed', () => {
211
+ resetPermissionBackendForTest();
212
+ const explanation = explainPermissionBackend();
213
+ expect(explanation.layer).toBe('host-not-enabled');
214
+ expect(explanation.conflict).toBe(false);
215
+ expect(explanation.viability).toBe('unobserved');
216
+ });
217
+
218
+ it('reports custom layer when a custom backend is set', () => {
219
+ setPermissionBackend(fakeBackend('granted'));
220
+ expect(explainPermissionBackend().layer).toBe('custom');
221
+ });
222
+
223
+ it('reports host layer when a host backend is installed', () => {
224
+ installPermissionHostBackend(fakeBackend('granted'));
225
+ expect(explainPermissionBackend().layer).toBe('host');
226
+ });
227
+
228
+ it('reports conflict when two different host backends are installed', () => {
229
+ installPermissionHostBackend(fakeBackend('granted'));
230
+ installPermissionHostBackend(fakeBackend('granted'));
231
+ expect(explainPermissionBackend().conflict).toBe(true);
232
+ });
233
+ });
234
+
205
235
  describe('explainPermissionState', () => {
206
236
  afterEach(() => {
207
237
  setPermissionBackend(null);
@@ -289,6 +319,43 @@ describe('getPermissionStates', () => {
289
319
  });
290
320
  });
291
321
 
322
+ describe('installPermissionHostBackend', () => {
323
+ afterEach(() => resetPermissionBackendForTest());
324
+
325
+ it('installs a host backend that getPermissionBackend returns', () => {
326
+ const backend = fakeBackend('granted');
327
+ installPermissionHostBackend(backend);
328
+ expect(getPermissionBackend()).toBe(backend);
329
+ });
330
+
331
+ it('is first-host-wins: a second different backend sets conflict', () => {
332
+ const first = fakeBackend('granted');
333
+ const second = fakeBackend('granted');
334
+ installPermissionHostBackend(first);
335
+ installPermissionHostBackend(second);
336
+ expect(getPermissionBackend()).toBe(first);
337
+ expect(explainPermissionBackend().conflict).toBe(true);
338
+ });
339
+ });
340
+
341
+ describe('observePermissionHostResult', () => {
342
+ afterEach(() => resetPermissionBackendForTest());
343
+
344
+ it('records a successful observation', () => {
345
+ installPermissionHostBackend(fakeBackend('granted'));
346
+ observePermissionHostResult('getState', true);
347
+ const explanation = explainPermissionBackend();
348
+ expect(explanation.operation).toBe('getState');
349
+ expect(explanation.viability).toBe('available');
350
+ });
351
+
352
+ it('records a failed observation', () => {
353
+ installPermissionHostBackend(fakeBackend('granted'));
354
+ observePermissionHostResult('getState', false);
355
+ expect(explainPermissionBackend().viability).toBe('runtime-api-unavailable');
356
+ });
357
+ });
358
+
292
359
  describe('requestPermission', () => {
293
360
  it('dispatches to the active backend and relays the resolved state', async () => {
294
361
  const backend = fakeBackend('granted');
@@ -298,6 +365,18 @@ describe('requestPermission', () => {
298
365
  });
299
366
  });
300
367
 
368
+ describe('resetPermissionBackendForTest', () => {
369
+ it('clears all backend slots', () => {
370
+ setPermissionBackend(fakeBackend('granted'));
371
+ installPermissionHostBackend(fakeBackend('granted'));
372
+ observePermissionHostResult('getState', true);
373
+ resetPermissionBackendForTest();
374
+ expect(explainPermissionBackend().layer).toBe('host-not-enabled');
375
+ expect(explainPermissionBackend().conflict).toBe(false);
376
+ expect(explainPermissionBackend().viability).toBe('unobserved');
377
+ });
378
+ });
379
+
301
380
  describe('setPermissionBackend', () => {
302
381
  it('installs a backend and restores a fresh distinct web default on null', () => {
303
382
  const backend = fakeBackend('prompt');