@flighthq/dialog 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 +2 -2
- package/src/dialog.test.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/dialog",
|
|
3
|
-
"version": "0.4.0-next.
|
|
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.
|
|
41
|
+
"@flighthq/types": "0.4.0-next.1908.751021c"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "^5.3.0"
|
package/src/dialog.test.ts
CHANGED
|
@@ -16,6 +16,10 @@ import {
|
|
|
16
16
|
showPromptDialog,
|
|
17
17
|
showSaveFileDialog,
|
|
18
18
|
showWarningDialog,
|
|
19
|
+
explainDialogBackend,
|
|
20
|
+
installDialogHostBackend,
|
|
21
|
+
observeDialogHostResult,
|
|
22
|
+
resetDialogBackendForTest,
|
|
19
23
|
} from './dialog';
|
|
20
24
|
|
|
21
25
|
function fakeHandle(name: string): FileDialogHandle {
|
|
@@ -105,6 +109,34 @@ describe('createWebDialogBackend', () => {
|
|
|
105
109
|
});
|
|
106
110
|
});
|
|
107
111
|
|
|
112
|
+
describe('explainDialogBackend', () => {
|
|
113
|
+
afterEach(() => resetDialogBackendForTest());
|
|
114
|
+
|
|
115
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
116
|
+
resetDialogBackendForTest();
|
|
117
|
+
const explanation = explainDialogBackend();
|
|
118
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
119
|
+
expect(explanation.conflict).toBe(false);
|
|
120
|
+
expect(explanation.viability).toBe('unobserved');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
124
|
+
setDialogBackend(fakeBackend());
|
|
125
|
+
expect(explainDialogBackend().layer).toBe('custom');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('reports host layer when a host backend is installed', () => {
|
|
129
|
+
installDialogHostBackend(fakeBackend());
|
|
130
|
+
expect(explainDialogBackend().layer).toBe('host');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
134
|
+
installDialogHostBackend(fakeBackend());
|
|
135
|
+
installDialogHostBackend(fakeBackend());
|
|
136
|
+
expect(explainDialogBackend().conflict).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
108
140
|
describe('getDialogBackend', () => {
|
|
109
141
|
it('falls back to a web backend when none is set', () => {
|
|
110
142
|
expect(getDialogBackend()).not.toBeNull();
|
|
@@ -131,6 +163,55 @@ describe('getWebFileSystemHandle', () => {
|
|
|
131
163
|
});
|
|
132
164
|
});
|
|
133
165
|
|
|
166
|
+
describe('installDialogHostBackend', () => {
|
|
167
|
+
afterEach(() => resetDialogBackendForTest());
|
|
168
|
+
|
|
169
|
+
it('installs a host backend that getDialogBackend returns', () => {
|
|
170
|
+
const backend = fakeBackend();
|
|
171
|
+
installDialogHostBackend(backend);
|
|
172
|
+
expect(getDialogBackend()).toBe(backend);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
176
|
+
const first = fakeBackend();
|
|
177
|
+
const second = fakeBackend();
|
|
178
|
+
installDialogHostBackend(first);
|
|
179
|
+
installDialogHostBackend(second);
|
|
180
|
+
expect(getDialogBackend()).toBe(first);
|
|
181
|
+
expect(explainDialogBackend().conflict).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('observeDialogHostResult', () => {
|
|
186
|
+
afterEach(() => resetDialogBackendForTest());
|
|
187
|
+
|
|
188
|
+
it('records a successful observation', () => {
|
|
189
|
+
installDialogHostBackend(fakeBackend());
|
|
190
|
+
observeDialogHostResult('confirm', true);
|
|
191
|
+
const explanation = explainDialogBackend();
|
|
192
|
+
expect(explanation.operation).toBe('confirm');
|
|
193
|
+
expect(explanation.viability).toBe('available');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('records a failed observation', () => {
|
|
197
|
+
installDialogHostBackend(fakeBackend());
|
|
198
|
+
observeDialogHostResult('confirm', false);
|
|
199
|
+
expect(explainDialogBackend().viability).toBe('runtime-api-unavailable');
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('resetDialogBackendForTest', () => {
|
|
204
|
+
it('clears all backend slots', () => {
|
|
205
|
+
setDialogBackend(fakeBackend());
|
|
206
|
+
installDialogHostBackend(fakeBackend());
|
|
207
|
+
observeDialogHostResult('confirm', true);
|
|
208
|
+
resetDialogBackendForTest();
|
|
209
|
+
expect(explainDialogBackend().layer).toBe('host-not-enabled');
|
|
210
|
+
expect(explainDialogBackend().conflict).toBe(false);
|
|
211
|
+
expect(explainDialogBackend().viability).toBe('unobserved');
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
134
215
|
describe('setDialogBackend', () => {
|
|
135
216
|
it('clears back to the web fallback when passed null', () => {
|
|
136
217
|
setDialogBackend(fakeBackend());
|