diff --git a/demo-shell-ng2/app/components/login/login-demo.component.ts b/demo-shell-ng2/app/components/login/login-demo.component.ts
index e7533e7794..6df82e500a 100644
--- a/demo-shell-ng2/app/components/login/login-demo.component.ts
+++ b/demo-shell-ng2/app/components/login/login-demo.component.ts
@@ -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;
}
diff --git a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.html b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.html
index f40a58ee8c..585eaab1ec 100644
--- a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.html
+++ b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.html
@@ -8,7 +8,7 @@
{{'LOGIN.MESSAGES.LOGIN-ERROR' | translate }}
+ class="error mdl-card__supporting-text">{{errorMsg | translate }}
{{'LOGIN.MESSAGES.LOGIN-SUCCESS' | translate }}
{
});
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');
+ });
});
diff --git a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts
index a0a67a46b2..a11c02516a 100644
--- a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts
+++ b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts
@@ -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;
diff --git a/ng2-components/ng2-alfresco-login/src/i18n/en.json b/ng2-components/ng2-alfresco-login/src/i18n/en.json
index 45c27d03ed..7c1ef10cd9 100644
--- a/ng2-components/ng2-alfresco-login/src/i18n/en.json
+++ b/ng2-components/ng2-alfresco-login/src/i18n/en.json
@@ -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": {
diff --git a/ng2-components/ng2-alfresco-login/src/i18n/it.json b/ng2-components/ng2-alfresco-login/src/i18n/it.json
index ff6604dcee..c274b00912 100644
--- a/ng2-components/ng2-alfresco-login/src/i18n/it.json
+++ b/ng2-components/ng2-alfresco-login/src/i18n/it.json
@@ -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": {