|
| 1 | +import AgentDeviceSnapshotPresentation |
| 2 | +import CoreGraphics |
| 3 | +import XCTest |
| 4 | + |
| 5 | +final class SnapshotVisibilityFoldTests: XCTestCase { |
| 6 | + func testFoldPreservesCapturedAttributesWhileReparentingClippingAndMergingHints() throws { |
| 7 | + let root = node(0, "Application", y: 0, height: 100, depth: 0, parent: nil) |
| 8 | + let dropped = node(1, "Other", y: 120, height: 10, depth: 1, parent: 0) |
| 9 | + let scroll = RawAXNode( |
| 10 | + index: 2, type: "ScrollView", label: "Results", identifier: "search-results", value: "loaded", |
| 11 | + placeholder: "Search", rect: SnapshotRect(x: 80, y: 20, width: 40, height: 60), |
| 12 | + enabled: true, focused: false, selected: true, hittable: nil, |
| 13 | + depth: 2, parentIndex: 1, hiddenContentAbove: true, hiddenContentBelow: false, |
| 14 | + actions: ["Refresh", "Jump"] |
| 15 | + ) |
| 16 | + |
| 17 | + for (hiddenY, expectedBelow) in [(0.0, nil as Bool?), (90.0, true as Bool?)] { |
| 18 | + let hidden = node(3, "Button", y: hiddenY, height: 10, depth: 3, parent: 2) |
| 19 | + let folded = SnapshotVisibilityFold.fold( |
| 20 | + [root, dropped, scroll, hidden], |
| 21 | + viewport: .reported(box: CGRect(x: 0, y: 0, width: 100, height: 100)), |
| 22 | + interactiveOnly: false, |
| 23 | + policy: .cursorProjected |
| 24 | + ) |
| 25 | + |
| 26 | + XCTAssertEqual(folded.count, 2) |
| 27 | + let presentation = try XCTUnwrap(folded.last) |
| 28 | + let raw = presentation.raw |
| 29 | + XCTAssertEqual(raw.index, 1) |
| 30 | + XCTAssertEqual(raw.depth, 1) |
| 31 | + XCTAssertEqual(raw.parentIndex, 0) |
| 32 | + XCTAssertEqual(raw.hittable, true) |
| 33 | + XCTAssertEqual(folded[0].raw.hittable, false) |
| 34 | + XCTAssertEqual(raw.hiddenContentAbove, true) |
| 35 | + XCTAssertEqual(raw.hiddenContentBelow, expectedBelow) |
| 36 | + XCTAssertEqual(presentation.effectiveRect, SnapshotRect(x: 80, y: 20, width: 20, height: 60)) |
| 37 | + XCTAssertEqual(raw.rect, scroll.rect) |
| 38 | + XCTAssertEqual(raw.type, scroll.type) |
| 39 | + XCTAssertEqual(raw.label, scroll.label) |
| 40 | + XCTAssertEqual(raw.identifier, scroll.identifier) |
| 41 | + XCTAssertEqual(raw.value, scroll.value) |
| 42 | + XCTAssertEqual(raw.placeholder, scroll.placeholder) |
| 43 | + XCTAssertEqual(raw.enabled, scroll.enabled) |
| 44 | + XCTAssertEqual(raw.focused, scroll.focused) |
| 45 | + XCTAssertEqual(raw.selected, scroll.selected) |
| 46 | + XCTAssertEqual(raw.actions, scroll.actions) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private func node( |
| 51 | + _ index: Int, _ type: String, y: Double, height: Double, depth: Int, parent: Int? |
| 52 | + ) -> RawAXNode { |
| 53 | + RawAXNode( |
| 54 | + index: index, type: type, label: nil, identifier: nil, value: nil, |
| 55 | + rect: SnapshotRect(x: 80, y: y, width: 20, height: height), |
| 56 | + enabled: true, focused: nil, selected: nil, hittable: false, |
| 57 | + depth: depth, parentIndex: parent, hiddenContentAbove: nil, hiddenContentBelow: nil |
| 58 | + ) |
| 59 | + } |
| 60 | +} |
0 commit comments