@flighthq/screen 0.4.0-next.1903.50bfa67 → 0.4.0-next.1909.c102f22
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 +3 -3
- package/src/screen.test.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/screen",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.1909.c102f22",
|
|
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.
|
|
42
|
-
"@flighthq/types": "0.4.0-next.
|
|
41
|
+
"@flighthq/signals": "0.4.0-next.1909.c102f22",
|
|
42
|
+
"@flighthq/types": "0.4.0-next.1909.c102f22"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
package/src/screen.test.ts
CHANGED
|
@@ -32,6 +32,10 @@ import {
|
|
|
32
32
|
screenToDipPoint,
|
|
33
33
|
screenToDipRect,
|
|
34
34
|
setScreenBackend,
|
|
35
|
+
explainScreenBackend,
|
|
36
|
+
installScreenHostBackend,
|
|
37
|
+
observeScreenHostResult,
|
|
38
|
+
resetScreenBackendForTest,
|
|
35
39
|
} from './screen';
|
|
36
40
|
function makeScreenInfo(overrides: Partial<ScreenInfo> = {}): ScreenInfo {
|
|
37
41
|
return { ...createScreenInfo(), ...overrides };
|
|
@@ -447,6 +451,33 @@ describe('enableScreenSignals', () => {
|
|
|
447
451
|
expect(signals.onScreenRemoved).toBeDefined();
|
|
448
452
|
});
|
|
449
453
|
});
|
|
454
|
+
describe('explainScreenBackend', () => {
|
|
455
|
+
afterEach(() => resetScreenBackendForTest());
|
|
456
|
+
|
|
457
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
458
|
+
resetScreenBackendForTest();
|
|
459
|
+
const explanation = explainScreenBackend();
|
|
460
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
461
|
+
expect(explanation.conflict).toBe(false);
|
|
462
|
+
expect(explanation.viability).toBe('unobserved');
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
466
|
+
setScreenBackend(fakeBackend([]));
|
|
467
|
+
expect(explainScreenBackend().layer).toBe('custom');
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('reports host layer when a host backend is installed', () => {
|
|
471
|
+
installScreenHostBackend(fakeBackend([]));
|
|
472
|
+
expect(explainScreenBackend().layer).toBe('host');
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
476
|
+
installScreenHostBackend(fakeBackend([]));
|
|
477
|
+
installScreenHostBackend(fakeBackend([]));
|
|
478
|
+
expect(explainScreenBackend().conflict).toBe(true);
|
|
479
|
+
});
|
|
480
|
+
});
|
|
450
481
|
describe('getPrimaryScreen', () => {
|
|
451
482
|
it('fills and returns the passed out object', () => {
|
|
452
483
|
setScreenBackend(fakeBackend([{ width: 1920, isPrimary: true }]));
|
|
@@ -729,6 +760,41 @@ describe('getScreenWorkArea', () => {
|
|
|
729
760
|
expect(out.height).toBe(1040);
|
|
730
761
|
});
|
|
731
762
|
});
|
|
763
|
+
describe('installScreenHostBackend', () => {
|
|
764
|
+
afterEach(() => resetScreenBackendForTest());
|
|
765
|
+
|
|
766
|
+
it('installs a host backend that getScreenBackend returns', () => {
|
|
767
|
+
const backend = fakeBackend([]);
|
|
768
|
+
installScreenHostBackend(backend);
|
|
769
|
+
expect(getScreenBackend()).toBe(backend);
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
773
|
+
const first = fakeBackend([]);
|
|
774
|
+
const second = fakeBackend([]);
|
|
775
|
+
installScreenHostBackend(first);
|
|
776
|
+
installScreenHostBackend(second);
|
|
777
|
+
expect(getScreenBackend()).toBe(first);
|
|
778
|
+
expect(explainScreenBackend().conflict).toBe(true);
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
describe('observeScreenHostResult', () => {
|
|
782
|
+
afterEach(() => resetScreenBackendForTest());
|
|
783
|
+
|
|
784
|
+
it('records a successful observation', () => {
|
|
785
|
+
installScreenHostBackend(fakeBackend([]));
|
|
786
|
+
observeScreenHostResult('getScreens', true);
|
|
787
|
+
const explanation = explainScreenBackend();
|
|
788
|
+
expect(explanation.operation).toBe('getScreens');
|
|
789
|
+
expect(explanation.viability).toBe('available');
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
it('records a failed observation', () => {
|
|
793
|
+
installScreenHostBackend(fakeBackend([]));
|
|
794
|
+
observeScreenHostResult('getScreens', false);
|
|
795
|
+
expect(explainScreenBackend().viability).toBe('runtime-api-unavailable');
|
|
796
|
+
});
|
|
797
|
+
});
|
|
732
798
|
describe('onScreenChange', () => {
|
|
733
799
|
it('delivers change events to the listener and unsubscribes', () => {
|
|
734
800
|
const backend = fakeBackend([{}]);
|
|
@@ -891,6 +957,19 @@ describe('requestScreenDetails', () => {
|
|
|
891
957
|
}
|
|
892
958
|
});
|
|
893
959
|
});
|
|
960
|
+
|
|
961
|
+
describe('resetScreenBackendForTest', () => {
|
|
962
|
+
it('clears all backend slots', () => {
|
|
963
|
+
setScreenBackend(fakeBackend([]));
|
|
964
|
+
installScreenHostBackend(fakeBackend([]));
|
|
965
|
+
observeScreenHostResult('getScreens', true);
|
|
966
|
+
resetScreenBackendForTest();
|
|
967
|
+
expect(explainScreenBackend().layer).toBe('host-not-enabled');
|
|
968
|
+
expect(explainScreenBackend().conflict).toBe(false);
|
|
969
|
+
expect(explainScreenBackend().viability).toBe('unobserved');
|
|
970
|
+
});
|
|
971
|
+
});
|
|
972
|
+
|
|
894
973
|
describe('screenToDipPoint', () => {
|
|
895
974
|
it('converts physical pixels to DIP', () => {
|
|
896
975
|
const screen = makeScreenInfo({ x: 0, y: 0, scaleFactor: 2 });
|
|
@@ -927,6 +1006,7 @@ describe('screenToDipPoint', () => {
|
|
|
927
1006
|
expect(recovered.y).toBeCloseTo(original.y);
|
|
928
1007
|
});
|
|
929
1008
|
});
|
|
1009
|
+
|
|
930
1010
|
describe('screenToDipRect', () => {
|
|
931
1011
|
it('scales the rect back to DIP', () => {
|
|
932
1012
|
const screen = makeScreenInfo({ x: 0, y: 0, scaleFactor: 2 });
|
|
@@ -961,6 +1041,7 @@ describe('screenToDipRect', () => {
|
|
|
961
1041
|
expect(recovered.height).toBeCloseTo(original.height);
|
|
962
1042
|
});
|
|
963
1043
|
});
|
|
1044
|
+
|
|
964
1045
|
describe('setScreenBackend', () => {
|
|
965
1046
|
it('clears back to the web fallback when passed null', () => {
|
|
966
1047
|
setScreenBackend(fakeBackend([{}]));
|