11import { Store , StoreModule } from '@ngrx/store' ;
2- import { ComponentFixture , inject , TestBed , waitForAsync } from '@angular/core/testing' ;
2+ import { ComponentFixture , fakeAsync , inject , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
33import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
44import { CommonModule } from '@angular/common' ;
5- import { ActivatedRoute , Router } from '@angular/router' ;
5+ import { ActivatedRoute , NavigationStart , Router } from '@angular/router' ;
66import { TranslateLoader , TranslateModule } from '@ngx-translate/core' ;
77
88// Load the implementations that should be tested
@@ -25,7 +25,6 @@ import { HostWindowService } from './shared/host-window.service';
2525import { HostWindowServiceStub } from './shared/testing/host-window-service.stub' ;
2626import { RouteService } from './core/services/route.service' ;
2727import { MockActivatedRoute } from './shared/mocks/active-router.mock' ;
28- import { RouterMock } from './shared/mocks/router.mock' ;
2928import { Angulartics2DSpace } from './statistics/angulartics/dspace-provider' ;
3029import { storeModuleConfig } from './app.reducer' ;
3130import { LocaleService } from './core/locale/locale.service' ;
@@ -34,7 +33,7 @@ import { provideMockStore } from '@ngrx/store/testing';
3433import { ThemeService } from './shared/theme-support/theme.service' ;
3534import { getMockThemeService } from './shared/mocks/theme-service.mock' ;
3635import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service' ;
37- import { of } from 'rxjs' ;
36+ import { of , Subject } from 'rxjs' ;
3837import { APP_CONFIG } from '../config/app-config.interface' ;
3938import { environment } from '../environments/environment' ;
4039import { KlaroService } from './shared/cookies/klaro.service' ;
@@ -47,6 +46,8 @@ const initialState = {
4746 core : { auth : { loading : false } }
4847} ;
4948
49+ const itemPageUrl = '/entities/publication/3b6ef8e8-15a1-4607-abf8-2a6fbd572346' ;
50+
5051export function getMockLocaleService ( ) : LocaleService {
5152 return jasmine . createSpyObj ( 'LocaleService' , {
5253 setCurrentLanguageCode : jasmine . createSpy ( 'setCurrentLanguageCode' )
@@ -59,13 +60,20 @@ describe('App component', () => {
5960 let routeServiceMock ;
6061 let klaroServiceSpy : jasmine . SpyObj < KlaroService > ;
6162 let datadogRumServiceSpy : jasmine . SpyObj < DatadogRumService > ;
63+ let routerEventsObs : Subject < any > ;
64+ let routerMock : Router ;
6265
6366 const getDefaultTestBedConf = ( ) => {
6467 breadcrumbsServiceSpy = jasmine . createSpyObj ( [ 'listenForRouteChanges' ] ) ;
6568 routeServiceMock = jasmine . createSpyObj ( 'RouterService' , {
6669 getCurrentUrl : of ( '/home' )
6770 } ) ;
6871
72+ routerEventsObs = new Subject < any > ( ) ;
73+ routerMock = jasmine . createSpyObj ( [ ] , {
74+ events : routerEventsObs ,
75+ } ) ;
76+
6977 klaroServiceSpy = jasmine . createSpyObj ( 'KlaroService' , {
7078 getSavedPreferences : jasmine . createSpy ( 'getSavedPreferences' ) ,
7179 watchConsentUpdates : jasmine . createSpy ( 'watchConsentUpdates' )
@@ -95,7 +103,7 @@ describe('App component', () => {
95103 { provide : MetadataService , useValue : new MetadataServiceMock ( ) } ,
96104 { provide : Angulartics2DSpace , useValue : new AngularticsProviderMock ( ) } ,
97105 { provide : AuthService , useValue : new AuthServiceMock ( ) } ,
98- { provide : Router , useValue : new RouterMock ( ) } ,
106+ { provide : Router , useValue : routerMock } ,
99107 { provide : ActivatedRoute , useValue : new MockActivatedRoute ( ) } ,
100108 { provide : MenuService , useValue : menuService } ,
101109 { provide : CSSVariableService , useClass : CSSVariableServiceStub } ,
@@ -151,4 +159,32 @@ describe('App component', () => {
151159 } ) ;
152160
153161 } ) ;
162+
163+ describe ( 'isRouteLoading$ handling' , ( ) => {
164+
165+ it ( 'should not show loading for item page' , fakeAsync ( ( ) => {
166+ routeServiceMock . getCurrentUrl . and . returnValue ( of ( itemPageUrl ) ) ;
167+ routerEventsObs . next ( new NavigationStart ( 1 , itemPageUrl ) ) ;
168+ fixture . detectChanges ( ) ;
169+ tick ( ) ;
170+ expect ( comp . isRouteLoading$ . value ) . toBeFalse ( ) ;
171+ } ) ) ;
172+
173+ it ( 'should show loading for item page administrative edit' , fakeAsync ( ( ) => {
174+ routeServiceMock . getCurrentUrl . and . returnValue ( of ( itemPageUrl ) ) ;
175+ routerEventsObs . next ( new NavigationStart ( 2 , itemPageUrl + '/edit' ) ) ;
176+ fixture . detectChanges ( ) ;
177+ tick ( ) ;
178+ expect ( comp . isRouteLoading$ . value ) . toBeTrue ( ) ;
179+ } ) ) ;
180+
181+ it ( 'should not show loading navigating between item pages in administrative edit' , fakeAsync ( ( ) => {
182+ routeServiceMock . getCurrentUrl . and . returnValue ( of ( itemPageUrl + '/edit' ) ) ;
183+ routerEventsObs . next ( new NavigationStart ( 2 , itemPageUrl + '/edit/status' ) ) ;
184+ fixture . detectChanges ( ) ;
185+ tick ( ) ;
186+ expect ( comp . isRouteLoading$ . value ) . toBeFalse ( ) ;
187+ } ) ) ;
188+
189+ } ) ;
154190} ) ;
0 commit comments