|
| 1 | +import { expect, test, vi } from 'vitest'; |
| 2 | +import { createLimrunIosInteractor, type LimrunIosSession } from './ios.ts'; |
| 3 | + |
| 4 | +function sessionWithClient() { |
| 5 | + const client = { |
| 6 | + tap: vi.fn(async () => {}), |
| 7 | + performActions: vi.fn(async () => ({ results: [] })), |
| 8 | + }; |
| 9 | + const session = { |
| 10 | + platform: 'ios', |
| 11 | + instanceId: 'limrun-long-press-instance', |
| 12 | + client, |
| 13 | + } as unknown as LimrunIosSession; |
| 14 | + return { interactor: createLimrunIosInteractor(session), client }; |
| 15 | +} |
| 16 | + |
| 17 | +test('long press holds one touch on the device for the requested duration', async () => { |
| 18 | + const { interactor, client } = sessionWithClient(); |
| 19 | + |
| 20 | + await interactor.longPress(120, 340, 1200); |
| 21 | + |
| 22 | + expect(client.performActions).toHaveBeenCalledTimes(1); |
| 23 | + expect(client.performActions).toHaveBeenCalledWith([ |
| 24 | + { type: 'touchDown', x: 120, y: 340 }, |
| 25 | + { type: 'wait', durationMs: 1200 }, |
| 26 | + { type: 'touchUp', x: 120, y: 340 }, |
| 27 | + ]); |
| 28 | + expect(client.tap).not.toHaveBeenCalled(); |
| 29 | +}); |
| 30 | + |
| 31 | +test('an omitted duration holds for the 800 ms the other interactors default to', async () => { |
| 32 | + const { interactor, client } = sessionWithClient(); |
| 33 | + |
| 34 | + await interactor.longPress(40, 60); |
| 35 | + |
| 36 | + expect(client.performActions).toHaveBeenCalledWith([ |
| 37 | + { type: 'touchDown', x: 40, y: 60 }, |
| 38 | + { type: 'wait', durationMs: 800 }, |
| 39 | + { type: 'touchUp', x: 40, y: 60 }, |
| 40 | + ]); |
| 41 | +}); |
| 42 | + |
| 43 | +test('a batch the device rejects surfaces as the long press failure', async () => { |
| 44 | + const { interactor, client } = sessionWithClient(); |
| 45 | + client.performActions.mockRejectedValueOnce(new Error('touchDown: no foreground application')); |
| 46 | + |
| 47 | + await expect(interactor.longPress(120, 340, 500)).rejects.toThrow( |
| 48 | + 'touchDown: no foreground application', |
| 49 | + ); |
| 50 | +}); |
0 commit comments