diff --git a/ng2-components/ng2-alfresco-login/src/components/login.component.spec.ts b/ng2-components/ng2-alfresco-login/src/components/login.component.spec.ts index e217937bcc..6507c6ced3 100644 --- a/ng2-components/ng2-alfresco-login/src/components/login.component.spec.ts +++ b/ng2-components/ng2-alfresco-login/src/components/login.component.spec.ts @@ -22,7 +22,7 @@ import { Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { AlfrescoAuthenticationService, CoreModule } from 'ng2-alfresco-core'; -import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService, UserPreferencesService } from 'ng2-alfresco-core'; import { MaterialModule } from '../material.module'; import { LoginErrorEvent } from '../models/login-error.event'; @@ -38,6 +38,7 @@ describe('LoginComponent', () => { let element: any; let authService: AlfrescoAuthenticationService; let router: Router; + let userPreferences: UserPreferencesService; let usernameInput, passwordInput; @@ -87,6 +88,7 @@ describe('LoginComponent', () => { authService = TestBed.get(AlfrescoAuthenticationService); router = TestBed.get(Router); + userPreferences = TestBed.get(UserPreferencesService); fixture.detectChanges(); }); @@ -112,6 +114,17 @@ describe('LoginComponent', () => { expect(router.navigate).toHaveBeenCalledWith([redirect]); }); + it('should update user preferences upon login', (done) => { + spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); + + component.success.subscribe(() => { + expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username'); + done(); + }); + + loginWithCredentials('fake-username', 'fake-password'); + }); + describe('Login button', () => { const getLoginButton = () => element.querySelector('#login-button'); diff --git a/ng2-components/ng2-alfresco-login/src/components/login.component.ts b/ng2-components/ng2-alfresco-login/src/components/login.component.ts index fd3597fa65..8770106034 100644 --- a/ng2-components/ng2-alfresco-login/src/components/login.component.ts +++ b/ng2-components/ng2-alfresco-login/src/components/login.component.ts @@ -18,7 +18,7 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, TemplateRef, ViewEncapsulation } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; -import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoTranslationService, LogService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoTranslationService, LogService, UserPreferencesService } from 'ng2-alfresco-core'; import { LoginErrorEvent } from '../models/login-error.event'; import { LoginSubmitEvent } from '../models/login-submit.event'; @@ -112,7 +112,8 @@ export class LoginComponent implements OnInit { private translateService: AlfrescoTranslationService, private logService: LogService, private elementRef: ElementRef, - private router: Router) { + private router: Router, + private userPreferences: UserPreferencesService) { this.initFormError(); this.initFormFieldsMessages(); } @@ -183,6 +184,7 @@ export class LoginComponent implements OnInit { .subscribe( (token: any) => { this.actualLoginStep = LoginSteps.Welcome; + this.userPreferences.setStoragePrefix(values.username); this.success.emit(new LoginSuccessEvent(token, values.username, values.password)); if (this.successRoute) { this.router.navigate([this.successRoute]);