@@ -32,7 +32,6 @@ import { storeModuleConfig } from './app.reducer';
3232import { LocaleService } from './core/locale/locale.service' ;
3333import { authReducer } from './core/auth/auth.reducer' ;
3434import { provideMockStore } from '@ngrx/store/testing' ;
35- import { GoogleAnalyticsService } from './statistics/google-analytics.service' ;
3635import { ThemeService } from './shared/theme-support/theme.service' ;
3736import { getMockThemeService } from './shared/mocks/theme-service.mock' ;
3837import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service' ;
@@ -46,16 +45,16 @@ const initialState = {
4645 core : { auth : { loading : false } }
4746} ;
4847
48+ export function getMockLocaleService ( ) : LocaleService {
49+ return jasmine . createSpyObj ( 'LocaleService' , {
50+ setCurrentLanguageCode : jasmine . createSpy ( 'setCurrentLanguageCode' )
51+ } ) ;
52+ }
53+
4954describe ( 'App component' , ( ) => {
5055
5156 let breadcrumbsServiceSpy ;
5257
53- function getMockLocaleService ( ) : LocaleService {
54- return jasmine . createSpyObj ( 'LocaleService' , {
55- setCurrentLanguageCode : jasmine . createSpy ( 'setCurrentLanguageCode' )
56- } ) ;
57- }
58-
5958 const getDefaultTestBedConf = ( ) => {
6059 breadcrumbsServiceSpy = jasmine . createSpyObj ( [ 'listenForRouteChanges' ] ) ;
6160
@@ -130,66 +129,4 @@ describe('App component', () => {
130129 } ) ;
131130
132131 } ) ;
133-
134- describe ( 'the constructor' , ( ) => {
135- it ( 'should call breadcrumbsService.listenForRouteChanges' , ( ) => {
136- expect ( breadcrumbsServiceSpy . listenForRouteChanges ) . toHaveBeenCalledTimes ( 1 ) ;
137- } ) ;
138- } ) ;
139-
140- describe ( 'when GoogleAnalyticsService is provided' , ( ) => {
141- let googleAnalyticsSpy ;
142-
143- beforeEach ( ( ) => {
144- // NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
145- TestBed . resetTestingModule ( ) ;
146- TestBed . configureTestingModule ( getDefaultTestBedConf ( ) ) ;
147- googleAnalyticsSpy = jasmine . createSpyObj ( 'googleAnalyticsService' , [
148- 'addTrackingIdToPage' ,
149- ] ) ;
150- TestBed . overrideProvider ( GoogleAnalyticsService , { useValue : googleAnalyticsSpy } ) ;
151- fixture = TestBed . createComponent ( AppComponent ) ;
152- comp = fixture . componentInstance ;
153- fixture . detectChanges ( ) ;
154- } ) ;
155-
156- it ( 'should create component' , ( ) => {
157- expect ( comp ) . toBeTruthy ( ) ;
158- } ) ;
159-
160- describe ( 'the constructor' , ( ) => {
161- it ( 'should call googleAnalyticsService.addTrackingIdToPage()' , ( ) => {
162- expect ( googleAnalyticsSpy . addTrackingIdToPage ) . toHaveBeenCalledTimes ( 1 ) ;
163- } ) ;
164- } ) ;
165- } ) ;
166-
167- describe ( 'when ThemeService returns a custom theme' , ( ) => {
168- let document ;
169- let headSpy ;
170-
171- beforeEach ( ( ) => {
172- // NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
173- TestBed . resetTestingModule ( ) ;
174- TestBed . configureTestingModule ( getDefaultTestBedConf ( ) ) ;
175- TestBed . overrideProvider ( ThemeService , { useValue : getMockThemeService ( 'custom' ) } ) ;
176- document = TestBed . inject ( DOCUMENT ) ;
177- headSpy = jasmine . createSpyObj ( 'head' , [ 'appendChild' , 'getElementsByClassName' ] ) ;
178- headSpy . getElementsByClassName . and . returnValue ( [ ] ) ;
179- spyOn ( document , 'getElementsByTagName' ) . and . returnValue ( [ headSpy ] ) ;
180- fixture = TestBed . createComponent ( AppComponent ) ;
181- comp = fixture . componentInstance ;
182- fixture . detectChanges ( ) ;
183- } ) ;
184-
185- it ( 'should append a link element with the correct attributes to the head element' , ( ) => {
186- const link = document . createElement ( 'link' ) ;
187- link . setAttribute ( 'rel' , 'stylesheet' ) ;
188- link . setAttribute ( 'type' , 'text/css' ) ;
189- link . setAttribute ( 'class' , 'theme-css' ) ;
190- link . setAttribute ( 'href' , 'custom-theme.css' ) ;
191-
192- expect ( headSpy . appendChild ) . toHaveBeenCalledWith ( link ) ;
193- } ) ;
194- } ) ;
195132} ) ;
0 commit comments