|
| 1 | +import { test, vi } from 'vitest'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { handlePressCommand } from '../dispatch-interactions.ts'; |
| 4 | +import type { Interactor } from '../interactors.ts'; |
| 5 | +import { MACOS_DEVICE } from '../../__tests__/test-utils/device-fixtures.ts'; |
| 6 | + |
| 7 | +vi.mock('../../platforms/ios/macos-helper.ts', async (importOriginal) => { |
| 8 | + const actual = await importOriginal<typeof import('../../platforms/ios/macos-helper.ts')>(); |
| 9 | + return { |
| 10 | + ...actual, |
| 11 | + runMacOsPressAction: vi.fn(async () => ({})), |
| 12 | + }; |
| 13 | +}); |
| 14 | + |
| 15 | +import { runMacOsPressAction } from '../../platforms/ios/macos-helper.ts'; |
| 16 | + |
| 17 | +function makeUnusedInteractor(): Interactor { |
| 18 | + const fail = async () => { |
| 19 | + throw new Error('interactor should not be used for macOS menubar press'); |
| 20 | + }; |
| 21 | + return { |
| 22 | + open: fail, |
| 23 | + openDevice: fail, |
| 24 | + close: fail, |
| 25 | + tap: fail, |
| 26 | + doubleTap: fail, |
| 27 | + swipe: fail, |
| 28 | + longPress: fail, |
| 29 | + focus: fail, |
| 30 | + type: fail, |
| 31 | + fill: fail, |
| 32 | + scroll: fail, |
| 33 | + screenshot: fail, |
| 34 | + back: fail, |
| 35 | + home: fail, |
| 36 | + rotate: fail, |
| 37 | + appSwitcher: fail, |
| 38 | + readClipboard: fail, |
| 39 | + writeClipboard: fail, |
| 40 | + setSetting: fail, |
| 41 | + }; |
| 42 | +} |
| 43 | + |
| 44 | +test('handlePressCommand routes macOS menubar press through the helper', async () => { |
| 45 | + const mockRunMacOsPressAction = vi.mocked(runMacOsPressAction); |
| 46 | + mockRunMacOsPressAction.mockClear(); |
| 47 | + |
| 48 | + const result = await handlePressCommand( |
| 49 | + MACOS_DEVICE, |
| 50 | + makeUnusedInteractor(), |
| 51 | + ['100', '200'], |
| 52 | + { |
| 53 | + surface: 'menubar', |
| 54 | + appBundleId: 'com.example.menubarapp', |
| 55 | + }, |
| 56 | + {}, |
| 57 | + ); |
| 58 | + |
| 59 | + assert.deepEqual(result, { |
| 60 | + x: 100, |
| 61 | + y: 200, |
| 62 | + message: 'Tapped (100, 200)', |
| 63 | + }); |
| 64 | + assert.equal(mockRunMacOsPressAction.mock.calls.length, 1); |
| 65 | + assert.deepEqual(mockRunMacOsPressAction.mock.calls[0], [ |
| 66 | + 100, |
| 67 | + 200, |
| 68 | + { bundleId: 'com.example.menubarapp', surface: 'menubar' }, |
| 69 | + ]); |
| 70 | +}); |
0 commit comments