1- import type { AuthMessage } from '../../../data-context/src/actions/AuthActions'
1+ import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
2+ import type { AuthStateShape } from '@packages/data-context/src/data'
3+
4+ const loginText = defaultMessages . topNav . login
25
36describe ( 'App Top Nav Workflows' , ( ) => {
47 beforeEach ( ( ) => {
@@ -312,7 +315,7 @@ describe('App Top Nav Workflows', () => {
312315 } )
313316 } )
314317
315- cy . intercept ( 'mutation-Logout ' ) . as ( 'logout' )
318+ cy . intercept ( 'mutation-Auth_Logout ' ) . as ( 'logout' )
316319
317320 cy . findByRole ( 'button' , { name : 'Log Out' } ) . click ( )
318321
@@ -338,7 +341,7 @@ describe('App Top Nav Workflows', () => {
338341 cy . withCtx ( ( ctx , options ) => {
339342 // @ts -ignore sinon is a global in the node process where this is executed
340343 sinon . stub ( ctx . _apis . authApi , 'logIn' ) . callsFake ( async ( onMessage ) => {
341- onMessage ( { browserOpened : true } as AuthMessage )
344+ onMessage ( { browserOpened : true } as AuthStateShape )
342345
343346 return new Promise ( ( resolve ) => {
344347 setTimeout ( ( ) => {
@@ -415,6 +418,116 @@ describe('App Top Nav Workflows', () => {
415418 cy . get ( '@logInModal' ) . should ( 'not.exist' )
416419 cy . findByTestId ( 'app-header-bar' ) . findByTestId ( 'user-avatar-title' ) . should ( 'be.visible' )
417420 } )
421+
422+ it ( 'shows correct error when browser cannot launch' , ( ) => {
423+ cy . withCtx ( ( ctx ) => {
424+ ctx . coreData . authState = {
425+ name : 'AUTH_COULD_NOT_LAUNCH_BROWSER' ,
426+ message : 'http://127.0.0.1:0000/redirect-to-auth' ,
427+ browserOpened : false ,
428+ }
429+ } )
430+
431+ cy . findByTestId ( 'app-header-bar' ) . within ( ( ) => {
432+ cy . findByTestId ( 'user-avatar-title' ) . should ( 'not.exist' )
433+ cy . findByRole ( 'button' , { name : 'Log In' } ) . click ( )
434+ } )
435+
436+ cy . contains ( 'http://127.0.0.1:0000/redirect-to-auth' ) . should ( 'be.visible' )
437+ cy . contains ( loginText . titleBrowserError ) . should ( 'be.visible' )
438+ cy . contains ( loginText . bodyBrowserError ) . should ( 'be.visible' )
439+ cy . contains ( loginText . bodyBrowserErrorDetails ) . should ( 'be.visible' )
440+
441+ // in this state, there is no retry UI, we ask the user to visit the auth url on their own
442+ cy . contains ( 'button' , loginText . actionTryAgain ) . should ( 'not.exist' )
443+ cy . contains ( 'button' , loginText . actionCancel ) . should ( 'not.exist' )
444+ } )
445+
446+ it ( 'shows correct error when error other than browser-launch happens' , ( ) => {
447+ cy . withCtx ( ( ctx ) => {
448+ ctx . coreData . authState = {
449+ name : 'AUTH_ERROR_DURING_LOGIN' ,
450+ message : 'An unexpected error occurred' ,
451+ browserOpened : false ,
452+ }
453+ } )
454+
455+ cy . findByTestId ( 'app-header-bar' ) . within ( ( ) => {
456+ cy . findByTestId ( 'user-avatar-title' ) . should ( 'not.exist' )
457+ cy . findByRole ( 'button' , { name : 'Log In' } ) . click ( )
458+ } )
459+
460+ cy . contains ( loginText . titleFailed ) . should ( 'be.visible' )
461+ cy . contains ( loginText . bodyError ) . should ( 'be.visible' )
462+ cy . contains ( 'An unexpected error occurred' ) . should ( 'be.visible' )
463+
464+ cy . contains ( 'button' , loginText . actionTryAgain ) . should ( 'be.visible' ) . as ( 'tryAgain' )
465+ cy . contains ( 'button' , loginText . actionCancel ) . should ( 'be.visible' )
466+
467+ cy . percySnapshot ( )
468+
469+ cy . withCtx ( ( ctx ) => {
470+ ctx . coreData . authState = {
471+ name : 'AUTH_BROWSER_LAUNCHED' ,
472+ message : '' ,
473+ browserOpened : true ,
474+ }
475+ } )
476+
477+ cy . get ( '@tryAgain' ) . click ( )
478+ cy . contains ( loginText . titleInitial ) . should ( 'be.visible' )
479+ } )
480+
481+ it ( 'cancel button correctly clears error state' , ( ) => {
482+ cy . withCtx ( ( ctx ) => {
483+ ctx . coreData . authState = {
484+ name : 'AUTH_ERROR_DURING_LOGIN' ,
485+ message : 'An unexpected error occurred' ,
486+ browserOpened : false ,
487+ }
488+ } )
489+
490+ cy . findByTestId ( 'app-header-bar' ) . within ( ( ) => {
491+ cy . findByTestId ( 'user-avatar-title' ) . should ( 'not.exist' )
492+ cy . findByRole ( 'button' , { name : 'Log In' } ) . as ( 'loginButton' ) . click ( )
493+ } )
494+
495+ cy . contains ( loginText . titleFailed ) . should ( 'be.visible' )
496+ cy . contains ( loginText . bodyError ) . should ( 'be.visible' )
497+ cy . contains ( 'An unexpected error occurred' ) . should ( 'be.visible' )
498+
499+ cy . percySnapshot ( )
500+
501+ cy . contains ( 'button' , loginText . actionTryAgain ) . should ( 'be.visible' )
502+ cy . contains ( 'button' , loginText . actionCancel ) . click ( )
503+
504+ cy . get ( '@loginButton' ) . click ( )
505+ cy . contains ( loginText . titleInitial ) . should ( 'be.visible' )
506+ } )
507+
508+ it ( 'closing modal correctly clears error state' , ( ) => {
509+ cy . withCtx ( ( ctx ) => {
510+ ctx . coreData . authState = {
511+ name : 'AUTH_ERROR_DURING_LOGIN' ,
512+ message : 'An unexpected error occurred' ,
513+ browserOpened : false ,
514+ }
515+ } )
516+
517+ cy . findByTestId ( 'app-header-bar' ) . within ( ( ) => {
518+ cy . findByTestId ( 'user-avatar-title' ) . should ( 'not.exist' )
519+ cy . findByRole ( 'button' , { name : 'Log In' } ) . as ( 'loginButton' ) . click ( )
520+ } )
521+
522+ cy . contains ( loginText . titleFailed ) . should ( 'be.visible' )
523+ cy . contains ( loginText . bodyError ) . should ( 'be.visible' )
524+ cy . contains ( 'An unexpected error occurred' ) . should ( 'be.visible' )
525+
526+ cy . findByLabelText ( defaultMessages . actions . close ) . click ( )
527+
528+ cy . get ( '@loginButton' ) . click ( )
529+ cy . contains ( loginText . titleInitial ) . should ( 'be.visible' )
530+ } )
418531 } )
419532 } )
420533} )
0 commit comments