File tree Expand file tree Collapse file tree
apps/desktop/src/main/browser-agent Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -673,6 +673,26 @@ describe('collectSnapshot', () => {
673673 expect ( clickElement ( ref ) ) . toMatchObject ( { error : 'stale' } )
674674 } )
675675
676+ it ( 'keeps a connected ref whose name grew when its own submenu opened' , ( ) => {
677+ document . body . innerHTML = '<div role="button" tabindex="0">Products ▾<ul></ul></div>'
678+ const menu = visible ( document . querySelector ( '[role="button"]' ) as HTMLDivElement )
679+ const ref = refFor ( outlineOf ( collectSnapshot ( ) ) , 'Products ▾' )
680+
681+ ; ( menu . querySelector ( 'ul' ) as HTMLUListElement ) . innerHTML = ' <li>Starter</li> <li>Business</li>'
682+
683+ expect ( clickElement ( ref ) ) . toMatchObject ( { dispatched : true } )
684+ } )
685+
686+ it ( 'invalidates a connected ref whose name changed to a longer, different word' , ( ) => {
687+ document . body . innerHTML = '<div role="listitem">Item 1</div>'
688+ const row = visible ( document . querySelector ( '[role="listitem"]' ) as HTMLDivElement )
689+ const ref = refFor ( outlineOf ( collectSnapshot ( ) ) , 'Item 1' )
690+
691+ row . textContent = 'Item 12'
692+
693+ expect ( clickElement ( ref ) ) . toMatchObject ( { error : 'stale' } )
694+ } )
695+
676696 it ( 'never recycles numeric refs across snapshots' , ( ) => {
677697 document . body . innerHTML = '<button>Pins</button>'
678698 visible ( document . querySelector ( 'button' ) as HTMLButtonElement )
Original file line number Diff line number Diff line change @@ -897,7 +897,16 @@ export function collectSnapshot(
897897 ) {
898898 return false
899899 }
900- if ( nameFor ( candidate ) !== locator . name ) return false
900+ // A still-mounted control whose own menu or disclosure opened (often by
901+ // the hover or click being validated) appends its new content to its
902+ // name; a recycled row replaces the name instead.
903+ const name = nameFor ( candidate )
904+ const nameGrewInPlace =
905+ connected &&
906+ locator . name . length > 0 &&
907+ name . startsWith ( locator . name ) &&
908+ ( locator . name . length >= 120 || / \s / . test ( name . charAt ( locator . name . length ) ) )
909+ if ( name !== locator . name && ! nameGrewInPlace ) return false
901910 const candidateAttributes = locatorAttributes ( candidate )
902911 const attributes = connected ? connectedIdentityAttributes : stableAttributes
903912 const genericName =
You can’t perform that action at this time.
0 commit comments