Skip to content

Commit fd3ae05

Browse files
committed
fix(ios): count a placeholder as content, keep value and placeholder apart in the tests
Review follow-ups: the collapsed-tab producer read the placeholder only after its content check, so a placeholder-only field inside a collapsed container was dropped; the placeholder now counts as content. The bridge test used one string for value and placeholder, so it could not tell the two attributes apart; it uses distinct strings and asserts both. A wire-shape test pins that a node without a placeholder encodes no key. The docs stop calling a value equal to the placeholder an empty field, since a user can type that text.
1 parent 80aa8df commit fd3ae05

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ extension RunnerTests {
387387
let label = element.label.trimmingCharacters(in: .whitespacesAndNewlines)
388388
let identifier = element.identifier.trimmingCharacters(in: .whitespacesAndNewlines)
389389
let valueText = snapshotValueText(element)
390-
let hasContent = !label.isEmpty || !identifier.isEmpty || valueText != nil
390+
let placeholder = placeholderText(element.placeholderValue)
391+
let hasContent = !label.isEmpty || !identifier.isEmpty || valueText != nil || placeholder != nil
391392
if !hasContent { return }
392393
if sameSemanticElement(
393394
containerSnapshot: containerSnapshot,
@@ -406,7 +407,7 @@ extension RunnerTests {
406407
label: label.isEmpty ? nil : label,
407408
identifier: identifier.isEmpty ? nil : identifier,
408409
value: valueText,
409-
placeholder: placeholderText(element.placeholderValue),
410+
placeholder: placeholder,
410411
rect: SnapshotRect(frame),
411412
enabled: element.isEnabled,
412413
focused: elementHasFocus(element) ? true : nil,

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SnapshotPresentationTests.swift‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ extension RunnerTests {
6363
XCTAssertEqual(capture.customActions?.candidates, 2)
6464
}
6565

66+
/// A node without a placeholder omits the key: the wire contract is "absent when empty", which
67+
/// the synthesized `encodeIfPresent` provides today and a hand-written encoder must keep.
68+
func testPresentedNodeOmitsAnAbsentPlaceholder() throws {
69+
let raw = RawAXNode(
70+
index: 0,
71+
type: "Button",
72+
label: "Save",
73+
identifier: nil,
74+
value: nil,
75+
rect: SnapshotRect(x: 0, y: 0, width: 100, height: 44),
76+
enabled: true,
77+
focused: nil,
78+
selected: nil,
79+
hittable: true,
80+
depth: 0,
81+
parentIndex: nil,
82+
hiddenContentAbove: nil,
83+
hiddenContentBelow: nil
84+
)
85+
let capture = try XCTUnwrap(try SnapshotPresentation.present(
86+
SnapshotAcquisition(
87+
hint: CaptureHint(
88+
projection: .raw, depth: nil, regularPresentedDepth: nil,
89+
interactiveOnly: false, customActions: false),
90+
nodes: [raw],
91+
truncated: false,
92+
effectiveDepth: nil,
93+
customActions: nil,
94+
viewport: .reported(box: CGRect(x: 0, y: 0, width: 100, height: 100))
95+
),
96+
options: PresentationOptions(interactiveOnly: false, depth: nil, scope: nil, raw: true)
97+
))
98+
let encoded = String(decoding: try JSONEncoder().encode(capture.nodes), as: UTF8.self)
99+
100+
XCTAssertNil(capture.nodes.first?.placeholder)
101+
XCTAssertFalse(encoded.contains("placeholder"), encoded)
102+
}
103+
66104
func testSnapshotPresentationOwnsBackendNeutralEligibility() throws {
67105
// Non-vacuity: forcing `isEligibleForRegularPresentation` to return true made this test execute
68106
// once and fail exactly four membership/index/depth/parent assertions before restoration.

‎packages/platform-apple/src/snapshot-source/tree.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ test('the bridge tree carries a text field placeholder and omits an empty one',
468468
const field = (placeholder?: unknown) => ({
469469
[application]: 'UITextField',
470470
[frame]: { X: 16, Y: 200, Width: 370, Height: 44 },
471-
XC_kAXXCAttributeValue: 'Type your name',
471+
XC_kAXXCAttributeValue: 'Ada Lovelace',
472472
...(placeholder === undefined ? {} : { XC_kAXXCAttributePlaceholderValue: placeholder }),
473473
[children]: [],
474474
});
@@ -479,7 +479,9 @@ test('the bridge tree carries a text field placeholder and omits an empty one',
479479
limits,
480480
).nodes[1];
481481

482-
assert.equal(decode('Type your name')?.placeholder, 'Type your name');
482+
const filled = decode('Type your name');
483+
assert.equal(filled?.placeholder, 'Type your name');
484+
assert.equal(filled?.value, 'Ada Lovelace', 'the value and the placeholder are separate facts');
483485
assert.equal(decode('')?.placeholder, undefined, 'no placeholder reads as none, not as ""');
484486
assert.equal(decode()?.placeholder, undefined, 'an unread fact stays unknown');
485487
});

‎website/docs/docs/snapshots.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ them. Explicit `false` and `0` are kept; an absent field means the fact was unav
151151
empty field shows it (`hintShowing: true`, and `value` repeats it), a filled field no longer does.
152152
A field without a hint omits it. iOS nodes carry the same fact from the field's
153153
`placeholderValue`, on every producer (the XCTest tree, the Simulator AX bridge, and the runner's
154-
private-AX reader); XCTest reports an empty field's placeholder as its `value` too, so a `value`
155-
equal to `placeholder` is an empty field.
154+
private-AX reader). XCTest reports an empty field's placeholder as its `value` too, so a `value`
155+
equal to `placeholder` is either an empty field or one holding exactly that text; equality alone
156+
cannot tell them apart.
156157
- `selectionStart`/`selectionEnd` are accessibility selection offsets. They are independent of
157158
`editable` (read-only selectable text exposes them too), they are not a character count, and
158159
they do not prove that a masked or secure value equals expected text.

0 commit comments

Comments
 (0)