small fixes

This commit is contained in:
lotte
2020-09-03 10:17:03 +02:00
parent c19f49fb96
commit 8d29090f24
3 changed files with 39 additions and 4 deletions

View File

@@ -95,6 +95,38 @@ describe('BrowserKlaroService', () => {
expect(service).toBeTruthy(); expect(service).toBeTruthy();
}); });
describe('initialize with user', () => {
beforeEach(() => {
spyOn((service as any), 'getUser$').and.returnValue(observableOf(user));
translateService.get.and.returnValue(observableOf('loading...'));
spyOn(service, 'addAppMessages');
spyOn((service as any), 'initializeUser');
spyOn(service, 'translateConfiguration');
});
it('to call the initialize user method and other methods', () => {
service.initialize();
expect((service as any).initializeUser).toHaveBeenCalledWith(user);
expect(service.addAppMessages).toHaveBeenCalled();
expect(service.translateConfiguration).toHaveBeenCalled();
});
});
describe('to not call the initialize user method, but the other methods', () => {
beforeEach(() => {
spyOn((service as any), 'getUser$').and.returnValue(observableOf(undefined));
translateService.get.and.returnValue(observableOf('loading...'));
spyOn(service, 'addAppMessages');
spyOn((service as any), 'initializeUser');
spyOn(service, 'translateConfiguration');
});
it('to call all ', () => {
service.initialize();
expect((service as any).initializeUser).not.toHaveBeenCalledWith(user);
expect(service.addAppMessages).toHaveBeenCalled();
expect(service.translateConfiguration).toHaveBeenCalled();
});
});
it('addAppMessages', () => { it('addAppMessages', () => {
service.addAppMessages(); service.addAppMessages();
expect(mockConfig.translations.en[appName]).toBeDefined(); expect(mockConfig.translations.en[appName]).toBeDefined();
@@ -203,4 +235,3 @@ describe('BrowserKlaroService', () => {
}); });
}); });
}); });

View File

@@ -11,12 +11,12 @@ import { hasValue, isNotEmpty } from '../empty.util';
import { CookieService } from '../../core/services/cookie.service'; import { CookieService } from '../../core/services/cookie.service';
import { EPersonDataService } from '../../core/eperson/eperson-data.service'; import { EPersonDataService } from '../../core/eperson/eperson-data.service';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { klaroConfiguration } from './klaro-configuration'; import { ANONYMOUS_STORAGE_NAME_KLARO, klaroConfiguration } from './klaro-configuration';
import { Operation } from 'fast-json-patch'; import { Operation } from 'fast-json-patch';
export const HAS_AGREED_END_USER = 'dsHasAgreedEndUser'; export const HAS_AGREED_END_USER = 'dsHasAgreedEndUser';
export const COOKIE_MDFIELD = 'dspace.agreements.cookies'; export const COOKIE_MDFIELD = 'dspace.agreements.cookies';
export const ANONYMOUS_STORAGE_NAME_KLARO = 'klaro-anonymous';
const cookieNameMessagePrefix = 'cookies.consent.app.title.'; const cookieNameMessagePrefix = 'cookies.consent.app.title.';
const cookieDescriptionMessagePrefix = 'cookies.consent.app.description.'; const cookieDescriptionMessagePrefix = 'cookies.consent.app.description.';
const cookiePurposeMessagePrefix = 'cookies.consent.purpose.'; const cookiePurposeMessagePrefix = 'cookies.consent.purpose.';
@@ -34,6 +34,7 @@ export class BrowserKlaroService extends KlaroService {
} }
initialize() { initialize() {
console.log(this.klaroConfig)
this.translateService.setDefaultLang(environment.defaultLanguage); this.translateService.setDefaultLang(environment.defaultLanguage);
const user$: Observable<EPerson> = this.getUser$(); const user$: Observable<EPerson> = this.getUser$();
@@ -43,6 +44,7 @@ export class BrowserKlaroService extends KlaroService {
observableCombineLatest(user$, translationServiceReady$) observableCombineLatest(user$, translationServiceReady$)
.subscribe(([user, translation]: [EPerson, string]) => { .subscribe(([user, translation]: [EPerson, string]) => {
user = cloneDeep(user); user = cloneDeep(user);
if (hasValue(user)) { if (hasValue(user)) {
this.initializeUser(user); this.initializeUser(user);
} }

View File

@@ -1,7 +1,9 @@
import { TOKENITEM } from '../../core/auth/models/auth-token-info.model'; import { TOKENITEM } from '../../core/auth/models/auth-token-info.model';
import { IMPERSONATING_COOKIE, REDIRECT_COOKIE } from '../../core/auth/auth.service'; import { IMPERSONATING_COOKIE, REDIRECT_COOKIE } from '../../core/auth/auth.service';
import { LANG_COOKIE } from '../../core/locale/locale.service'; import { LANG_COOKIE } from '../../core/locale/locale.service';
import { ANONYMOUS_STORAGE_NAME_KLARO, HAS_AGREED_END_USER } from './browser-klaro.service'; import { HAS_AGREED_END_USER } from './browser-klaro.service';
export const ANONYMOUS_STORAGE_NAME_KLARO = 'klaro-anonymous';
export const klaroConfiguration: any = { export const klaroConfiguration: any = {
storageName: ANONYMOUS_STORAGE_NAME_KLARO, storageName: ANONYMOUS_STORAGE_NAME_KLARO,