Files
cinny/src/app/utils/haptics.test.ts
T

34 lines
1.1 KiB
TypeScript
Raw Normal View History

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { hapticsSupported, tick } from './haptics';
const g = globalThis as { navigator?: unknown; window?: unknown };
test('tick is a no-op without the API, with the setting off, or under reduced motion', () => {
g.navigator = {};
assert.equal(hapticsSupported(), false);
assert.equal(tick('ptt-on'), false);
const calls: number[] = [];
g.navigator = { vibrate: (ms: number) => calls.push(ms) === 1 };
g.window = { matchMedia: () => ({ matches: true }) };
assert.equal(tick('ptt-on'), false);
assert.deepEqual(calls, []);
g.window = { matchMedia: () => ({ matches: false }) };
assert.equal(tick('ptt-on', false), false);
assert.deepEqual(calls, []);
});
test('tick vibrates per kind when allowed', () => {
const calls: number[] = [];
g.navigator = { vibrate: (ms: number) => calls.push(ms) > 0 };
g.window = { matchMedia: () => ({ matches: false }) };
assert.equal(tick('ptt-on'), true);
assert.equal(tick('ptt-off'), true);
assert.equal(tick('reaction'), true);
assert.deepEqual(calls, [10, 10, 8]);
delete g.navigator;
delete g.window;
});