@@ -2,12 +2,15 @@ import { CommonModule } from '@angular/common';
22import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
33import {
44 ComponentFixture ,
5+ fakeAsync ,
56 inject ,
67 TestBed ,
8+ tick ,
79 waitForAsync ,
810} from '@angular/core/testing' ;
911import {
1012 ActivatedRoute ,
13+ NavigationStart ,
1114 Router ,
1215} from '@angular/router' ;
1316import {
@@ -19,7 +22,10 @@ import {
1922 TranslateLoader ,
2023 TranslateModule ,
2124} from '@ngx-translate/core' ;
22- import { of } from 'rxjs' ;
25+ import {
26+ of ,
27+ Subject ,
28+ } from 'rxjs' ;
2329
2430import { APP_CONFIG } from '../config/app-config.interface' ;
2531import { environment } from '../environments/environment' ;
@@ -46,7 +52,6 @@ import { MockActivatedRoute } from './shared/mocks/active-router.mock';
4652import { AngularticsProviderMock } from './shared/mocks/angulartics-provider.service.mock' ;
4753import { AuthServiceMock } from './shared/mocks/auth.service.mock' ;
4854import { HeadTagServiceMock } from './shared/mocks/head-tag-service.mock' ;
49- import { RouterMock } from './shared/mocks/router.mock' ;
5055import { getMockThemeService } from './shared/mocks/theme-service.mock' ;
5156import { TranslateLoaderMock } from './shared/mocks/translate-loader.mock' ;
5257import { CSSVariableService } from './shared/sass-helper/css-variable.service' ;
@@ -65,6 +70,8 @@ const initialState = {
6570 core : { auth : { loading : false } } ,
6671} ;
6772
73+ const itemPageUrl = '/entities/publication/3b6ef8e8-15a1-4607-abf8-2a6fbd572346' ;
74+
6875export function getMockLocaleService ( ) : LocaleService {
6976 return jasmine . createSpyObj ( 'LocaleService' , {
7077 setCurrentLanguageCode : jasmine . createSpy ( 'setCurrentLanguageCode' ) ,
@@ -77,13 +84,20 @@ describe('App component', () => {
7784 let routeServiceMock ;
7885 let klaroServiceSpy : jasmine . SpyObj < KlaroService > ;
7986 let datadogRumServiceSpy : jasmine . SpyObj < DatadogRumService > ;
87+ let routerEventsObs : Subject < any > ;
88+ let routerMock : Router ;
8089
8190 const getDefaultTestBedConf = ( ) => {
8291 breadcrumbsServiceSpy = jasmine . createSpyObj ( [ 'listenForRouteChanges' ] ) ;
8392 routeServiceMock = jasmine . createSpyObj ( 'RouterService' , {
8493 getCurrentUrl : of ( '/home' ) ,
8594 } ) ;
8695
96+ routerEventsObs = new Subject < any > ( ) ;
97+ routerMock = jasmine . createSpyObj ( [ ] , {
98+ events : routerEventsObs ,
99+ } ) ;
100+
87101 klaroServiceSpy = jasmine . createSpyObj ( 'KlaroService' , {
88102 getSavedPreferences : jasmine . createSpy ( 'getSavedPreferences' ) ,
89103 watchConsentUpdates : jasmine . createSpy ( 'watchConsentUpdates' ) . and . returnValue ( null ) ,
@@ -112,7 +126,7 @@ describe('App component', () => {
112126 { provide : HeadTagService , useValue : new HeadTagServiceMock ( ) } ,
113127 { provide : Angulartics2DSpace , useValue : new AngularticsProviderMock ( ) } ,
114128 { provide : AuthService , useValue : new AuthServiceMock ( ) } ,
115- { provide : Router , useValue : new RouterMock ( ) } ,
129+ { provide : Router , useValue : routerMock } ,
116130 { provide : ActivatedRoute , useValue : new MockActivatedRoute ( ) } ,
117131 { provide : MenuService , useValue : menuService } ,
118132 { provide : CSSVariableService , useClass : CSSVariableServiceStub } ,
@@ -173,4 +187,32 @@ describe('App component', () => {
173187 } ) ;
174188
175189 } ) ;
190+
191+ describe ( 'isRouteLoading$ handling' , ( ) => {
192+
193+ it ( 'should not show loading for item page' , fakeAsync ( ( ) => {
194+ routeServiceMock . getCurrentUrl . and . returnValue ( of ( itemPageUrl ) ) ;
195+ routerEventsObs . next ( new NavigationStart ( 1 , itemPageUrl ) ) ;
196+ fixture . detectChanges ( ) ;
197+ tick ( ) ;
198+ expect ( comp . isRouteLoading$ . value ) . toBeFalse ( ) ;
199+ } ) ) ;
200+
201+ it ( 'should show loading for item page administrative edit' , fakeAsync ( ( ) => {
202+ routeServiceMock . getCurrentUrl . and . returnValue ( of ( itemPageUrl ) ) ;
203+ routerEventsObs . next ( new NavigationStart ( 2 , itemPageUrl + '/edit' ) ) ;
204+ fixture . detectChanges ( ) ;
205+ tick ( ) ;
206+ expect ( comp . isRouteLoading$ . value ) . toBeTrue ( ) ;
207+ } ) ) ;
208+
209+ it ( 'should not show loading navigating between item pages in administrative edit' , fakeAsync ( ( ) => {
210+ routeServiceMock . getCurrentUrl . and . returnValue ( of ( itemPageUrl + '/edit' ) ) ;
211+ routerEventsObs . next ( new NavigationStart ( 2 , itemPageUrl + '/edit/status' ) ) ;
212+ fixture . detectChanges ( ) ;
213+ tick ( ) ;
214+ expect ( comp . isRouteLoading$ . value ) . toBeFalse ( ) ;
215+ } ) ) ;
216+
217+ } ) ;
176218} ) ;
0 commit comments