Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/selectors/src/internal/match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ test('focused selector matches snapshot focus state', () => {
assert.equal(resolved.node.ref, 'tv2');
});

test('editable selector follows a published editable fact and infers from type without one', () => {
const nodes: SnapshotState['nodes'] = [
{ ref: 'e1', index: 0, type: 'com.example.RichEditor', label: 'Custom', editable: true },
{ ref: 'e2', index: 1, type: 'android.widget.EditText', label: 'ReadOnly', editable: false },
{ ref: 'e3', index: 2, type: 'android.widget.EditText', label: 'Disabled', enabled: false },
{ ref: 'e4', index: 3, type: 'android.widget.EditText', label: 'Inferred' },
{ ref: 'e5', index: 4, type: 'android.widget.TextView', label: 'Plain' },
];
const labelsMatching = (selector: string) =>
nodes
.filter((node) =>
resolveSelectorChain([node], parseSelectorChain(selector), { platform: 'android' }),
)
.map((node) => node.label);

assert.deepEqual(labelsMatching('editable=true'), ['Custom', 'Inferred']);
assert.deepEqual(labelsMatching('editable=false'), ['ReadOnly', 'Disabled', 'Plain']);
});

// ── appName / windowTitle selectors ──────────────────────────────────────

test('appName selector matches nodes with appName field', () => {
Expand Down
24 changes: 23 additions & 1 deletion packages/selectors/src/internal/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import assert from 'node:assert/strict';
import { test } from 'vitest';
import { attachRefs, formatRole, type SnapshotNode } from '@agent-device/kernel/snapshot';
import { normalizeType } from '@agent-device/contracts/snapshot';
import { roleSpellingsOfNode } from './node.ts';
import { isNodeEditable, roleSpellingsOfNode } from './node.ts';

function bareNode(type: string): SnapshotNode {
return { index: 0, ref: 'e1', type, kind: formatRole(type) };
Expand Down Expand Up @@ -153,3 +153,25 @@ test('the window IS normalizeType: drift in the owner moves the window and the r
}
}
});

test('isNodeEditable lets a published editable fact decide over the type', () => {
const customView: SnapshotNode = { ...bareNode('com.example.RichEditor'), editable: true };
const readOnlyField: SnapshotNode = { ...bareNode('android.widget.EditText'), editable: false };
assert.equal(isNodeEditable(customView, 'android'), true);
assert.equal(isNodeEditable(readOnlyField, 'android'), false);
});

test('isNodeEditable keeps the disabled refusal whatever the fact says', () => {
const disabledField: SnapshotNode = {
...bareNode('android.widget.EditText'),
editable: true,
enabled: false,
};
assert.equal(isNodeEditable(disabledField, 'android'), false);
assert.equal(isNodeEditable({ ...disabledField, editable: undefined }, 'android'), false);
});

test('isNodeEditable infers from the type when the fact is absent', () => {
assert.equal(isNodeEditable(bareNode('android.widget.EditText'), 'android'), true);
assert.equal(isNodeEditable(bareNode('com.example.RichEditor'), 'android'), false);
});
4 changes: 3 additions & 1 deletion packages/selectors/src/internal/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export function isNodeVisible(node: SnapshotNode): boolean {
return node.rect.width > 0 && node.rect.height > 0;
}

/** A published `editable` fact decides; the type inference applies only when the fact is absent. */
Comment thread
thymikee marked this conversation as resolved.
Resolved
export function isNodeEditable(node: SnapshotNode, platform: Platform | PublicPlatform): boolean {
return isFillableType(node.type ?? '', platform) && node.enabled !== false;
if (node.enabled === false) return false;
return node.editable ?? isFillableType(node.type ?? '', platform);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/selectors/src/internal/predicates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,27 @@ test('visible predicate does not use non-hittable Android layout ancestors for r
assert.equal(result.pass, false);
});

test('editable predicate follows a published editable fact and infers from type without one', () => {
const editableAt = (node: Partial<SnapshotNode>) => {
const full: SnapshotNode = { index: 0, ref: 'e1', ...node };
return evaluateIsPredicate({
predicate: 'editable',
node: full,
visibility: createSnapshotVisibility([full]),
platform: 'android',
}).pass;
};

assert.equal(editableAt({ type: 'com.example.RichEditor', editable: true }), true);
assert.equal(editableAt({ type: 'android.widget.EditText', editable: false }), false);
assert.equal(
editableAt({ type: 'android.widget.EditText', editable: true, enabled: false }),
false,
);
assert.equal(editableAt({ type: 'android.widget.EditText' }), true);
assert.equal(editableAt({ type: 'com.example.RichEditor' }), false);
});

/** One capture whose two rows share a label: one on screen, one below the fold. */
const SHARED_CAPTURE: SnapshotNode[] = [
{
Expand Down
4 changes: 4 additions & 0 deletions website/docs/docs/selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ Text values match the whole field, ignoring case and extra whitespace: `label="s
Boolean keys: `visible`, `hidden`, `editable`, `selected`, `focused`, `enabled`, `hittable`. Write
`visible=true` or `visible=false`; a bare `visible` means `visible=true`.

`editable` (and `is editable`) uses the node's native `editable` fact when the snapshot carries one,
so a custom text view can match and a read-only field cannot. Without the fact it is inferred from
the element type. A disabled element is never editable.

Quoting and alternatives:

- Quote values that contain spaces, with double or single quotes: `label="Sign in"`. Escape a quote
Expand Down
Loading