@@ -75,3 +75,69 @@ describe('Snapshot', () => {
7575 } , 60000 ) ; // 60 seconds - browser startup can be slow
7676} ) ;
7777
78+ describe ( 'Element ML Fields' , ( ) => {
79+ it ( 'should accept elements without ML reranking fields' , ( ) => {
80+ const element = {
81+ id : 1 ,
82+ role : 'button' ,
83+ text : 'Click me' ,
84+ importance : 100 ,
85+ bbox : { x : 10 , y : 20 , width : 100 , height : 50 } ,
86+ visual_cues : { is_primary : true , background_color_name : 'blue' , is_clickable : true } ,
87+ in_viewport : true ,
88+ is_occluded : false ,
89+ z_index : 0 ,
90+ } ;
91+
92+ expect ( element . id ) . toBe ( 1 ) ;
93+ expect ( element ) . not . toHaveProperty ( 'rerank_index' ) ;
94+ expect ( element ) . not . toHaveProperty ( 'heuristic_index' ) ;
95+ expect ( element ) . not . toHaveProperty ( 'ml_probability' ) ;
96+ expect ( element ) . not . toHaveProperty ( 'ml_score' ) ;
97+ } ) ;
98+
99+ it ( 'should accept elements with ML reranking fields' , ( ) => {
100+ const element = {
101+ id : 2 ,
102+ role : 'link' ,
103+ text : 'Learn more' ,
104+ importance : 80 ,
105+ bbox : { x : 15 , y : 25 , width : 120 , height : 40 } ,
106+ visual_cues : { is_primary : false , background_color_name : 'white' , is_clickable : true } ,
107+ in_viewport : true ,
108+ is_occluded : false ,
109+ z_index : 1 ,
110+ rerank_index : 0 ,
111+ heuristic_index : 5 ,
112+ ml_probability : 0.95 ,
113+ ml_score : 2.34 ,
114+ } ;
115+
116+ expect ( element . rerank_index ) . toBe ( 0 ) ;
117+ expect ( element . heuristic_index ) . toBe ( 5 ) ;
118+ expect ( element . ml_probability ) . toBe ( 0.95 ) ;
119+ expect ( element . ml_score ) . toBe ( 2.34 ) ;
120+ } ) ;
121+
122+ it ( 'should accept elements with partial ML fields' , ( ) => {
123+ const element = {
124+ id : 3 ,
125+ role : 'textbox' ,
126+ text : null ,
127+ importance : 60 ,
128+ bbox : { x : 20 , y : 30 , width : 200 , height : 30 } ,
129+ visual_cues : { is_primary : false , background_color_name : null , is_clickable : true } ,
130+ in_viewport : true ,
131+ is_occluded : false ,
132+ z_index : 0 ,
133+ rerank_index : 1 ,
134+ ml_probability : 0.87 ,
135+ } ;
136+
137+ expect ( element . rerank_index ) . toBe ( 1 ) ;
138+ expect ( element ) . not . toHaveProperty ( 'heuristic_index' ) ;
139+ expect ( element . ml_probability ) . toBe ( 0.87 ) ;
140+ expect ( element ) . not . toHaveProperty ( 'ml_score' ) ;
141+ } ) ;
142+ } ) ;
143+
0 commit comments