diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index c092362c7e6..3f2dc45ce7d 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -35,6 +35,7 @@ import { provideMockStore } from '@ngrx/store/testing'; import { GoogleAnalyticsService } from './statistics/google-analytics.service'; import { ThemeService } from './shared/theme-support/theme.service'; import { getMockThemeService } from './shared/mocks/theme-service.mock'; +import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service'; let comp: AppComponent; let fixture: ComponentFixture; @@ -45,47 +46,54 @@ const initialState = { describe('App component', () => { + let breadcrumbsServiceSpy; + function getMockLocaleService(): LocaleService { return jasmine.createSpyObj('LocaleService', { setCurrentLanguageCode: jasmine.createSpy('setCurrentLanguageCode') }); } - const defaultTestBedConf = { - imports: [ - CommonModule, - StoreModule.forRoot(authReducer, storeModuleConfig), - TranslateModule.forRoot({ - loader: { - provide: TranslateLoader, - useClass: TranslateLoaderMock - } - }), - ], - declarations: [AppComponent], // declare the test component - providers: [ - { provide: NativeWindowService, useValue: new NativeWindowRef() }, - { provide: MetadataService, useValue: new MetadataServiceMock() }, - { provide: Angulartics2GoogleAnalytics, useValue: new AngularticsProviderMock() }, - { provide: Angulartics2DSpace, useValue: new AngularticsProviderMock() }, - { provide: AuthService, useValue: new AuthServiceMock() }, - { provide: Router, useValue: new RouterMock() }, - { provide: ActivatedRoute, useValue: new MockActivatedRoute() }, - { provide: MenuService, useValue: menuService }, - { provide: CSSVariableService, useClass: CSSVariableServiceStub }, - { provide: HostWindowService, useValue: new HostWindowServiceStub(800) }, - { provide: LocaleService, useValue: getMockLocaleService() }, - { provide: ThemeService, useValue: getMockThemeService() }, - provideMockStore({ initialState }), - AppComponent, - RouteService - ], - schemas: [CUSTOM_ELEMENTS_SCHEMA] + const getDefaultTestBedConf = () => { + breadcrumbsServiceSpy = jasmine.createSpyObj(['listenForRouteChanges']); + + return { + imports: [ + CommonModule, + StoreModule.forRoot(authReducer, storeModuleConfig), + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useClass: TranslateLoaderMock + } + }), + ], + declarations: [AppComponent], // declare the test component + providers: [ + { provide: NativeWindowService, useValue: new NativeWindowRef() }, + { provide: MetadataService, useValue: new MetadataServiceMock() }, + { provide: Angulartics2GoogleAnalytics, useValue: new AngularticsProviderMock() }, + { provide: Angulartics2DSpace, useValue: new AngularticsProviderMock() }, + { provide: AuthService, useValue: new AuthServiceMock() }, + { provide: Router, useValue: new RouterMock() }, + { provide: ActivatedRoute, useValue: new MockActivatedRoute() }, + { provide: MenuService, useValue: menuService }, + { provide: CSSVariableService, useClass: CSSVariableServiceStub }, + { provide: HostWindowService, useValue: new HostWindowServiceStub(800) }, + { provide: LocaleService, useValue: getMockLocaleService() }, + { provide: ThemeService, useValue: getMockThemeService() }, + { provide: BreadcrumbsService, useValue: breadcrumbsServiceSpy }, + provideMockStore({ initialState }), + AppComponent, + RouteService + ], + schemas: [CUSTOM_ELEMENTS_SCHEMA] + }; }; // waitForAsync beforeEach beforeEach(waitForAsync(() => { - return TestBed.configureTestingModule(defaultTestBedConf); + return TestBed.configureTestingModule(getDefaultTestBedConf()); })); // synchronous beforeEach @@ -120,13 +128,19 @@ describe('App component', () => { }); + describe('the constructor', () => { + it('should call breadcrumbsService.listenForRouteChanges', () => { + expect(breadcrumbsServiceSpy.listenForRouteChanges).toHaveBeenCalledTimes(1); + }); + }); + describe('when GoogleAnalyticsService is provided', () => { let googleAnalyticsSpy; beforeEach(() => { // NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset TestBed.resetTestingModule(); - TestBed.configureTestingModule(defaultTestBedConf); + TestBed.configureTestingModule(getDefaultTestBedConf()); googleAnalyticsSpy = jasmine.createSpyObj('googleAnalyticsService', [ 'addTrackingIdToPage', ]); @@ -154,7 +168,7 @@ describe('App component', () => { beforeEach(() => { // NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset TestBed.resetTestingModule(); - TestBed.configureTestingModule(defaultTestBedConf); + TestBed.configureTestingModule(getDefaultTestBedConf()); TestBed.overrideProvider(ThemeService, {useValue: getMockThemeService('custom')}); document = TestBed.inject(DOCUMENT); headSpy = jasmine.createSpyObj('head', ['appendChild']); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8a38d14fe30..a596ba56cd4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -36,6 +36,7 @@ import { DOCUMENT } from '@angular/common'; import { ThemeService } from './shared/theme-support/theme.service'; import { BASE_THEME_NAME } from './shared/theme-support/theme.constants'; import { DEFAULT_THEME_CONFIG } from './shared/theme-support/theme.effects'; +import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service'; @Component({ selector: 'ds-app', @@ -73,6 +74,7 @@ export class AppComponent implements OnInit, AfterViewInit { private menuService: MenuService, private windowService: HostWindowService, private localeService: LocaleService, + private breadcrumbsService: BreadcrumbsService, @Optional() private cookiesService: KlaroService, @Optional() private googleAnalyticsService: GoogleAnalyticsService, ) { @@ -106,6 +108,7 @@ export class AppComponent implements OnInit, AfterViewInit { angulartics2DSpace.startTracking(); metadata.listenForRouteChange(); + breadcrumbsService.listenForRouteChanges(); if (environment.debug) { console.info(environment); diff --git a/src/app/breadcrumbs/breadcrumb/breadcrumb-config.model.ts b/src/app/breadcrumbs/breadcrumb/breadcrumb-config.model.ts index 0ff8fc5033b..cc9277ee50b 100644 --- a/src/app/breadcrumbs/breadcrumb/breadcrumb-config.model.ts +++ b/src/app/breadcrumbs/breadcrumb/breadcrumb-config.model.ts @@ -1,4 +1,4 @@ -import { BreadcrumbsService } from '../../core/breadcrumbs/breadcrumbs.service'; +import { BreadcrumbsProviderService } from '../../core/breadcrumbs/breadcrumbsProviderService'; /** * Interface for breadcrumb configuration objects @@ -7,7 +7,7 @@ export interface BreadcrumbConfig { /** * The service used to calculate the breadcrumb object */ - provider: BreadcrumbsService; + provider: BreadcrumbsProviderService; /** * The key that is used to calculate the breadcrumb display value diff --git a/src/app/breadcrumbs/breadcrumbs.component.html b/src/app/breadcrumbs/breadcrumbs.component.html index 1f142526e27..a6072ed58a6 100644 --- a/src/app/breadcrumbs/breadcrumbs.component.html +++ b/src/app/breadcrumbs/breadcrumbs.component.html @@ -1,5 +1,5 @@ -