@flighthq/haptics 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/haptics.test.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/haptics",
|
|
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/haptics.test.ts
CHANGED
|
@@ -19,6 +19,10 @@ import {
|
|
|
19
19
|
vibrateDevice,
|
|
20
20
|
vibrateDevicePattern,
|
|
21
21
|
vibrateDeviceWaveform,
|
|
22
|
+
explainHapticsBackend,
|
|
23
|
+
installHapticsHostBackend,
|
|
24
|
+
observeHapticsHostResult,
|
|
25
|
+
resetHapticsBackendForTest,
|
|
22
26
|
} from './haptics';
|
|
23
27
|
|
|
24
28
|
function makeCapabilities(overrides: Partial<HapticsCapabilities> = {}): HapticsCapabilities {
|
|
@@ -155,6 +159,34 @@ describe('createWebHapticsBackend', () => {
|
|
|
155
159
|
});
|
|
156
160
|
});
|
|
157
161
|
|
|
162
|
+
describe('explainHapticsBackend', () => {
|
|
163
|
+
afterEach(() => resetHapticsBackendForTest());
|
|
164
|
+
|
|
165
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
166
|
+
resetHapticsBackendForTest();
|
|
167
|
+
const explanation = explainHapticsBackend();
|
|
168
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
169
|
+
expect(explanation.conflict).toBe(false);
|
|
170
|
+
expect(explanation.viability).toBe('unobserved');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
174
|
+
setHapticsBackend(fakeBackend());
|
|
175
|
+
expect(explainHapticsBackend().layer).toBe('custom');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('reports host layer when a host backend is installed', () => {
|
|
179
|
+
installHapticsHostBackend(fakeBackend());
|
|
180
|
+
expect(explainHapticsBackend().layer).toBe('host');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
184
|
+
installHapticsHostBackend(fakeBackend());
|
|
185
|
+
installHapticsHostBackend(fakeBackend());
|
|
186
|
+
expect(explainHapticsBackend().conflict).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
158
190
|
describe('getHapticsBackend', () => {
|
|
159
191
|
it('falls back to a web backend', () => {
|
|
160
192
|
expect(getHapticsBackend()).not.toBeNull();
|
|
@@ -188,6 +220,25 @@ describe('getHapticsCapabilities', () => {
|
|
|
188
220
|
});
|
|
189
221
|
});
|
|
190
222
|
|
|
223
|
+
describe('installHapticsHostBackend', () => {
|
|
224
|
+
afterEach(() => resetHapticsBackendForTest());
|
|
225
|
+
|
|
226
|
+
it('installs a host backend that getHapticsBackend returns', () => {
|
|
227
|
+
const backend = fakeBackend();
|
|
228
|
+
installHapticsHostBackend(backend);
|
|
229
|
+
expect(getHapticsBackend()).toBe(backend);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
233
|
+
const first = fakeBackend();
|
|
234
|
+
const second = fakeBackend();
|
|
235
|
+
installHapticsHostBackend(first);
|
|
236
|
+
installHapticsHostBackend(second);
|
|
237
|
+
expect(getHapticsBackend()).toBe(first);
|
|
238
|
+
expect(explainHapticsBackend().conflict).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
191
242
|
describe('isHapticsSupported', () => {
|
|
192
243
|
it('returns true from fake backend', () => {
|
|
193
244
|
setHapticsBackend(fakeBackend());
|
|
@@ -199,6 +250,24 @@ describe('isHapticsSupported', () => {
|
|
|
199
250
|
});
|
|
200
251
|
});
|
|
201
252
|
|
|
253
|
+
describe('observeHapticsHostResult', () => {
|
|
254
|
+
afterEach(() => resetHapticsBackendForTest());
|
|
255
|
+
|
|
256
|
+
it('records a successful observation', () => {
|
|
257
|
+
installHapticsHostBackend(fakeBackend());
|
|
258
|
+
observeHapticsHostResult('cancel', true);
|
|
259
|
+
const explanation = explainHapticsBackend();
|
|
260
|
+
expect(explanation.operation).toBe('cancel');
|
|
261
|
+
expect(explanation.viability).toBe('available');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('records a failed observation', () => {
|
|
265
|
+
installHapticsHostBackend(fakeBackend());
|
|
266
|
+
observeHapticsHostResult('cancel', false);
|
|
267
|
+
expect(explainHapticsBackend().viability).toBe('runtime-api-unavailable');
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
202
271
|
describe('prepareHaptics', () => {
|
|
203
272
|
it('calls prepare on backends that provide it', () => {
|
|
204
273
|
const backend = fakeBackend();
|
|
@@ -216,6 +285,18 @@ describe('prepareHaptics', () => {
|
|
|
216
285
|
});
|
|
217
286
|
});
|
|
218
287
|
|
|
288
|
+
describe('resetHapticsBackendForTest', () => {
|
|
289
|
+
it('clears all backend slots', () => {
|
|
290
|
+
setHapticsBackend(fakeBackend());
|
|
291
|
+
installHapticsHostBackend(fakeBackend());
|
|
292
|
+
observeHapticsHostResult('cancel', true);
|
|
293
|
+
resetHapticsBackendForTest();
|
|
294
|
+
expect(explainHapticsBackend().layer).toBe('host-not-enabled');
|
|
295
|
+
expect(explainHapticsBackend().conflict).toBe(false);
|
|
296
|
+
expect(explainHapticsBackend().viability).toBe('unobserved');
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
219
300
|
describe('setHapticsBackend', () => {
|
|
220
301
|
it('clears back to the web fallback when passed null', () => {
|
|
221
302
|
setHapticsBackend(fakeBackend());
|