mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
fix issue with switching accounts (#2564)
This commit is contained in:
committed by
Eugenio Romano
parent
d923070d4f
commit
42aa4c04ce
@@ -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');
|
||||
|
@@ -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]);
|
||||
|
Reference in New Issue
Block a user