@flighthq/share 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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/share.test.ts +79 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/share",
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/signals": "0.4.0-next.1903.50bfa67",
42
- "@flighthq/types": "0.4.0-next.1903.50bfa67"
41
+ "@flighthq/signals": "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"
package/src/share.test.ts CHANGED
@@ -19,6 +19,8 @@ import {
19
19
  shareFiles,
20
20
  shareText,
21
21
  shareUrl,
22
+ explainShareBackend,
23
+ observeShareHostResult,
22
24
  } from './share';
23
25
 
24
26
  function fakeBackend(
@@ -219,6 +221,34 @@ describe('enableShareSignals', () => {
219
221
  });
220
222
  });
221
223
 
224
+ describe('explainShareBackend', () => {
225
+ afterEach(() => resetShareBackendForTest());
226
+
227
+ it('reports host-not-enabled when no backend is installed', () => {
228
+ resetShareBackendForTest();
229
+ const explanation = explainShareBackend();
230
+ expect(explanation.layer).toBe('host-not-enabled');
231
+ expect(explanation.conflict).toBe(false);
232
+ expect(explanation.viability).toBe('unobserved');
233
+ });
234
+
235
+ it('reports custom layer when a custom backend is set', () => {
236
+ setShareBackend(fakeBackend());
237
+ expect(explainShareBackend().layer).toBe('custom');
238
+ });
239
+
240
+ it('reports host layer when a host backend is installed', () => {
241
+ installShareHostBackend(fakeBackend());
242
+ expect(explainShareBackend().layer).toBe('host');
243
+ });
244
+
245
+ it('reports conflict when two different host backends are installed', () => {
246
+ installShareHostBackend(fakeBackend());
247
+ installShareHostBackend(fakeBackend());
248
+ expect(explainShareBackend().conflict).toBe(true);
249
+ });
250
+ });
251
+
222
252
  describe('getShareBackend', () => {
223
253
  it('falls back to the sentinel when no backend is installed', () => {
224
254
  expect(getShareBackend()).not.toBeNull();
@@ -262,6 +292,25 @@ describe('hasShareContentFields', () => {
262
292
  });
263
293
  });
264
294
 
295
+ describe('installShareHostBackend', () => {
296
+ afterEach(() => resetShareBackendForTest());
297
+
298
+ it('installs a host backend that getShareBackend returns', () => {
299
+ const backend = fakeBackend();
300
+ installShareHostBackend(backend);
301
+ expect(getShareBackend()).toBe(backend);
302
+ });
303
+
304
+ it('is first-host-wins: a second different backend sets conflict', () => {
305
+ const first = fakeBackend();
306
+ const second = fakeBackend();
307
+ installShareHostBackend(first);
308
+ installShareHostBackend(second);
309
+ expect(getShareBackend()).toBe(first);
310
+ expect(explainShareBackend().conflict).toBe(true);
311
+ });
312
+ });
313
+
265
314
  describe('isShareAvailable', () => {
266
315
  it('returns false from the sentinel when no backend is installed', () => {
267
316
  expect(isShareAvailable()).toBe(false);
@@ -279,6 +328,36 @@ describe('isShareAvailable', () => {
279
328
  });
280
329
  });
281
330
 
331
+ describe('observeShareHostResult', () => {
332
+ afterEach(() => resetShareBackendForTest());
333
+
334
+ it('records a successful observation', () => {
335
+ installShareHostBackend(fakeBackend());
336
+ observeShareHostResult('canShare', true);
337
+ const explanation = explainShareBackend();
338
+ expect(explanation.operation).toBe('canShare');
339
+ expect(explanation.viability).toBe('available');
340
+ });
341
+
342
+ it('records a failed observation', () => {
343
+ installShareHostBackend(fakeBackend());
344
+ observeShareHostResult('canShare', false);
345
+ expect(explainShareBackend().viability).toBe('runtime-api-unavailable');
346
+ });
347
+ });
348
+
349
+ describe('resetShareBackendForTest', () => {
350
+ it('clears all backend slots', () => {
351
+ setShareBackend(fakeBackend());
352
+ installShareHostBackend(fakeBackend());
353
+ observeShareHostResult('canShare', true);
354
+ resetShareBackendForTest();
355
+ expect(explainShareBackend().layer).toBe('host-not-enabled');
356
+ expect(explainShareBackend().conflict).toBe(false);
357
+ expect(explainShareBackend().viability).toBe('unobserved');
358
+ });
359
+ });
360
+
282
361
  describe('setShareBackend', () => {
283
362
  it('clears back to the sentinel when passed null', () => {
284
363
  setShareBackend(fakeBackend());