@@ -258,6 +258,34 @@ describe('ApplicationService', () => {
258258 expect ( history . entries . length ) . toEqual ( 2 ) ;
259259 expect ( history . entries [ 1 ] . pathname ) . toEqual ( '/app/app1' ) ;
260260 } ) ;
261+
262+ it ( 'does not trigger navigation check if navigating to the current app' , async ( ) => {
263+ startDeps . overlays . openConfirm . mockResolvedValue ( false ) ;
264+
265+ const { register } = service . setup ( setupDeps ) ;
266+
267+ register ( Symbol ( ) , {
268+ id : 'app1' ,
269+ title : 'App1' ,
270+ mount : ( { onAppLeave } : AppMountParameters ) => {
271+ onAppLeave ( ( actions ) => actions . confirm ( 'confirmation-message' , 'confirmation-title' ) ) ;
272+ return ( ) => undefined ;
273+ } ,
274+ } ) ;
275+
276+ const { navigateToApp, getComponent } = await service . start ( startDeps ) ;
277+
278+ update = createRenderer ( getComponent ( ) ) ;
279+
280+ await act ( async ( ) => {
281+ await navigate ( '/app/app1' ) ;
282+ await navigateToApp ( 'app1' , { path : '/internal-path' } ) ;
283+ } ) ;
284+
285+ expect ( startDeps . overlays . openConfirm ) . not . toHaveBeenCalled ( ) ;
286+ expect ( history . entries . length ) . toEqual ( 3 ) ;
287+ expect ( history . entries [ 2 ] . pathname ) . toEqual ( '/app/app1/internal-path' ) ;
288+ } ) ;
261289 } ) ;
262290
263291 describe ( 'registering action menus' , ( ) => {
@@ -331,6 +359,48 @@ describe('ApplicationService', () => {
331359 expect ( await getValue ( currentActionMenu$ ) ) . toBe ( mounter2 ) ;
332360 } ) ;
333361
362+ it ( 'does not update the observable value when navigating to the current app' , async ( ) => {
363+ const { register } = service . setup ( setupDeps ) ;
364+
365+ let initialMount = true ;
366+ register ( Symbol ( ) , {
367+ id : 'app1' ,
368+ title : 'App1' ,
369+ mount : async ( { setHeaderActionMenu } : AppMountParameters ) => {
370+ if ( initialMount ) {
371+ setHeaderActionMenu ( mounter1 ) ;
372+ initialMount = false ;
373+ }
374+ return ( ) => undefined ;
375+ } ,
376+ } ) ;
377+
378+ const { navigateToApp, getComponent, currentActionMenu$ } = await service . start ( startDeps ) ;
379+ update = createRenderer ( getComponent ( ) ) ;
380+
381+ let mountedMenuCount = 0 ;
382+ currentActionMenu$ . subscribe ( ( ) => {
383+ mountedMenuCount ++ ;
384+ } ) ;
385+
386+ await act ( async ( ) => {
387+ await navigateToApp ( 'app1' ) ;
388+ await flushPromises ( ) ;
389+ } ) ;
390+
391+ expect ( await getValue ( currentActionMenu$ ) ) . toBe ( mounter1 ) ;
392+
393+ await act ( async ( ) => {
394+ await navigateToApp ( 'app1' ) ;
395+ await flushPromises ( ) ;
396+ } ) ;
397+
398+ expect ( await getValue ( currentActionMenu$ ) ) . toBe ( mounter1 ) ;
399+
400+ // there is an initial 'undefined' emission
401+ expect ( mountedMenuCount ) . toBe ( 2 ) ;
402+ } ) ;
403+
334404 it ( 'updates the observable value to undefined when switching to an application without action menu' , async ( ) => {
335405 const { register } = service . setup ( setupDeps ) ;
336406
0 commit comments