@@ -460,3 +460,178 @@ 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+
501+ // Capture the account address from the page
502+ const demoPageContent = await page . textContent ( "body" ) ;
503+ const accountMatch = demoPageContent ?. match ( / 0 x [ a - f A - F 0 - 9 ] { 40 } / ) ;
504+ const demoAccountAddress = accountMatch ? accountMatch [ 0 ] : "unknown" ;
505+ console . log ( `✓ Account created: ${ demoAccountAddress } ` ) ;
506+
507+ // Step 2: Create session
508+ console . log ( "\nStep 2: Creating session..." ) ;
509+ await page . getByRole ( "button" , { name : "Disconnect" , exact : true } ) . click ( ) ;
510+ await expect ( page . getByRole ( "button" , { name : "Connect with Session" , exact : true } ) ) . toBeVisible ( ) ;
511+ await page . getByRole ( "button" , { name : "Connect with Session" , exact : true } ) . click ( ) ;
512+ await page . waitForTimeout ( 2000 ) ;
513+
514+ const sessionPopup = page . context ( ) . pages ( ) [ 1 ] ;
515+ await expect ( sessionPopup . getByText ( "Act on your behalf" ) ) . toBeVisible ( ) ;
516+
517+ // Setup WebAuthn with existing credential
518+ const sessionClient = await sessionPopup . context ( ) . newCDPSession ( sessionPopup ) ;
519+ await sessionClient . send ( "WebAuthn.enable" ) ;
520+ const sessionAuthenticator = await sessionClient . send ( "WebAuthn.addVirtualAuthenticator" , {
521+ options : {
522+ protocol : "ctap2" ,
523+ transport : "usb" ,
524+ hasResidentKey : true ,
525+ hasUserVerification : true ,
526+ isUserVerified : true ,
527+ automaticPresenceSimulation : true ,
528+ } ,
529+ } ) ;
530+ await expect ( newCredential ) . not . toBeNull ( ) ;
531+ await sessionClient . send ( "WebAuthn.addCredential" , {
532+ authenticatorId : sessionAuthenticator . authenticatorId ,
533+ credential : newCredential ! ,
534+ } ) ;
535+
536+ // Authorize session
537+ await expect ( sessionPopup . getByText ( "Authorize ZKsync SSO Demo" ) ) . toBeVisible ( ) ;
538+ await sessionPopup . getByTestId ( "connect" ) . click ( ) ;
539+ await page . waitForTimeout ( 3000 ) ;
540+ await expect ( page . getByText ( "Disconnect" ) ) . toBeVisible ( ) ;
541+ console . log ( "✓ Session created" ) ;
542+
543+ // Step 3: Navigate to auth-server sessions page to verify
544+ console . log ( "\nStep 3: Verifying session appears in auth-server..." ) ;
545+
546+ const authPage = await page . context ( ) . newPage ( ) ;
547+ await authPage . goto ( "http://localhost:3002" ) ;
548+ await authPage . waitForTimeout ( 1000 ) ;
549+
550+ // Check if logged in
551+ const isLoggedIn = await authPage . locator ( "[data-testid='account-address']" ) . isVisible ( { timeout : 2000 } ) . catch ( ( ) => false ) ;
552+
553+ if ( ! isLoggedIn ) {
554+ console . log ( "Logging into auth-server..." ) ;
555+ // Already on auth-server homepage, just click login
556+ await authPage . getByTestId ( "login" ) . click ( ) ;
557+ await authPage . waitForTimeout ( 1000 ) ;
558+
559+ // Setup WebAuthn for login
560+ const authClient = await authPage . context ( ) . newCDPSession ( authPage ) ;
561+ await authClient . send ( "WebAuthn.enable" ) ;
562+ const authAuthenticator = await authClient . send ( "WebAuthn.addVirtualAuthenticator" , {
563+ options : {
564+ protocol : "ctap2" ,
565+ transport : "usb" ,
566+ hasResidentKey : true ,
567+ hasUserVerification : true ,
568+ isUserVerified : true ,
569+ automaticPresenceSimulation : true ,
570+ } ,
571+ } ) ;
572+ await authClient . send ( "WebAuthn.addCredential" , {
573+ authenticatorId : authAuthenticator . authenticatorId ,
574+ credential : newCredential ! ,
575+ } ) ;
576+
577+ await authPage . waitForURL ( "**/dashboard" , { timeout : 15000 } ) ;
578+ console . log ( "✓ Logged into auth-server" ) ;
579+ }
580+
581+ // Navigate to sessions page
582+ await authPage . goto ( "http://localhost:3002/dashboard/sessions" ) ;
583+ await authPage . waitForLoadState ( "domcontentloaded" ) ;
584+
585+ // Listen for console logs from the sessions page
586+ authPage . on ( "console" , ( msg ) => {
587+ if ( msg . text ( ) . includes ( "[sessions.vue]" ) ) {
588+ console . log ( ` Auth-server: ${ msg . text ( ) } ` ) ;
589+ }
590+ } ) ;
591+
592+ console . log ( "✓ Navigated to sessions page" ) ;
593+ console . log ( ` Demo account (created session): ${ demoAccountAddress } ` ) ;
594+
595+ // Verify sessions page content
596+ const header = authPage . locator ( "header" ) . getByText ( "Sessions" ) ;
597+ await expect ( header ) . toBeVisible ( ) ;
598+ console . log ( "✓ Sessions page loaded" ) ;
599+
600+ // Wait for sessions data to load - look for either session rows or the table/list container
601+ // The sessions are loaded via WASM asynchronously, so we need to wait
602+ try {
603+ // Wait for the sessions list container or session rows to appear
604+ await authPage . waitForSelector ( "table tbody tr, [role='list'] > div, [data-testid*='session']" , {
605+ timeout : 15000 ,
606+ state : "attached" ,
607+ } ) ;
608+ console . log ( "✓ Sessions data container loaded" ) ;
609+ } catch ( e ) {
610+ console . log ( "⚠ No sessions container appeared within 15s" , e ) ;
611+ }
612+
613+ // Additional wait to ensure console logs are captured
614+ await authPage . waitForTimeout ( 2000 ) ;
615+
616+ // Log page content for debugging
617+ const pageContent = await authPage . locator ( "main" ) . textContent ( ) ;
618+ console . log ( `Page content: ${ pageContent ?. substring ( 0 , 500 ) } ` ) ;
619+
620+ // Verify at least one session is displayed
621+ // The session rows use class="session-row" in the SessionRow component
622+ const sessionRows = authPage . locator ( ".session-row" ) ;
623+ const sessionCount = await sessionRows . count ( ) ;
624+ console . log ( `Found ${ sessionCount } session row(s)` ) ;
625+
626+ expect ( sessionCount , "At least one session should be displayed" ) . toBeGreaterThan ( 0 ) ;
627+ console . log ( `✓ Found ${ sessionCount } session(s) displayed` ) ;
628+
629+ // Verify empty state message is NOT shown
630+ const emptyState = authPage . getByText ( / n o a c t i v e s e s s i o n s / i) ;
631+ const emptyVisible = await emptyState . isVisible ( { timeout : 1000 } ) . catch ( ( ) => false ) ;
632+ expect ( emptyVisible , "Empty state should NOT be visible when sessions exist" ) . toBe ( false ) ;
633+ console . log ( "✓ Empty state correctly hidden" ) ;
634+
635+ await authPage . close ( ) ;
636+ console . log ( "\n=== Session Display Test Complete ===\n" ) ;
637+ } ) ;
0 commit comments