Files
cinny/src/app/utils/haptics.test.ts
T
jaredandClaude Opus 5 492b57c60d feat(mobile): haptic tick on PTT press/release and on reactions (#125)
utils/haptics.ts: tick('ptt-on' | 'ptt-off' | 'reaction') → 10/10/8 ms
navigator.vibrate, a no-op without the API (iOS), when the system prefers
reduced motion, or when the new Settings → Calls "Haptic Feedback" switch
(default on, only rendered where the API exists) is off. PTT is observed
once through pttActiveAtom so the keyboard, global-hotkey and on-screen
paths all tick; reactions tick where the reaction event is sent in the
room and thread timelines (quick bar, hover bar, sheet and emoji board
all funnel there).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
2026-09-20 15:15:04 -04:00

34 lines
1.1 KiB
TypeScript

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;
});