@@ -460,3 +460,148 @@ test("Create account with session, create session via paymaster, and send ETH",
460460
461461 console . log ( "Session created successfully with balance:" , sessionStartBalance , "ETH" ) ;
462462} ) ;
463+
464+ test ( "Create session and verify it appears in auth-server sessions list" , async ( { page } ) => {
465+ test . setTimeout ( 120000 ) ;
466+ console . log ( "\n=== Session Display in Sessions List Test ===\n" ) ;
467+
468+ // Step 1: Create account
469+ console . log ( "Step 1: Creating account..." ) ;
470+ await page . getByRole ( "button" , { name : "Connect" , exact : true } ) . click ( ) ;
471+ await page . waitForTimeout ( 2000 ) ;
472+
473+ const popup = page . context ( ) . pages ( ) [ 1 ] ;
474+ await expect ( popup . getByText ( "Connect to" ) ) . toBeVisible ( ) ;
475+
476+ // Setup WebAuthn
477+ const client = await popup . context ( ) . newCDPSession ( popup ) ;
478+ await client . send ( "WebAuthn.enable" ) ;
479+ let newCredential : WebAuthnCredential | null = null ;
480+ client . on ( "WebAuthn.credentialAdded" , ( credentialAdded ) => {
481+ newCredential = credentialAdded . credential ;
482+ } ) ;
483+ await client . send ( "WebAuthn.addVirtualAuthenticator" , {
484+ options : {
485+ protocol : "ctap2" ,
486+ transport : "usb" ,
487+ hasResidentKey : true ,
488+ hasUserVerification : true ,
489+ isUserVerified : true ,
490+ automaticPresenceSimulation : true ,
491+ } ,
492+ } ) ;
493+
494+ // Complete signup
495+ await popup . getByTestId ( "signup" ) . click ( ) ;
496+ await expect ( popup . getByText ( "Connect to ZKsync SSO Demo" ) ) . toBeVisible ( ) ;
497+ await popup . getByTestId ( "connect" ) . click ( ) ;
498+ await page . waitForTimeout ( 2000 ) ;
499+ await expect ( page . getByText ( "Disconnect" ) ) . toBeVisible ( ) ;
500+ console . log ( "✓ Account created" ) ;
501+
502+ // Step 2: Create session
503+ console . log ( "\nStep 2: Creating session..." ) ;
504+ await page . getByRole ( "button" , { name : "Disconnect" , exact : true } ) . click ( ) ;
505+ await expect ( page . getByRole ( "button" , { name : "Connect with Session" , exact : true } ) ) . toBeVisible ( ) ;
506+ await page . getByRole ( "button" , { name : "Connect with Session" , exact : true } ) . click ( ) ;
507+ await page . waitForTimeout ( 2000 ) ;
508+
509+ const sessionPopup = page . context ( ) . pages ( ) [ 1 ] ;
510+ await expect ( sessionPopup . getByText ( "Act on your behalf" ) ) . toBeVisible ( ) ;
511+
512+ // Setup WebAuthn with existing credential
513+ const sessionClient = await sessionPopup . context ( ) . newCDPSession ( sessionPopup ) ;
514+ await sessionClient . send ( "WebAuthn.enable" ) ;
515+ const sessionAuthenticator = await sessionClient . send ( "WebAuthn.addVirtualAuthenticator" , {
516+ options : {
517+ protocol : "ctap2" ,
518+ transport : "usb" ,
519+ hasResidentKey : true ,
520+ hasUserVerification : true ,
521+ isUserVerified : true ,
522+ automaticPresenceSimulation : true ,
523+ } ,
524+ } ) ;
525+ await expect ( newCredential ) . not . toBeNull ( ) ;
526+ await sessionClient . send ( "WebAuthn.addCredential" , {
527+ authenticatorId : sessionAuthenticator . authenticatorId ,
528+ credential : newCredential ! ,
529+ } ) ;
530+
531+ // Authorize session
532+ await expect ( sessionPopup . getByText ( "Authorize ZKsync SSO Demo" ) ) . toBeVisible ( ) ;
533+ await sessionPopup . getByTestId ( "connect" ) . click ( ) ;
534+ await page . waitForTimeout ( 3000 ) ;
535+ await expect ( page . getByText ( "Disconnect" ) ) . toBeVisible ( ) ;
536+ console . log ( "✓ Session created" ) ;
537+
538+ // Step 3: Navigate to auth-server sessions page to verify
539+ console . log ( "\nStep 3: Verifying session appears in auth-server..." ) ;
540+
541+ const authPage = await page . context ( ) . newPage ( ) ;
542+ await authPage . goto ( "http://localhost:3002" ) ;
543+ await authPage . waitForTimeout ( 1000 ) ;
544+
545+ // Check if logged in
546+ const isLoggedIn = await authPage . locator ( "[data-testid='account-address']" ) . isVisible ( { timeout : 2000 } ) . catch ( ( ) => false ) ;
547+
548+ if ( ! isLoggedIn ) {
549+ console . log ( "Logging into auth-server..." ) ;
550+ // Already on auth-server homepage, just click login
551+ await authPage . getByTestId ( "login" ) . click ( ) ;
552+ await authPage . waitForTimeout ( 1000 ) ;
553+
554+ // Setup WebAuthn for login
555+ const authClient = await authPage . context ( ) . newCDPSession ( authPage ) ;
556+ await authClient . send ( "WebAuthn.enable" ) ;
557+ const authAuthenticator = await authClient . send ( "WebAuthn.addVirtualAuthenticator" , {
558+ options : {
559+ protocol : "ctap2" ,
560+ transport : "usb" ,
561+ hasResidentKey : true ,
562+ hasUserVerification : true ,
563+ isUserVerified : true ,
564+ automaticPresenceSimulation : true ,
565+ } ,
566+ } ) ;
567+ await authClient . send ( "WebAuthn.addCredential" , {
568+ authenticatorId : authAuthenticator . authenticatorId ,
569+ credential : newCredential ! ,
570+ } ) ;
571+
572+ await authPage . waitForURL ( "**/dashboard" , { timeout : 15000 } ) ;
573+ console . log ( "✓ Logged into auth-server" ) ;
574+ }
575+
576+ // Navigate to sessions page
577+ await authPage . goto ( "http://localhost:3002/dashboard/sessions" ) ;
578+ await authPage . waitForLoadState ( "domcontentloaded" ) ;
579+ await authPage . waitForTimeout ( 3000 ) ;
580+ console . log ( "✓ Navigated to sessions page" ) ;
581+
582+ // Verify sessions page content
583+ const header = authPage . locator ( "header" ) . getByText ( "Sessions" ) ;
584+ await expect ( header ) . toBeVisible ( ) ;
585+ console . log ( "✓ Sessions page loaded" ) ;
586+
587+ // Log page content for debugging
588+ const pageContent = await authPage . locator ( "main" ) . textContent ( ) ;
589+ console . log ( `Page content: ${ pageContent ?. substring ( 0 , 500 ) } ` ) ;
590+
591+ // Verify at least one session is displayed
592+ const sessionRows = authPage . locator ( "[data-testid*='session']" ) ;
593+ const sessionCount = await sessionRows . count ( ) ;
594+ console . log ( `Found ${ sessionCount } session row(s)` ) ;
595+
596+ expect ( sessionCount , "At least one session should be displayed" ) . toBeGreaterThan ( 0 ) ;
597+ console . log ( `✓ Found ${ sessionCount } session(s) displayed` ) ;
598+
599+ // Verify empty state message is NOT shown
600+ const emptyState = authPage . getByText ( / n o a c t i v e s e s s i o n s / i) ;
601+ const emptyVisible = await emptyState . isVisible ( { timeout : 1000 } ) . catch ( ( ) => false ) ;
602+ expect ( emptyVisible , "Empty state should NOT be visible when sessions exist" ) . toBe ( false ) ;
603+ console . log ( "✓ Empty state correctly hidden" ) ;
604+
605+ await authPage . close ( ) ;
606+ console . log ( "\n=== Session Display Test Complete ===\n" ) ;
607+ } ) ;
0 commit comments