@@ -159,22 +159,23 @@ describe('WebBrowser Wallet Injection', () => {
159159 ) ;
160160 } ) ;
161161
162- test ( 'should handle wallet injection into iframe with secure postMessage' , ( ) => {
163- render (
162+ test ( 'should handle wallet injection into iframe when navigating to URL' , async ( ) => {
163+ const { container } = render (
164164 < WalletProviderContext >
165165 < WebBrowser isActive = { true } />
166166 </ WalletProviderContext >
167167 ) ;
168168
169- const iframe = createMockIframe ( ) ;
170- document . body . appendChild ( iframe ) ;
171-
172- // Simulate iframe load event
173- const loadEvent = new Event ( 'load' ) ;
174- fireEvent ( iframe , loadEvent ) ;
169+ // Find the address bar and enter a URL
170+ const addressBar = screen . getByLabelText ( / a d d r e s s / i) ;
171+ fireEvent . change ( addressBar , { target : { value : 'https://example.com' } } ) ;
172+ fireEvent . keyPress ( addressBar , { key : 'Enter' , code : 'Enter' , charCode : 13 } ) ;
175173
176- // Verify that postMessage was called with wallet injection script
177- expect ( iframe . contentWindow ?. postMessage ) . toHaveBeenCalled ( ) ;
174+ // The component should render an iframe
175+ const iframe = container . querySelector ( 'iframe' ) ;
176+ expect ( iframe ) . toBeInTheDocument ( ) ;
177+ expect ( iframe ) . toHaveAttribute ( 'title' , 'Solana dApp Browser' ) ;
178+ expect ( iframe ) . toHaveAttribute ( 'sandbox' ) ;
178179 } ) ;
179180
180181 test ( 'should handle connection when wallet is not available' , async ( ) => {
@@ -268,14 +269,25 @@ describe('WebBrowser Wallet Injection', () => {
268269 expect ( messageHandler ) . toHaveBeenCalledWith ( malformedMessage ) ;
269270 } ) ;
270271
271- test ( 'should validate iframe sandbox attributes' , ( ) => {
272+ test ( 'should validate iframe sandbox attributes' , async ( ) => {
272273 render (
273274 < WalletProviderContext >
274275 < WebBrowser isActive = { true } />
275276 </ WalletProviderContext >
276277 ) ;
277278
278- const iframe = screen . getByTitle ( / b r o w s e r i f r a m e / i) ;
279+ // Enter a URL to trigger iframe rendering
280+ const addressBar = screen . getByLabelText ( / a d d r e s s / i) ;
281+ fireEvent . change ( addressBar , { target : { value : 'https://example.com' } } ) ;
282+ fireEvent . keyPress ( addressBar , { key : 'Enter' , code : 'Enter' , charCode : 13 } ) ;
283+
284+ // Wait for iframe to appear
285+ await waitFor ( ( ) => {
286+ const iframe = screen . getByTitle ( / s o l a n a d a p p b r o w s e r / i) ;
287+ expect ( iframe ) . toBeInTheDocument ( ) ;
288+ } ) ;
289+
290+ const iframe = screen . getByTitle ( / s o l a n a d a p p b r o w s e r / i) ;
279291
280292 expect ( iframe ) . toHaveAttribute ( 'sandbox' ) ;
281293 expect ( iframe . getAttribute ( 'sandbox' ) ) . toContain ( 'allow-scripts' ) ;
@@ -306,8 +318,9 @@ describe('WebBrowser Wallet Injection', () => {
306318
307319 // Should handle wallet state change gracefully
308320 await waitFor ( ( ) => {
309- const status = screen . getByText ( / c o n n e c t y o u r w a l l e t / i) ;
310- expect ( status ) . toBeInTheDocument ( ) ;
321+ // The component should still render and show popular dApps when wallet is disconnected
322+ const dappsHeading = screen . getByText ( / p o p u l a r s o l a n a d a p p s / i) ;
323+ expect ( dappsHeading ) . toBeInTheDocument ( ) ;
311324 } ) ;
312325 } ) ;
313326
0 commit comments