@@ -312,7 +312,7 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
312312 const hoverElement = async ( selector : string ) => {
313313 const element = page . locator ( selector ) . first ( ) ;
314314 await element . hover ( { force : true } ) ;
315- await page . waitForTimeout ( 100 ) ;
315+ await page . waitForTimeout ( 250 ) ;
316316 } ;
317317
318318 const clickElement = async ( selector : string ) => {
@@ -362,7 +362,8 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
362362 const state = api ?. getState ( ) ;
363363 return state ?. isSelectionBoxVisible || state ?. targetElement !== null ;
364364 } ,
365- { timeout : 2000 } ,
365+ undefined ,
366+ { timeout : 10_000 } ,
366367 ) ;
367368 } ;
368369
@@ -378,6 +379,7 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
378379 ) . __REACT_GRAB__ ;
379380 return api ?. getState ( ) ?. selectionFilePath !== null ;
380381 } ,
382+ undefined ,
381383 { timeout : 5000 } ,
382384 ) ;
383385 } ;
@@ -608,7 +610,31 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
608610 const enterPromptMode = async ( selector : string ) => {
609611 await activate ( ) ;
610612 await hoverElement ( selector ) ;
611- await waitForSelectionBox ( ) ;
613+ const isSelected = await page
614+ . waitForFunction (
615+ ( ) => {
616+ const api = (
617+ window as {
618+ __REACT_GRAB__ ?: {
619+ getState : ( ) => {
620+ isSelectionBoxVisible : boolean ;
621+ targetElement : unknown ;
622+ } ;
623+ } ;
624+ }
625+ ) . __REACT_GRAB__ ;
626+ const state = api ?. getState ( ) ;
627+ return state ?. isSelectionBoxVisible || state ?. targetElement !== null ;
628+ } ,
629+ undefined ,
630+ { timeout : 2000 } ,
631+ )
632+ . then ( ( ) => true )
633+ . catch ( ( ) => false ) ;
634+ if ( ! isSelected ) {
635+ await hoverElement ( selector ) ;
636+ await waitForSelectionBox ( ) ;
637+ }
612638 await rightClickElement ( selector ) ;
613639 await clickContextMenuItem ( "Edit" ) ;
614640 await waitForPromptMode ( true ) ;
@@ -1820,6 +1846,7 @@ const createReactGrabPageObject = (page: Page): ReactGrabPageObject => {
18201846 const api = ( window as { __REACT_GRAB__ ?: unknown } ) . __REACT_GRAB__ ;
18211847 return api !== undefined ;
18221848 } ,
1849+ undefined ,
18231850 { timeout : 5000 } ,
18241851 ) ;
18251852 } ;
@@ -2494,6 +2521,7 @@ export const test = base.extend<{ reactGrab: ReactGrabPageObject }>({
24942521 const api = ( window as { __REACT_GRAB__ ?: unknown } ) . __REACT_GRAB__ ;
24952522 return api !== undefined ;
24962523 } ,
2524+ undefined ,
24972525 { timeout : PAGE_SETUP_API_TIMEOUT_MS } ,
24982526 ) ;
24992527 } ;
0 commit comments