|
| 1 | +import { expect, test } from 'vitest'; |
| 2 | +import type { RawSnapshotNode } from '@agent-device/kernel/snapshot'; |
| 3 | +import type { SnapshotCaptureProvenance } from '@agent-device/contracts/snapshot-model'; |
| 4 | +import { buildSnapshotState } from './snapshot-state.ts'; |
| 5 | + |
| 6 | +/** |
| 7 | + * A Flutter screen on iOS at the top of its content (#4451): the scroll view and its content are |
| 8 | + * siblings, and the content below the fold keeps a zero-area frame at the origin. |
| 9 | + */ |
| 10 | +function scrolledOutButtonTree(): RawSnapshotNode[] { |
| 11 | + return [ |
| 12 | + { index: 0, depth: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } }, |
| 13 | + { |
| 14 | + index: 1, |
| 15 | + depth: 1, |
| 16 | + parentIndex: 0, |
| 17 | + type: 'ScrollView', |
| 18 | + rect: { x: 0, y: 118, width: 402, height: 756 }, |
| 19 | + }, |
| 20 | + { |
| 21 | + index: 2, |
| 22 | + depth: 1, |
| 23 | + parentIndex: 0, |
| 24 | + type: 'StaticText', |
| 25 | + label: 'Tall block', |
| 26 | + rect: { x: 157, y: 546, width: 86, height: 27 }, |
| 27 | + }, |
| 28 | + { |
| 29 | + index: 3, |
| 30 | + depth: 1, |
| 31 | + parentIndex: 0, |
| 32 | + type: 'Button', |
| 33 | + label: 'View all', |
| 34 | + rect: { x: 0, y: 0, width: 0, height: 0 }, |
| 35 | + }, |
| 36 | + { index: 4, depth: 1, parentIndex: 0, type: 'StaticText', label: 'No frame' }, |
| 37 | + ]; |
| 38 | +} |
| 39 | + |
| 40 | +function hintsByNode(nodes: readonly RawSnapshotNode[]) { |
| 41 | + return nodes.map((node) => [node.label ?? node.type, node.presentationHints]); |
| 42 | +} |
| 43 | + |
| 44 | +const PROVENANCES: SnapshotCaptureProvenance[] = [ |
| 45 | + { backend: 'xctest', producer: 'apple-runner' }, |
| 46 | + { backend: 'android', producer: 'android-uiautomator' }, |
| 47 | +]; |
| 48 | + |
| 49 | +test.each(PROVENANCES)( |
| 50 | + 'marks a node published with a zero-area rect as unmeasured ($producer)', |
| 51 | + (provenance) => { |
| 52 | + const state = buildSnapshotState({ nodes: scrolledOutButtonTree(), ...provenance }, undefined); |
| 53 | + |
| 54 | + expect(hintsByNode(state.nodes)).toEqual([ |
| 55 | + ['Application', undefined], |
| 56 | + ['ScrollView', undefined], |
| 57 | + ['Tall block', undefined], |
| 58 | + ['View all', ['unmeasured']], |
| 59 | + // A node that reports no frame at all made no measurement to doubt. |
| 60 | + ['No frame', undefined], |
| 61 | + ]); |
| 62 | + }, |
| 63 | +); |
| 64 | + |
| 65 | +test('a raw snapshot keeps the reported nodes without the unmeasured mark', () => { |
| 66 | + const state = buildSnapshotState( |
| 67 | + { nodes: scrolledOutButtonTree(), backend: 'xctest', producer: 'apple-runner' }, |
| 68 | + { snapshotRaw: true }, |
| 69 | + ); |
| 70 | + |
| 71 | + expect(state.nodes.flatMap((node) => node.presentationHints ?? [])).toEqual([]); |
| 72 | +}); |
0 commit comments