Fix login providers

This commit is contained in:
mauriziovitale84
2016-09-05 16:15:16 +01:00
parent 35c2433536
commit 3cd0670762
6 changed files with 62 additions and 9 deletions

View File

@@ -49,6 +49,8 @@ export class LoginDemoComponent {
this.providers = 'ALL';
} else if (checked) {
this.providers = 'ECM';
} else if (!checked && this.providers === 'ALL') {
this.providers = 'BPM';
} else {
this.providers = undefined;
}
@@ -59,6 +61,8 @@ export class LoginDemoComponent {
this.providers = 'ALL';
} else if (checked) {
this.providers = 'BPM';
} else if (!checked && this.providers === 'ALL') {
this.providers = 'ECM';
} else {
this.providers = undefined;
}

View File

@@ -8,7 +8,7 @@
<div class="mdl-card__supporting-text">
<div>
<div *ngIf="error" id="login-error" data-automation-id="login-error"
class="error mdl-card__supporting-text">{{'LOGIN.MESSAGES.LOGIN-ERROR' | translate }}</div>
class="error mdl-card__supporting-text">{{errorMsg | translate }}</div>
<div *ngIf="success" id="login-success" data-automation-id="login-success" class="mdl-card__supporting-text" style="color: blue;">{{'LOGIN.MESSAGES.LOGIN-SUCCESS' | translate }}</div>
</div>
<div [ngClass]="{'is-invalid': isErrorStyle(form.controls.username)}"

View File

@@ -212,6 +212,7 @@ describe('AlfrescoLogin', () => {
});
it('should return success true after the login have succeeded', () => {
component.providers = 'ECM';
expect(component.error).toBe(false);
expect(component.success).toBe(false);
@@ -238,6 +239,7 @@ describe('AlfrescoLogin', () => {
});
it('should return error with a wrong username', () => {
component.providers = 'ECM';
expect(component.error).toBe(false);
expect(component.success).toBe(false);
@@ -262,10 +264,11 @@ describe('AlfrescoLogin', () => {
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(compiled.querySelector('#login-error')).toBeDefined();
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR');
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
it('should return error with a wrong password', () => {
component.providers = 'ECM';
expect(component.success).toBe(false);
expect(component.error).toBe(false);
@@ -290,10 +293,11 @@ describe('AlfrescoLogin', () => {
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(compiled.querySelector('#login-error')).toBeDefined();
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR');
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
it('should return error with a wrong username and password', () => {
component.providers = 'ECM';
expect(component.success).toBe(false);
expect(component.error).toBe(false);
@@ -318,12 +322,12 @@ describe('AlfrescoLogin', () => {
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(compiled.querySelector('#login-error')).toBeDefined();
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR');
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
it('should emit onSuccess event after the login has succeeded', () => {
spyOn(component.onSuccess, 'emit');
component.providers = 'ECM';
expect(component.error).toBe(false);
expect(component.success).toBe(false);
@@ -355,6 +359,7 @@ describe('AlfrescoLogin', () => {
it('should emit onError event after the login has failed', () => {
spyOn(component.onError, 'emit');
component.providers = 'ECM';
expect(component.success).toBe(false);
expect(component.error).toBe(false);
@@ -379,7 +384,7 @@ describe('AlfrescoLogin', () => {
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(compiled.querySelector('#login-error')).toBeDefined();
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR');
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
expect(component.onError.emit).toHaveBeenCalledWith('Fake server error');
});
@@ -410,5 +415,36 @@ describe('AlfrescoLogin', () => {
expect(component.isPasswordShow).toBe(false);
expect(compiled.querySelector('#password').type).toEqual('password');
});
it('should emit onError event when the providers is undefined', () => {
spyOn(component.onError, 'emit');
expect(component.success).toBe(false);
expect(component.error).toBe(false);
let compiled = componentFixture.debugElement.nativeElement;
let usernameInput = compiled.querySelector('#username');
let passwordInput = compiled.querySelector('#password');
componentFixture.detectChanges();
usernameInput.value = 'fake-username';
passwordInput.value = 'fake-password';
usernameInput.dispatchEvent(new Event('input'));
passwordInput.dispatchEvent(new Event('input'));
componentFixture.detectChanges();
compiled.querySelector('button').click();
componentFixture.detectChanges();
expect(component.error).toBe(true);
expect(component.success).toBe(false);
expect(compiled.querySelector('#login-error')).toBeDefined();
expect(compiled.querySelector('#login-error').innerText).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS');
expect(component.onError.emit).toHaveBeenCalledWith('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS');
});
});

View File

@@ -59,6 +59,7 @@ export class AlfrescoLoginComponent {
form: ControlGroup;
error: boolean = false;
errorMsg: string;
success: boolean = false;
formError: { [id: string]: string };
@@ -108,10 +109,19 @@ export class AlfrescoLoginComponent {
* @param event
*/
onSubmit(value: any, event: any) {
this.error = false;
if (event) {
event.preventDefault();
}
if (this.providers === undefined) {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS';
this.error = true;
let messageProviders: any;
messageProviders = this.translate.get(this.errorMsg);
this.onError.emit(messageProviders.value);
this.success = false;
return false;
}
this.error = false;
this.settingsService.setProviders(this.providers);
@@ -123,6 +133,7 @@ export class AlfrescoLoginComponent {
},
(err: any) => {
this.error = true;
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS';
this.onError.emit(err);
console.log(err);
this.success = false;

View File

@@ -11,7 +11,8 @@
"USERNAME-REQUIRED": "Required",
"USERNAME-MIN": "Your username needs to be at least 4 characters.",
"PASSWORD-REQUIRED": "Enter your password to sign in",
"LOGIN-ERROR": "You have entered an invalid username or password",
"LOGIN-ERROR-CREDENTIALS": "You have entered an invalid username or password",
"LOGIN-ERROR-PROVIDERS": "Providers cannot be undefined",
"LOGIN-SUCCESS": "Login successful"
},
"BUTTON": {

View File

@@ -10,7 +10,8 @@
"USERNAME-REQUIRED": "Campo obbligatorio",
"USERNAME-MIN": "Inserire un nome utente di minimo 4 caratteri.",
"PASSWORD-REQUIRED": "Campo obbligatorio",
"LOGIN-ERROR": "Nome utente o password non validi",
"LOGIN-ERROR-CREDENTIALS": "Nome utente o password non validi",
"LOGIN-ERROR-PROVIDERS": "Providers non può essere nullo",
"LOGIN-SUCCESS": "Login effettuata con successo"
},
"BUTTON": {