@@ -15,7 +15,7 @@ async function waitForElement(selector: string, timeout = 10000): Promise<HTMLEl
1515 throw new Error ( `Element ${ selector } not found within ${ timeout } ms` )
1616}
1717
18- it ( 'opens Hub popup when clicking Choose Address button ' , async ( ) => {
18+ it ( 'opens Hub popup and verifies it loads the Hub interface ' , async ( ) => {
1919 // Load the app HTML
2020 const response = await fetch ( '/index.html' )
2121 const html = await response . text ( )
@@ -26,22 +26,23 @@ it('opens Hub popup when clicking Choose Address button', async () => {
2626 document . body . innerHTML = bodyMatch [ 1 ]
2727 }
2828
29- // Track if Hub popup was opened
30- let hubPopupOpened = false
29+ // Track the opened popup
30+ let hubPopup : Window | null = null
3131 let hubPopupUrl = ''
3232
33- // Override window.open to intercept Hub popup
33+ // Override window.open to capture the popup reference
3434 const originalOpen = window . open
3535 window . open = function ( ...args : Parameters < typeof window . open > ) {
3636 const url = args [ 0 ] ?. toString ( ) || ''
3737
3838 // Check if it's the Hub
3939 if ( url . includes ( 'hub.nimiq-testnet.com' ) || url . includes ( 'hub.nimiq.com' ) ) {
40- console . log ( '✅ Hub popup intercepted:' , url )
41- hubPopupOpened = true
40+ console . log ( '✅ Hub popup opening:' , url )
4241 hubPopupUrl = url
43- // Don't actually open the popup in tests
44- return null
42+
43+ // Actually open the popup so we can inspect it
44+ hubPopup = originalOpen . apply ( window , args )
45+ return hubPopup
4546 }
4647
4748 return originalOpen . apply ( window , args )
@@ -53,19 +54,47 @@ it('opens Hub popup when clicking Choose Address button', async () => {
5354 // Wait for the Choose Address button
5455 const chooseAddressBtn = await waitForElement ( '#choose-address' )
5556
56- // Click the button
57+ // Click the button to open Hub popup
5758 chooseAddressBtn . click ( )
5859
59- // Give it time to trigger the popup
60- await sleep ( 1000 )
60+ // Wait for popup to open
61+ await sleep ( 2000 )
6162
6263 // Verify Hub popup was opened
63- expect ( hubPopupOpened ) . toBe ( true )
6464 expect ( hubPopupUrl ) . toContain ( 'hub.nimiq' )
65+ expect ( hubPopup ) . toBeTruthy ( )
66+
67+ // Try to verify the popup loaded (if accessible due to CORS/same-origin policy)
68+ if ( hubPopup && ! hubPopup . closed ) {
69+ try {
70+ // Wait a bit for the Hub to load
71+ await sleep ( 3000 )
72+
73+ // Check if we can access the popup's location
74+ const popupLocation = hubPopup . location . href
75+ expect ( popupLocation ) . toContain ( 'hub.nimiq' )
76+ console . log ( '✅ Hub popup verified - URL:' , popupLocation )
77+
78+ // Close the popup
79+ hubPopup . close ( )
80+ }
81+ catch ( error ) {
82+ // If we get a cross-origin error, that's actually good - it means the real Hub loaded
83+ const errorMessage = error instanceof Error ? error . message : String ( error )
84+ if ( errorMessage . includes ( 'cross-origin' ) || errorMessage . includes ( 'SecurityError' ) ) {
85+ console . log ( '✅ Hub popup loaded (cross-origin - real Hub domain)' )
86+ console . log ( ' Expected cross-origin restriction confirms real Hub loaded' )
87+ hubPopup . close ( )
88+ }
89+ else {
90+ throw error
91+ }
92+ }
93+ }
6594
66- console . log ( '✅ Hub API integration test passed: Hub popup opens correctly ' )
95+ console . log ( '✅ Hub API integration test passed' )
6796 console . log ( ` Hub URL: ${ hubPopupUrl } ` )
6897
6998 // Restore original window.open
7099 window . open = originalOpen
71- } , 30000 )
100+ } , 45000 )
0 commit comments