@@ -4,6 +4,7 @@ import type { RawSnapshotNode, Rect, SnapshotNode } from '@agent-device/kernel/s
44import {
55 buildSnapshotNodeMap ,
66 extractNodeText ,
7+ findNearestAncestor ,
78 findNearestScrollableAncestor ,
89 findSnapshotAncestor ,
910 isFillableType ,
@@ -28,8 +29,6 @@ test('snapshot text semantics normalize roles, identify fillable controls, and e
2829 assert . equal ( isFillableType ( 'android.widget.EditText' , 'android' ) , true ) ;
2930 assert . equal (
3031 extractNodeText ( {
31- index : 0 ,
32- ref : '@e0' ,
3332 label : ' ' ,
3433 value : ' Enter name ' ,
3534 identifier : 'name' ,
@@ -68,6 +67,19 @@ test('findSnapshotAncestor terminates on a parent-linkage cycle without resolvin
6867 assert . equal ( ancestor , null ) ;
6968} ) ;
7069
70+ test ( 'findNearestAncestor adapts a predicate to the shared tree walk' , ( ) => {
71+ const nodes : SnapshotNode [ ] = [
72+ { ref : 'e10' , index : 10 , type : 'Window' } ,
73+ { ref : 'e30' , index : 30 , parentIndex : 20 , type : 'Text' } ,
74+ { ref : 'e20' , index : 20 , parentIndex : 10 , type : 'Cell' } ,
75+ ] ;
76+
77+ assert . equal (
78+ findNearestAncestor ( nodes , nodes [ 1 ] ! , ( ancestor ) => ancestor . type === 'Window' ) ?. index ,
79+ 10 ,
80+ ) ;
81+ } ) ;
82+
7183test ( 'snapshot tree and scroll semantics identify nodes through their stable indexes' , ( ) => {
7284 const nodes = [
7385 node ( { index : 0 , type : 'Window' } ) ,
0 commit comments