On a real G2 a touch held slightly too long is reported as a long press (sysEvent type 9, then type 10 on release; source 1 right temple, 3 left), not as a tap, and was ignored. A long press now does what a tap does. If it started a recording and is held at least 700 ms, releasing it sends (push-to-talk); released sooner, it behaves like a tap and the recording continues until the next tap or press. Tests: 219 unit/integration; simulator 7 scenarios (long_press / long_press_release through the automation API). Not reviewed, not deployed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
83 lines
4.5 KiB
TypeScript
83 lines
4.5 KiB
TypeScript
import { evenHubEventFromJson, OsEventTypeList } from '@evenrealities/even_hub_sdk';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { normalizeEvent, OS_EVENT, type RawEvenHubEvent } from '../src/device/events.ts';
|
|
|
|
/**
|
|
* These run the published SDK's own parser (`evenHubEventFromJson`) over host
|
|
* payload shapes, then our normaliser. They verify our mapping against the SDK
|
|
* as shipped, not against a pair of glasses.
|
|
*/
|
|
const parse = (payload: unknown) => normalizeEvent(evenHubEventFromJson(payload) as RawEvenHubEvent);
|
|
|
|
describe('event constants', () => {
|
|
it('match the SDK enum', () => {
|
|
expect(OS_EVENT).toEqual({
|
|
CLICK: OsEventTypeList.CLICK_EVENT,
|
|
SCROLL_TOP: OsEventTypeList.SCROLL_TOP_EVENT,
|
|
SCROLL_BOTTOM: OsEventTypeList.SCROLL_BOTTOM_EVENT,
|
|
DOUBLE_CLICK: OsEventTypeList.DOUBLE_CLICK_EVENT,
|
|
FOREGROUND_ENTER: OsEventTypeList.FOREGROUND_ENTER_EVENT,
|
|
FOREGROUND_EXIT: OsEventTypeList.FOREGROUND_EXIT_EVENT,
|
|
ABNORMAL_EXIT: OsEventTypeList.ABNORMAL_EXIT_EVENT,
|
|
SYSTEM_EXIT: OsEventTypeList.SYSTEM_EXIT_EVENT,
|
|
IMU_DATA_REPORT: OsEventTypeList.IMU_DATA_REPORT,
|
|
LONG_PRESS: OsEventTypeList.LONG_PRESS_EVENT,
|
|
LONG_PRESS_RELEASE: OsEventTypeList.LONG_PRESS_RELEASE_EVENT,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('gestures through the SDK parser', () => {
|
|
it('a tap arrives with no eventType (protobuf omits zero) on either envelope', () => {
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventSource: 1 } })).toEqual([{ type: 'tap' }]);
|
|
expect(parse({ type: 'textEvent', jsonData: { containerID: 1, containerName: 'body' } })).toEqual([{ type: 'tap' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 0 } })).toEqual([{ type: 'tap' }]);
|
|
});
|
|
|
|
it('double tap, swipes and lifecycle map from sysEvent and textEvent', () => {
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 3 } })).toEqual([{ type: 'double_tap' }]);
|
|
expect(parse({ type: 'textEvent', jsonData: { eventType: 3 } })).toEqual([{ type: 'double_tap' }]);
|
|
expect(parse({ type: 'textEvent', jsonData: { eventType: 1 } })).toEqual([{ type: 'swipe_up' }]);
|
|
expect(parse({ type: 'textEvent', jsonData: { eventType: 2 } })).toEqual([{ type: 'swipe_down' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 'SCROLL_BOTTOM_EVENT' } })).toEqual([{ type: 'swipe_down' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 4 } })).toEqual([{ type: 'foreground_enter' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 5 } })).toEqual([{ type: 'foreground_exit' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 6 } })).toEqual([{ type: 'abnormal_exit' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 7 } })).toEqual([{ type: 'system_exit' }]);
|
|
});
|
|
|
|
it('ring and left-temple sources produce the same semantic gestures', () => {
|
|
for (const eventSource of [1, 2, 3]) {
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventSource } })).toEqual([{ type: 'tap' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventSource, eventType: 3 } })).toEqual([{ type: 'double_tap' }]);
|
|
}
|
|
});
|
|
|
|
it('audio frames are never mistaken for taps', () => {
|
|
const out = parse({ type: 'audioEvent', jsonData: { audioPcm: [1, 2, 3, 4] } });
|
|
expect(out).toHaveLength(1);
|
|
expect(out[0]!.type).toBe('audio');
|
|
expect(Array.from((out[0] as { pcm: Uint8Array }).pcm)).toEqual([1, 2, 3, 4]);
|
|
});
|
|
|
|
it('menu selections carry their item id and are not taps', () => {
|
|
expect(parse({ type: 'menuItemClickEvent', jsonData: { itemID: 2 } })).toEqual([{ type: 'menu', itemId: 2 }]);
|
|
});
|
|
|
|
it('IMU reports are outside the interaction contract', () => {
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 8, imuData: { x: 1, y: 2, z: 3 } } })).toEqual([]);
|
|
});
|
|
|
|
it('long press and its release are recognised (a real G2 reported a slow tap as type 9)', () => {
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 9, eventSource: 1 } })).toEqual([{ type: 'long_press' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 10, eventSource: 1 } })).toEqual([{ type: 'long_press_release' }]);
|
|
expect(parse({ type: 'textEvent', jsonData: { eventType: 9 } })).toEqual([{ type: 'long_press' }]);
|
|
expect(parse({ type: 'sysEvent', jsonData: { eventType: 'LONG_PRESS_EVENT' } })).toEqual([{ type: 'long_press' }]);
|
|
});
|
|
|
|
it('an empty or unknown event produces nothing', () => {
|
|
expect(normalizeEvent({})).toEqual([]);
|
|
expect(parse({ type: 'somethingNew', jsonData: {} })).toEqual([]);
|
|
});
|
|
});
|