@@ -17,7 +17,13 @@ import {
1717 createMockSigninOAuthNativeIntegration ,
1818 createMockSigninOAuthIntegration ,
1919} from './mocks' ;
20- import { handleNavigation , ensureCanLinkAcountOrRedirect } from './utils' ;
20+ import {
21+ handleNavigation ,
22+ ensureCanLinkAcountOrRedirect ,
23+ getSyncNavigate ,
24+ isSendTabEntrypoint ,
25+ } from './utils' ;
26+ import { SEND_TAB_ENTRYPOINTS } from '../../constants' ;
2127import * as ReachRouter from '@reach/router' ;
2228import * as ReactUtils from 'fxa-react/lib/utils' ;
2329import firefox from '../../lib/channels/firefox' ;
@@ -344,6 +350,65 @@ describe('Signin utils', () => {
344350 ) ;
345351 } ) ;
346352 } ) ;
353+
354+ describe ( 'handleNavigation with send-tab entrypoints' , ( ) => {
355+ const createSendTabNavigationOptions = (
356+ overrides : Partial < NavigationOptions > = { }
357+ ) : NavigationOptions =>
358+ ( {
359+ email : MOCK_EMAIL ,
360+ signinData : {
361+ uid : MOCK_UID ,
362+ sessionToken : MOCK_SESSION_TOKEN ,
363+ emailVerified : true ,
364+ sessionVerified : true ,
365+ verificationMethod : VerificationMethods . EMAIL ,
366+ verificationReason : VerificationReasons . SIGN_IN ,
367+ keyFetchToken : MOCK_KEY_FETCH_TOKEN ,
368+ } ,
369+ redirectTo : '' ,
370+ finishOAuthFlowHandler : jest
371+ . fn ( )
372+ . mockReturnValue ( MOCK_OAUTH_FLOW_HANDLER_RESPONSE ) ,
373+ queryParams : '' ,
374+ ...overrides ,
375+ } ) as NavigationOptions ;
376+
377+ it ( 'clears showInlineRecoveryKeySetup for send-tab sign-in and navigates to /pair' , async ( ) => {
378+ const navigationOptions = createSendTabNavigationOptions ( {
379+ integration : createMockSigninOAuthNativeSyncIntegration ( ) ,
380+ queryParams : '?service=sync&entrypoint=send-tab-toolbar-icon' ,
381+ showInlineRecoveryKeySetup : true ,
382+ handleFxaLogin : true ,
383+ } ) ;
384+
385+ await handleNavigation ( navigationOptions ) ;
386+
387+ expect ( hardNavigateSpy ) . toHaveBeenCalled ( ) ;
388+ const navigatedUrl = hardNavigateSpy . mock . calls [ 0 ] [ 0 ] as string ;
389+ expect ( navigatedUrl ) . toContain ( '/pair?' ) ;
390+ expect ( navigatedUrl ) . toContain ( 'showSuccessMessage=true' ) ;
391+ expect ( navigatedUrl ) . not . toContain ( 'inline_recovery_key' ) ;
392+ } ) ;
393+
394+ it ( 'clears showSignupConfirmedSync for send-tab post-verify and navigates to /pair with passwordCreated' , async ( ) => {
395+ const navigationOptions = createSendTabNavigationOptions ( {
396+ integration : createMockSigninOAuthNativeSyncIntegration ( ) ,
397+ queryParams : '?service=sync&entrypoint=send-tab-app-menu' ,
398+ showSignupConfirmedSync : true ,
399+ origin : 'post-verify-set-password' ,
400+ handleFxaLogin : true ,
401+ } ) ;
402+
403+ await handleNavigation ( navigationOptions ) ;
404+
405+ expect ( hardNavigateSpy ) . toHaveBeenCalled ( ) ;
406+ const navigatedUrl = hardNavigateSpy . mock . calls [ 0 ] [ 0 ] as string ;
407+ expect ( navigatedUrl ) . toContain ( '/pair?' ) ;
408+ expect ( navigatedUrl ) . toContain ( 'showSuccessMessage=true' ) ;
409+ expect ( navigatedUrl ) . toContain ( 'passwordCreated=true' ) ;
410+ } ) ;
411+ } ) ;
347412 } ) ;
348413
349414 describe ( 'ensureCanLinkAcountOrRedirect' , ( ) => {
@@ -400,4 +465,69 @@ describe('Signin utils', () => {
400465 } ) ;
401466 } ) ;
402467 } ) ;
468+
469+ describe ( 'isSendTabEntrypoint' , ( ) => {
470+ it ( 'returns true for all send-tab entrypoints' , ( ) => {
471+ for ( const entrypoint of SEND_TAB_ENTRYPOINTS ) {
472+ expect ( isSendTabEntrypoint ( `?entrypoint=${ entrypoint } ` ) ) . toBe ( true ) ;
473+ }
474+ } ) ;
475+
476+ it ( 'returns false for non-send-tab entrypoints' , ( ) => {
477+ expect ( isSendTabEntrypoint ( '?entrypoint=preferences' ) ) . toBe ( false ) ;
478+ expect ( isSendTabEntrypoint ( '?entrypoint=fxa_app_menu' ) ) . toBe ( false ) ;
479+ expect ( isSendTabEntrypoint ( '' ) ) . toBe ( false ) ;
480+ expect ( isSendTabEntrypoint ( '?service=sync' ) ) . toBe ( false ) ;
481+ } ) ;
482+ } ) ;
483+
484+ describe ( 'getSyncNavigate' , ( ) => {
485+ it ( 'returns /inline_recovery_key_setup when showInlineRecoveryKeySetup is true' , ( ) => {
486+ const result = getSyncNavigate ( '?service=sync' , {
487+ showInlineRecoveryKeySetup : true ,
488+ } ) ;
489+ expect ( result . to ) . toContain ( '/inline_recovery_key_setup?' ) ;
490+ } ) ;
491+
492+ it ( 'returns /signup_confirmed_sync when showSignupConfirmedSync is true' , ( ) => {
493+ const result = getSyncNavigate ( '?service=sync' , {
494+ showSignupConfirmedSync : true ,
495+ } ) ;
496+ expect ( result . to ) . toContain ( '/signup_confirmed_sync?' ) ;
497+ } ) ;
498+
499+ describe ( '/pair redirect' , ( ) => {
500+ it ( 'returns /pair with showSuccessMessage by default' , ( ) => {
501+ const result = getSyncNavigate ( '?service=sync' ) ;
502+ expect ( result . to ) . toContain ( '/pair?' ) ;
503+ expect ( result . to ) . toContain ( 'showSuccessMessage=true' ) ;
504+ expect ( result . shouldHardNavigate ) . toBe ( true ) ;
505+ } ) ;
506+
507+ it ( 'includes signupSuccess param when signupSuccess is true' , ( ) => {
508+ const result = getSyncNavigate ( '?service=sync' , {
509+ signupSuccess : true ,
510+ } ) ;
511+ expect ( result . to ) . toContain ( '/pair?' ) ;
512+ expect ( result . to ) . toContain ( 'signupSuccess=true' ) ;
513+ expect ( result . to ) . toContain ( 'showSuccessMessage=true' ) ;
514+ } ) ;
515+
516+ it ( 'includes passwordCreated param when origin is post-verify-set-password' , ( ) => {
517+ const result = getSyncNavigate ( '?service=sync' , {
518+ origin : 'post-verify-set-password' ,
519+ } ) ;
520+ expect ( result . to ) . toContain ( '/pair?' ) ;
521+ expect ( result . to ) . toContain ( 'passwordCreated=true' ) ;
522+ expect ( result . to ) . toContain ( 'showSuccessMessage=true' ) ;
523+ } ) ;
524+
525+ it ( 'does not include passwordCreated for other origins' , ( ) => {
526+ const result = getSyncNavigate ( '?service=sync' , {
527+ origin : 'signup' ,
528+ } ) ;
529+ expect ( result . to ) . not . toContain ( 'passwordCreated' ) ;
530+ } ) ;
531+ } ) ;
532+ } ) ;
403533} ) ;
0 commit comments