mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
Update specs
This commit is contained in:
@@ -2,11 +2,10 @@ import { InitService } from './init.service';
|
|||||||
import { APP_CONFIG } from 'src/config/app-config.interface';
|
import { APP_CONFIG } from 'src/config/app-config.interface';
|
||||||
import { APP_INITIALIZER, Injectable } from '@angular/core';
|
import { APP_INITIALIZER, Injectable } from '@angular/core';
|
||||||
import { inject, TestBed, waitForAsync } from '@angular/core/testing';
|
import { inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { GoogleAnalyticsService } from './statistics/google-analytics.service';
|
|
||||||
import { MetadataService } from './core/metadata/metadata.service';
|
import { MetadataService } from './core/metadata/metadata.service';
|
||||||
import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service';
|
import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Store, StoreModule } from '@ngrx/store';
|
import { StoreModule } from '@ngrx/store';
|
||||||
import { authReducer } from './core/auth/auth.reducer';
|
import { authReducer } from './core/auth/auth.reducer';
|
||||||
import { storeModuleConfig } from './app.reducer';
|
import { storeModuleConfig } from './app.reducer';
|
||||||
import { AngularticsProviderMock } from './shared/mocks/angulartics-provider.service.mock';
|
import { AngularticsProviderMock } from './shared/mocks/angulartics-provider.service.mock';
|
||||||
@@ -25,15 +24,13 @@ import { RouteService } from './core/services/route.service';
|
|||||||
import { getMockLocaleService } from './app.component.spec';
|
import { getMockLocaleService } from './app.component.spec';
|
||||||
import { MenuServiceStub } from './shared/testing/menu-service.stub';
|
import { MenuServiceStub } from './shared/testing/menu-service.stub';
|
||||||
import { CorrelationIdService } from './correlation-id/correlation-id.service';
|
import { CorrelationIdService } from './correlation-id/correlation-id.service';
|
||||||
import { KlaroService } from './shared/cookies/klaro.service';
|
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { TranslateLoaderMock } from './shared/mocks/translate-loader.mock';
|
import { TranslateLoaderMock } from './shared/mocks/translate-loader.mock';
|
||||||
import { getTestScheduler } from 'jasmine-marbles';
|
import { ThemeService } from './shared/theme-support/theme.service';
|
||||||
|
import { getMockThemeService } from './shared/mocks/theme-service.mock';
|
||||||
import objectContaining = jasmine.objectContaining;
|
import objectContaining = jasmine.objectContaining;
|
||||||
import createSpyObj = jasmine.createSpyObj;
|
import createSpyObj = jasmine.createSpyObj;
|
||||||
import SpyObj = jasmine.SpyObj;
|
import SpyObj = jasmine.SpyObj;
|
||||||
import { ThemeService } from './shared/theme-support/theme.service';
|
|
||||||
import { getMockThemeService } from './shared/mocks/theme-service.mock';
|
|
||||||
|
|
||||||
let spy: SpyObj<any>;
|
let spy: SpyObj<any>;
|
||||||
|
|
||||||
@@ -169,8 +166,6 @@ describe('InitService', () => {
|
|||||||
{ provide: Router, useValue: new RouterMock() },
|
{ provide: Router, useValue: new RouterMock() },
|
||||||
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
|
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
|
||||||
{ provide: MenuService, useValue: new MenuServiceStub() },
|
{ provide: MenuService, useValue: new MenuServiceStub() },
|
||||||
{ provide: KlaroService, useValue: undefined },
|
|
||||||
{ provide: GoogleAnalyticsService, useValue: undefined },
|
|
||||||
{ provide: ThemeService, useValue: getMockThemeService() },
|
{ provide: ThemeService, useValue: getMockThemeService() },
|
||||||
provideMockStore({ initialState }),
|
provideMockStore({ initialState }),
|
||||||
AppComponent,
|
AppComponent,
|
||||||
@@ -179,26 +174,6 @@ describe('InitService', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('initÀnalytics', () => {
|
|
||||||
describe('when GoogleAnalyticsService is provided', () => {
|
|
||||||
let googleAnalyticsSpy;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
googleAnalyticsSpy = jasmine.createSpyObj('googleAnalyticsService', [
|
|
||||||
'addTrackingIdToPage',
|
|
||||||
]);
|
|
||||||
|
|
||||||
TestBed.overrideProvider(GoogleAnalyticsService, { useValue: googleAnalyticsSpy });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call googleAnalyticsService.addTrackingIdToPage()', inject([InitService], (service) => {
|
|
||||||
// @ts-ignore
|
|
||||||
service.initAnalytics();
|
|
||||||
expect(googleAnalyticsSpy.addTrackingIdToPage).toHaveBeenCalledTimes(1);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('initRouteListeners', () => {
|
describe('initRouteListeners', () => {
|
||||||
it('should call listenForRouteChanges', inject([InitService], (service) => {
|
it('should call listenForRouteChanges', inject([InitService], (service) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -207,68 +182,6 @@ describe('InitService', () => {
|
|||||||
expect(breadcrumbsServiceSpy.listenForRouteChanges).toHaveBeenCalledTimes(1);
|
expect(breadcrumbsServiceSpy.listenForRouteChanges).toHaveBeenCalledTimes(1);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('initKlaro', () => {
|
|
||||||
const BLOCKING = {
|
|
||||||
t: { core: { auth: { blocking: true } } },
|
|
||||||
f: { core: { auth: { blocking: false } } },
|
|
||||||
};
|
|
||||||
|
|
||||||
it('should not error out if KlaroService is not provided', inject([InitService], (service) => {
|
|
||||||
// @ts-ignore
|
|
||||||
service.initKlaro();
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('when KlaroService is provided', () => {
|
|
||||||
let klaroServiceSpy;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
klaroServiceSpy = jasmine.createSpyObj('klaroServiceSpy', [
|
|
||||||
'initialize',
|
|
||||||
]);
|
|
||||||
|
|
||||||
TestBed.overrideProvider(KlaroService, { useValue: klaroServiceSpy });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not initialize Klaro while auth is blocking', () => {
|
|
||||||
getTestScheduler().run(({ cold, flush}) => {
|
|
||||||
TestBed.overrideProvider(Store, { useValue: cold('t--t--t--', BLOCKING) });
|
|
||||||
const service = TestBed.inject(InitService);
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
service.initKlaro();
|
|
||||||
flush();
|
|
||||||
expect(klaroServiceSpy.initialize).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should only initialize Klaro the first time auth is unblocked', () => {
|
|
||||||
getTestScheduler().run(({ cold, flush}) => {
|
|
||||||
TestBed.overrideProvider(Store, { useValue: cold('t--t--f--t--f--', BLOCKING) });
|
|
||||||
const service = TestBed.inject(InitService);
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
service.initKlaro();
|
|
||||||
flush();
|
|
||||||
expect(klaroServiceSpy.initialize).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when KlaroService is not provided', () => {
|
|
||||||
it('should not error out when auth is unblocked', () => {
|
|
||||||
getTestScheduler().run(({ cold, flush}) => {
|
|
||||||
TestBed.overrideProvider(Store, { useValue: cold('t--t--f--t--f--', BLOCKING) });
|
|
||||||
const service = TestBed.inject(InitService);
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
service.initKlaro();
|
|
||||||
flush();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
155
src/modules/app/browser-init.service.spec.ts
Normal file
155
src/modules/app/browser-init.service.spec.ts
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
import { InitService } from '../../app/init.service';
|
||||||
|
import { APP_CONFIG } from 'src/config/app-config.interface';
|
||||||
|
import { inject, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { GoogleAnalyticsService } from '../../app/statistics/google-analytics.service';
|
||||||
|
import { MetadataService } from '../../app/core/metadata/metadata.service';
|
||||||
|
import { BreadcrumbsService } from '../../app/breadcrumbs/breadcrumbs.service';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { Store, StoreModule } from '@ngrx/store';
|
||||||
|
import { authReducer } from '../../app/core/auth/auth.reducer';
|
||||||
|
import { storeModuleConfig } from '../../app/app.reducer';
|
||||||
|
import { AngularticsProviderMock } from '../../app/shared/mocks/angulartics-provider.service.mock';
|
||||||
|
import { Angulartics2DSpace } from '../../app/statistics/angulartics/dspace-provider';
|
||||||
|
import { AuthService } from '../../app/core/auth/auth.service';
|
||||||
|
import { AuthServiceMock } from '../../app/shared/mocks/auth.service.mock';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { RouterMock } from '../../app/shared/mocks/router.mock';
|
||||||
|
import { MockActivatedRoute } from '../../app/shared/mocks/active-router.mock';
|
||||||
|
import { MenuService } from '../../app/shared/menu/menu.service';
|
||||||
|
import { LocaleService } from '../../app/core/locale/locale.service';
|
||||||
|
import { environment } from '../../environments/environment';
|
||||||
|
import { provideMockStore } from '@ngrx/store/testing';
|
||||||
|
import { AppComponent } from '../../app/app.component';
|
||||||
|
import { RouteService } from '../../app/core/services/route.service';
|
||||||
|
import { getMockLocaleService } from '../../app/app.component.spec';
|
||||||
|
import { MenuServiceStub } from '../../app/shared/testing/menu-service.stub';
|
||||||
|
import { CorrelationIdService } from '../../app/correlation-id/correlation-id.service';
|
||||||
|
import { KlaroService } from '../../app/shared/cookies/klaro.service';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { TranslateLoaderMock } from '../../app/shared/mocks/translate-loader.mock';
|
||||||
|
import { getTestScheduler } from 'jasmine-marbles';
|
||||||
|
import { ThemeService } from '../../app/shared/theme-support/theme.service';
|
||||||
|
import { getMockThemeService } from '../../app/shared/mocks/theme-service.mock';
|
||||||
|
import { BrowserInitService } from './browser-init.service';
|
||||||
|
import { TransferState } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
core: {
|
||||||
|
auth: {
|
||||||
|
loading: false,
|
||||||
|
blocking: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('BrowserInitService', () => {
|
||||||
|
describe('browser-specific initialization steps', () => {
|
||||||
|
let correlationIdServiceSpy;
|
||||||
|
let dspaceTransferStateSpy;
|
||||||
|
let transferStateSpy;
|
||||||
|
let metadataServiceSpy;
|
||||||
|
let breadcrumbsServiceSpy;
|
||||||
|
let klaroServiceSpy;
|
||||||
|
let googleAnalyticsSpy;
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
correlationIdServiceSpy = jasmine.createSpyObj('correlationIdServiceSpy', [
|
||||||
|
'initCorrelationId',
|
||||||
|
]);
|
||||||
|
dspaceTransferStateSpy = jasmine.createSpyObj('dspaceTransferStateSpy', [
|
||||||
|
'transfer',
|
||||||
|
]);
|
||||||
|
transferStateSpy = jasmine.createSpyObj('dspaceTransferStateSpy', [
|
||||||
|
'get', 'hasKey'
|
||||||
|
]);
|
||||||
|
breadcrumbsServiceSpy = jasmine.createSpyObj('breadcrumbsServiceSpy', [
|
||||||
|
'listenForRouteChanges',
|
||||||
|
]);
|
||||||
|
metadataServiceSpy = jasmine.createSpyObj('metadataService', [
|
||||||
|
'listenForRouteChange',
|
||||||
|
]);
|
||||||
|
klaroServiceSpy = jasmine.createSpyObj('klaroServiceSpy', [
|
||||||
|
'initialize',
|
||||||
|
]);
|
||||||
|
googleAnalyticsSpy = jasmine.createSpyObj('googleAnalyticsService', [
|
||||||
|
'addTrackingIdToPage',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
StoreModule.forRoot(authReducer, storeModuleConfig),
|
||||||
|
TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: TranslateLoaderMock
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: InitService, useClass: BrowserInitService },
|
||||||
|
{ provide: CorrelationIdService, useValue: correlationIdServiceSpy },
|
||||||
|
{ provide: APP_CONFIG, useValue: environment },
|
||||||
|
{ provide: LocaleService, useValue: getMockLocaleService() },
|
||||||
|
{ provide: Angulartics2DSpace, useValue: new AngularticsProviderMock() },
|
||||||
|
{ provide: MetadataService, useValue: metadataServiceSpy },
|
||||||
|
{ provide: BreadcrumbsService, useValue: breadcrumbsServiceSpy },
|
||||||
|
{ provide: AuthService, useValue: new AuthServiceMock() },
|
||||||
|
{ provide: Router, useValue: new RouterMock() },
|
||||||
|
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
|
||||||
|
{ provide: MenuService, useValue: new MenuServiceStub() },
|
||||||
|
{ provide: KlaroService, useValue: klaroServiceSpy },
|
||||||
|
{ provide: GoogleAnalyticsService, useValue: googleAnalyticsSpy },
|
||||||
|
{ provide: ThemeService, useValue: getMockThemeService() },
|
||||||
|
provideMockStore({ initialState }),
|
||||||
|
AppComponent,
|
||||||
|
RouteService,
|
||||||
|
{ provide: TransferState, useValue: undefined },
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('initGoogleÀnalytics', () => {
|
||||||
|
it('should call googleAnalyticsService.addTrackingIdToPage()', inject([InitService], (service) => {
|
||||||
|
// @ts-ignore
|
||||||
|
service.initGoogleAnalytics();
|
||||||
|
expect(googleAnalyticsSpy.addTrackingIdToPage).toHaveBeenCalledTimes(1);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('initKlaro', () => {
|
||||||
|
const BLOCKING = {
|
||||||
|
t: { core: { auth: { blocking: true } } },
|
||||||
|
f: { core: { auth: { blocking: false } } },
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should not initialize Klaro while auth is blocking', () => {
|
||||||
|
getTestScheduler().run(({ cold, flush}) => {
|
||||||
|
TestBed.overrideProvider(Store, { useValue: cold('t--t--t--', BLOCKING) });
|
||||||
|
const service = TestBed.inject(InitService);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
service.initKlaro();
|
||||||
|
flush();
|
||||||
|
expect(klaroServiceSpy.initialize).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should only initialize Klaro the first time auth is unblocked', () => {
|
||||||
|
getTestScheduler().run(({ cold, flush}) => {
|
||||||
|
TestBed.overrideProvider(Store, { useValue: cold('t--t--f--t--f--', BLOCKING) });
|
||||||
|
const service = TestBed.inject(InitService);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
service.initKlaro();
|
||||||
|
flush();
|
||||||
|
expect(klaroServiceSpy.initialize).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@@ -47,7 +47,6 @@ export class BrowserInitService extends InitService {
|
|||||||
protected googleAnalyticsService: GoogleAnalyticsService,
|
protected googleAnalyticsService: GoogleAnalyticsService,
|
||||||
protected metadata: MetadataService,
|
protected metadata: MetadataService,
|
||||||
protected breadcrumbsService: BreadcrumbsService,
|
protected breadcrumbsService: BreadcrumbsService,
|
||||||
protected cssService: CSSVariableService,
|
|
||||||
protected klaroService: KlaroService,
|
protected klaroService: KlaroService,
|
||||||
protected authService: AuthService,
|
protected authService: AuthService,
|
||||||
protected themeService: ThemeService,
|
protected themeService: ThemeService,
|
||||||
|
Reference in New Issue
Block a user