55import React , { ReactNode } from 'react' ;
66import { act , screen , waitFor } from '@testing-library/react' ;
77import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localizationProvider' ;
8+ import { navigate } from '@reach/router' ;
89import App from '.' ;
910import * as Metrics from '../../lib/metrics' ;
1011import {
@@ -29,12 +30,18 @@ import { firefox } from '../../lib/channels/firefox';
2930
3031import GleanMetrics from '../../lib/glean' ;
3132import config from '../../lib/config' ;
32- import * as utils from 'fxa-react/lib/utils' ;
3333import { currentAccount } from '../../lib/cache' ;
3434import { MozServices } from '../../lib/types' ;
3535import mockUseSyncEngines from '../../lib/hooks/useSyncEngines/mocks' ;
3636import useSyncEngines from '../../lib/hooks/useSyncEngines' ;
3737
38+ jest . mock ( '@reach/router' , ( ) => {
39+ return {
40+ ...jest . requireActual ( '@reach/router' ) ,
41+ navigate : jest . fn ( ) ,
42+ } ;
43+ } ) ;
44+
3845jest . mock ( '../../lib/hooks/useSyncEngines' , ( ) => ( {
3946 __esModule : true ,
4047 default : jest . fn ( ) ,
@@ -269,6 +276,7 @@ describe('loading spinner states', () => {
269276 } ) ;
270277 ( useSession as jest . Mock ) . mockReturnValue ( {
271278 isValid : ( ) => true ,
279+ isSessionVerified : ( ) => Promise . resolve ( true ) ,
272280 } ) ;
273281 ( currentAccount as jest . Mock ) . mockReturnValueOnce ( {
274282 uid : 123 ,
@@ -368,21 +376,10 @@ describe('AuthAndAccountSetupRoutes', () => {
368376} ) ;
369377
370378describe ( 'SettingsRoutes' , ( ) => {
371- let hardNavigateSpy : jest . SpyInstance ;
372379 const settingsPath = '/settings' ;
373- jest . mock ( '@reach/router' , ( ) => ( {
374- ...jest . requireActual ( '@reach/router' ) ,
375- useLocation : ( ) => {
376- return {
377- pathname : settingsPath ,
378- } ;
379- } ,
380- } ) ) ;
381380
382381 beforeEach ( ( ) => {
383- hardNavigateSpy = jest
384- . spyOn ( utils , 'hardNavigate' )
385- . mockImplementation ( ( ) => { } ) ;
382+ ( navigate as jest . Mock ) . mockClear ( ) ;
386383 ( useInitialMetricsQueryState as jest . Mock ) . mockReturnValue ( {
387384 loading : false ,
388385 } ) ;
@@ -396,6 +393,7 @@ describe('SettingsRoutes', () => {
396393 } ) ;
397394 ( useSession as jest . Mock ) . mockReturnValue ( {
398395 isValid : ( ) => false ,
396+ isSessionVerified : ( ) => Promise . resolve ( true ) ,
399397 } ) ;
400398 ( useProductInfoState as jest . Mock ) . mockReturnValue ( {
401399 loading : false ,
@@ -409,7 +407,7 @@ describe('SettingsRoutes', () => {
409407 } ) ;
410408
411409 afterEach ( ( ) => {
412- hardNavigateSpy . mockRestore ( ) ;
410+ ( navigate as jest . Mock ) . mockRestore ( ) ;
413411 ( useIntegration as jest . Mock ) . mockRestore ( ) ;
414412 ( useInitialMetricsQueryState as jest . Mock ) . mockRestore ( ) ;
415413 ( useLocalSignedInQueryState as jest . Mock ) . mockRestore ( ) ;
@@ -449,7 +447,7 @@ describe('SettingsRoutes', () => {
449447 await act ( ( ) => navigateResult ) ;
450448
451449 await waitFor ( ( ) => {
452- expect ( hardNavigateSpy ) . toHaveBeenCalledWith (
450+ expect ( navigate ) . toHaveBeenCalledWith (
453451 `/?redirect_to=${ encodeURIComponent ( settingsPath ) } `
454452 ) ;
455453 } ) ;
@@ -493,7 +491,7 @@ describe('SettingsRoutes', () => {
493491 await act ( ( ) => navigateResult ) ;
494492
495493 await waitFor ( ( ) => {
496- expect ( hardNavigateSpy ) . not . toHaveBeenCalled ( ) ;
494+ expect ( navigate ) . not . toHaveBeenCalled ( ) ;
497495 } ) ;
498496
499497 expect ( screen . getByText ( 'Session Expired' ) ) . toBeInTheDocument ( ) ;
@@ -529,6 +527,7 @@ describe('SettingsRoutes', () => {
529527
530528 ( useSession as jest . Mock ) . mockReturnValue ( {
531529 isValid : ( ) => true ,
530+ isSessionVerified : ( ) => Promise . resolve ( true ) ,
532531 } ) ;
533532
534533 let navigateResult : Promise < void > ;
@@ -556,7 +555,7 @@ describe('SettingsRoutes', () => {
556555 await act ( ( ) => navigateResult ) ;
557556
558557 await waitFor ( ( ) => {
559- expect ( hardNavigateSpy ) . not . toHaveBeenCalled ( ) ;
558+ expect ( navigate ) . not . toHaveBeenCalled ( ) ;
560559 } ) ;
561560 expect ( screen . getByTestId ( 'settings-profile' ) ) . toBeInTheDocument ( ) ;
562561 } ) ;
@@ -588,7 +587,7 @@ describe('SettingsRoutes', () => {
588587 await act ( ( ) => navigateResult ) ;
589588
590589 await waitFor ( ( ) => {
591- expect ( hardNavigateSpy ) . not . toHaveBeenCalled ( ) ;
590+ expect ( navigate ) . not . toHaveBeenCalled ( ) ;
592591 } ) ;
593592 expect ( screen . getByTestId ( 'settings-profile' ) ) . toBeInTheDocument ( ) ;
594593 } ) ;
0 commit comments