|
| 1 | +import { expect, test } from 'vitest'; |
| 2 | +import type { DaemonRequest, DaemonResponse } from '../../../daemon/types.ts'; |
| 3 | +import type { ReplayVarScope } from '../../../replay/vars.ts'; |
| 4 | +import type { SnapshotState } from '../../../utils/snapshot.ts'; |
| 5 | +import { invokeMaestroTapOn } from '../runtime-interactions.ts'; |
| 6 | +import { rememberMaestroSnapshot } from '../runtime-support.ts'; |
| 7 | + |
| 8 | +test('invokeMaestroTapOn resolves mutating taps from a fresh snapshot instead of stale assertion cache', async () => { |
| 9 | + const scope: ReplayVarScope = { values: {} }; |
| 10 | + const selector = |
| 11 | + 'label="Article by Gandalf" || text="Article by Gandalf" || id="Article by Gandalf"'; |
| 12 | + rememberMaestroSnapshot(scope, staleLaunchSnapshot(), selector); |
| 13 | + |
| 14 | + const clicks: string[][] = []; |
| 15 | + const response = await invokeMaestroTapOn({ |
| 16 | + baseReq: { |
| 17 | + token: 'test', |
| 18 | + session: 'nav', |
| 19 | + flags: { platform: 'ios' }, |
| 20 | + }, |
| 21 | + positionals: [selector], |
| 22 | + scope, |
| 23 | + invoke: async (req: DaemonRequest): Promise<DaemonResponse> => { |
| 24 | + if (req.command === 'snapshot') return { ok: true, data: currentBreadcrumbSnapshot() }; |
| 25 | + if (req.command === 'click') { |
| 26 | + clicks.push(req.positionals ?? []); |
| 27 | + return { ok: true, data: {} }; |
| 28 | + } |
| 29 | + return { ok: false, error: { code: 'UNEXPECTED_COMMAND', message: req.command } }; |
| 30 | + }, |
| 31 | + }); |
| 32 | + |
| 33 | + expect(response.ok).toBe(true); |
| 34 | + expect(clicks).toEqual([['86', '89']]); |
| 35 | +}); |
| 36 | + |
| 37 | +function staleLaunchSnapshot(): SnapshotState { |
| 38 | + return { |
| 39 | + createdAt: Date.now(), |
| 40 | + nodes: [ |
| 41 | + appNode(), |
| 42 | + windowNode(), |
| 43 | + { |
| 44 | + index: 2, |
| 45 | + ref: 'e3', |
| 46 | + type: 'Other', |
| 47 | + label: 'Article by Gandalf', |
| 48 | + depth: 2, |
| 49 | + rect: { x: 0, y: 0, width: 402, height: 48 }, |
| 50 | + }, |
| 51 | + ], |
| 52 | + }; |
| 53 | +} |
| 54 | + |
| 55 | +function currentBreadcrumbSnapshot(): SnapshotState { |
| 56 | + return { |
| 57 | + createdAt: Date.now(), |
| 58 | + nodes: [ |
| 59 | + appNode(), |
| 60 | + windowNode(), |
| 61 | + { |
| 62 | + index: 2, |
| 63 | + ref: 'e3', |
| 64 | + type: 'ScrollView', |
| 65 | + label: 'Article by Gandalf', |
| 66 | + depth: 4, |
| 67 | + parentIndex: 1, |
| 68 | + rect: { x: 0, y: 58.33333333333333, width: 402, height: 58.33333333333333 }, |
| 69 | + }, |
| 70 | + { |
| 71 | + index: 3, |
| 72 | + ref: 'e4', |
| 73 | + type: 'Cell', |
| 74 | + label: 'Article by Gandalf', |
| 75 | + depth: 5, |
| 76 | + parentIndex: 2, |
| 77 | + rect: { x: 8, y: 65.33333587646484, width: 155, height: 48 }, |
| 78 | + }, |
| 79 | + ], |
| 80 | + }; |
| 81 | +} |
| 82 | + |
| 83 | +function appNode(): SnapshotState['nodes'][number] { |
| 84 | + return { |
| 85 | + index: 0, |
| 86 | + ref: 'e1', |
| 87 | + type: 'Application', |
| 88 | + label: 'React Navigation Example', |
| 89 | + depth: 0, |
| 90 | + rect: { x: 0, y: 0, width: 402, height: 874 }, |
| 91 | + }; |
| 92 | +} |
| 93 | + |
| 94 | +function windowNode(): SnapshotState['nodes'][number] { |
| 95 | + return { |
| 96 | + index: 1, |
| 97 | + ref: 'e2', |
| 98 | + type: 'Window', |
| 99 | + depth: 1, |
| 100 | + parentIndex: 0, |
| 101 | + rect: { x: 0, y: 0, width: 402, height: 874 }, |
| 102 | + }; |
| 103 | +} |
0 commit comments