@@ -64,12 +64,16 @@ const clearPayLoad = async (browser: NightwatchBrowser) => {
6464 } )
6565}
6666
67- const clickButton = async ( browser : NightwatchBrowser , buttonText : string ) => {
67+ const clickButton = async ( browser : NightwatchBrowser , buttonText : string , waitResult : boolean = true ) => {
6868 return new Promise ( ( resolve ) => {
6969 browser . useXpath ( ) . waitForElementVisible ( `//*[@data-id='${ buttonText } ']` ) . pause ( 100 )
7070 . click ( `//*[@data-id='${ buttonText } ']` , async ( ) => {
7171 await checkForAcceptAndRemember ( browser )
72- browser . waitForElementContainsText ( '//*[@id="callStatus"]' , 'stop' ) . perform ( ( ) => resolve ( true ) )
72+ if ( waitResult ) {
73+ browser . waitForElementContainsText ( '//*[@id="callStatus"]' , 'stop' ) . perform ( ( ) => resolve ( true ) )
74+ } else {
75+ resolve ( true )
76+ }
7377 } )
7478 } )
7579}
@@ -103,7 +107,7 @@ const checkForAcceptAndRemember = async function (browser: NightwatchBrowser) {
103107 * @return {Promise }
104108 */
105109
106- const clickAndCheckLog = async ( browser : NightwatchBrowser , buttonText : string , methodResult : any , eventResult : any , payload : any ) => {
110+ const clickAndCheckLog = async ( browser : NightwatchBrowser , buttonText : string , methodResult : any , eventResult : any , payload : any , waitResult : boolean = true ) => {
107111 if ( payload ) {
108112 await setPayload ( browser , payload )
109113 } else {
@@ -112,10 +116,14 @@ const clickAndCheckLog = async (browser: NightwatchBrowser, buttonText: string,
112116 if ( methodResult && typeof methodResult !== 'string' ) { methodResult = JSON . stringify ( methodResult ) }
113117 if ( eventResult && typeof eventResult !== 'string' ) { eventResult = JSON . stringify ( eventResult ) }
114118 if ( buttonText ) {
115- await clickButton ( browser , buttonText )
119+ await clickButton ( browser , buttonText , waitResult )
120+ }
121+ if ( methodResult ) {
122+ await debugValues ( browser , 'methods' , methodResult )
123+ }
124+ if ( eventResult ) {
125+ await debugValues ( browser , 'events' , eventResult )
116126 }
117- await debugValues ( browser , 'methods' , methodResult )
118- await debugValues ( browser , 'events' , eventResult )
119127}
120128
121129const assertPluginIsActive = function ( browser : NightwatchBrowser , id : string , shouldBeVisible : boolean ) {
@@ -364,5 +372,72 @@ module.exports = {
364372 const result = '{"jsonrpc":"2.0","result":true,"id":9999}'
365373 await clickAndCheckLog ( browser , 'hardhat-provider:sendAsync' , result , null , request )
366374 } )
375+ } ,
376+
377+ // MODAL
378+
379+ 'Should open 2 alert in a row and trigger 2 toaster in between #group9' : function ( browser : NightwatchBrowser ) {
380+ browser
381+ . frameParent ( )
382+ . useCss ( )
383+ . addFile ( 'test_modal.js' , { content : testModalToasterApi } )
384+ . executeScript ( 'remix.execute(\'test_modal.js\')' )
385+ . clickLaunchIcon ( 'localPlugin' )
386+ . useXpath ( )
387+ // @ts -ignore
388+ . frame ( 0 )
389+ . perform ( async ( ) => {
390+ await clickAndCheckLog ( browser , 'notification:toast' , null , null , 'message toast from local plugin' , false ) // create a toast on behalf of the localplugin
391+ await clickAndCheckLog ( browser , 'notification:alert' , null , null , { message : 'message from local plugin' , id : 'test_id_1_local_plugin' } , false ) // create an alert on behalf of the localplugin
392+ } )
393+ . frameParent ( )
394+ . useCss ( )
395+ // check the local plugin notifications
396+ . waitForElementVisible ( '*[data-id="test_id_1_local_pluginModalDialogModalBody-react"]' )
397+ . assert . containsText ( '*[data-id="test_id_1_local_pluginModalDialogModalBody-react"]' , 'message from local plugin' )
398+ . modalFooterOKClick ( 'test_id_1_local_plugin' )
399+ // check the script runner notifications
400+ . waitForElementVisible ( '*[data-id="test_id_1_ModalDialogModalBody-react"]' )
401+ . assert . containsText ( '*[data-id="test_id_1_ModalDialogModalBody-react"]' , 'message 1' )
402+ . modalFooterOKClick ( 'test_id_1_' )
403+ . waitForElementVisible ( '*[data-id="test_id_2_ModalDialogModalBody-react"]' )
404+ . assert . containsText ( '*[data-id="test_id_2_ModalDialogModalBody-react"]' , 'message 2' )
405+ . modalFooterOKClick ( 'test_id_2_' )
406+ . waitForElementVisible ( '*[data-id="test_id_3_ModalDialogModalBody-react"]' )
407+ . modalFooterOKClick ( 'test_id_3_' )
408+ . journalLastChildIncludes ( 'default value... ' ) // check the return value of the prompt
409+ // check the toasters
410+ . waitForElementVisible ( '*[data-shared="tooltipPopup"]' )
411+ . waitForElementContainsText ( '*[data-shared="tooltipPopup"]' , 'message toast from local plugin' )
412+ . waitForElementContainsText ( '*[data-shared="tooltipPopup"]' , 'I am a toast' )
413+ . waitForElementContainsText ( '*[data-shared="tooltipPopup"]' , 'I am a re-toast' )
367414 }
368415}
416+
417+ const testModalToasterApi = `
418+ // Right click on the script name and hit "Run" to execute
419+ (async () => {
420+ try {
421+ setTimeout(async () => {
422+ console.log('test .. ')
423+ remix.call('notification', 'alert', { message: 'message 1', id: 'test_id_1_' })
424+ remix.call('notification', 'toast', 'I am a toast')
425+ remix.call('notification', 'toast', 'I am a re-toast')
426+ remix.call('notification', 'alert', { message: 'message 2', id: 'test_id_2_' })
427+
428+ const modalContent = {
429+ id: 'test_id_3_',
430+ title: 'test with input title',
431+ message: 'test with input content',
432+ modalType: 'prompt',
433+ okLabel: 'OK',
434+ cancelLabel: 'Cancel',
435+ defaultValue: 'default value... '
436+ }
437+ const result = await remix.call('notification', 'modal', modalContent)
438+ console.log(result)
439+ }, 500)
440+ } catch (e) {
441+ console.log(e.message)
442+ }
443+ })() `
0 commit comments