@@ -116,10 +116,26 @@ describe('highlight-detection helpers', () => {
116116 expect ( script ) . toContain ( 'evaluateLayoutReadiness' ) ;
117117 } ) ;
118118
119+ test ( 'buildHighlightDetectionScript can force full scans on not-ready pages' , ( ) => {
120+ const script = buildHighlightDetectionScript ( {
121+ elementType : 'any' ,
122+ fullPageScanOnNotReady : true ,
123+ } ) ;
124+
125+ expect ( script ) . toContain ( '"fullPageScanOnNotReady":true' ) ;
126+ expect ( script ) . toContain ( 'config.fullPageScanOnNotReady === true' ) ;
127+ expect ( script ) . toContain ( 'override=full_scan' ) ;
128+ } ) ;
129+
119130 test ( 'buildHighlightDetectionScript uses readiness snapshot instead of wait loop' , ( ) => {
120131 const script = buildHighlightDetectionScript ( { elementType : 'any' } ) ;
121132
122133 expect ( script ) . toContain ( 'function evaluateReadinessSnapshot' ) ;
134+ expect ( script ) . toContain ( 'function getCandidateElementsForScan' ) ;
135+ expect ( script ) . toContain ( "layoutStability.state !== 'not_ready'" ) ;
136+ expect ( script ) . toContain ( 'config.fullPageScanOnNotReady === true' ) ;
137+ expect ( script ) . toContain ( 'const NOT_READY_SCAN_LIMIT = 500;' ) ;
138+ expect ( script ) . toContain ( "trace('scan:capped'" ) ;
123139 expect ( script ) . toContain ( 'readiness:snapshot' ) ;
124140 expect ( script ) . not . toContain ( 'function waitForLayoutStability' ) ;
125141 } ) ;
@@ -143,6 +159,51 @@ describe('highlight-detection helpers', () => {
143159 ) ;
144160 } ) ;
145161
162+ test ( 'buildHighlightDetectionScript excludes visually hidden screen-reader nodes' , ( ) => {
163+ const script = buildHighlightDetectionScript ( { elementType : 'any' } ) ;
164+ const start = script . indexOf ( 'function isElementVisibleForDetection' ) ;
165+ const end = script . indexOf (
166+ 'function isElementInViewportForDetection' ,
167+ start ,
168+ ) ;
169+ const visibilitySource = script . slice ( start , end ) ;
170+
171+ expect ( script ) . toContain ( 'const VISUALLY_HIDDEN_TOKEN_REGEX' ) ;
172+ expect ( script ) . toContain ( 'sr-only' ) ;
173+ expect ( script ) . toContain ( 'screen-reader' ) ;
174+ expect ( script ) . toContain ( 'visually-hidden' ) ;
175+ expect ( script ) . toContain ( 'function isVisuallyHiddenForDetection' ) ;
176+ expect ( visibilitySource ) . toContain ( 'isVisuallyHiddenForDetection(el)' ) ;
177+ } ) ;
178+
179+ test ( 'buildHighlightDetectionScript excludes truncation-only scrollable false positives' , ( ) => {
180+ const script = buildHighlightDetectionScript ( { elementType : 'scrollable' } ) ;
181+ const truncationStart = script . indexOf (
182+ 'function isLikelyTextTruncationContainer' ,
183+ ) ;
184+ const truncationEnd = script . indexOf (
185+ 'function isScrollableCandidate' ,
186+ truncationStart ,
187+ ) ;
188+ const truncationSource = script . slice ( truncationStart , truncationEnd ) ;
189+ const scrollableStart = script . indexOf ( 'function isScrollableCandidate' ) ;
190+ const scrollableEnd = script . indexOf (
191+ 'function isHoverableCandidate' ,
192+ scrollableStart ,
193+ ) ;
194+ const scrollableSource = script . slice ( scrollableStart , scrollableEnd ) ;
195+
196+ expect ( truncationSource ) . toContain ( "style.textOverflow === 'ellipsis'" ) ;
197+ expect ( truncationSource ) . toContain ( "style.whiteSpace === 'nowrap'" ) ;
198+ expect ( truncationSource ) . toContain ( 'countVisibleElementChildren(el, 2)' ) ;
199+ expect ( scrollableSource ) . toContain ( 'isLikelyTextTruncationContainer(el)' ) ;
200+ expect ( scrollableSource ) . toContain ( 'isSemanticControlElement(el)' ) ;
201+ expect ( scrollableSource ) . toContain (
202+ "overflowX.includes('hidden') || overflowX.includes('clip')" ,
203+ ) ;
204+ expect ( scrollableSource ) . toContain ( 'hasHorizontalSwipeLayout(el)' ) ;
205+ } ) ;
206+
146207 test ( "buildHighlightDetectionScript keeps 'any' candidate selection across all element types" , ( ) => {
147208 const script = buildHighlightDetectionScript ( { elementType : 'any' } ) ;
148209 const start = script . indexOf ( 'function resolveElementCandidate' ) ;
0 commit comments