mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
fix login unit test to nit emit error in the network (#4885)
* fix login unit test to nit emit error in the network * fix lint
This commit is contained in:
parent
2a2dfbcc42
commit
4dccc2a49a
@ -31,6 +31,7 @@ import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
|||||||
|
|
||||||
import { setupTestBed } from '../../testing/setupTestBed';
|
import { setupTestBed } from '../../testing/setupTestBed';
|
||||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||||
|
import { Observable } from 'rxjs/index';
|
||||||
|
|
||||||
describe('LoginComponent', () => {
|
describe('LoginComponent', () => {
|
||||||
let component: LoginComponent;
|
let component: LoginComponent;
|
||||||
@ -89,7 +90,7 @@ describe('LoginComponent', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
function loginWithCredentials(username, password, providers: string = 'ECM') {
|
function loginWithCredentials(username, password) {
|
||||||
usernameInput.value = username;
|
usernameInput.value = username;
|
||||||
passwordInput.value = password;
|
passwordInput.value = password;
|
||||||
|
|
||||||
@ -130,6 +131,12 @@ describe('LoginComponent', () => {
|
|||||||
|
|
||||||
it('should update user preferences upon login', async(() => {
|
it('should update user preferences upon login', async(() => {
|
||||||
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
|
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
|
||||||
|
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.complete();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
component.success.subscribe(() => {
|
component.success.subscribe(() => {
|
||||||
expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username');
|
expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username');
|
||||||
@ -276,6 +283,8 @@ describe('LoginComponent', () => {
|
|||||||
expect(element.querySelector('#username-error')).toBeNull();
|
expect(element.querySelector('#username-error')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Error', () => {
|
||||||
|
|
||||||
it('should render validation min-length error when the username is just 1 character with a custom validation Validators.minLength(3)', () => {
|
it('should render validation min-length error when the username is just 1 character with a custom validation Validators.minLength(3)', () => {
|
||||||
component.fieldsValidation = {
|
component.fieldsValidation = {
|
||||||
username: ['', Validators.compose([Validators.required, Validators.minLength(3)])],
|
username: ['', Validators.compose([Validators.required, Validators.minLength(3)])],
|
||||||
@ -346,16 +355,6 @@ describe('LoginComponent', () => {
|
|||||||
expect(element.querySelector('#password-required').innerText).toEqual('LOGIN.MESSAGES.PASSWORD-REQUIRED');
|
expect(element.querySelector('#password-required').innerText).toEqual('LOGIN.MESSAGES.PASSWORD-REQUIRED');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should trim the username value', () => {
|
|
||||||
usernameInput.value = 'username ';
|
|
||||||
component.form.controls.password.markAsDirty();
|
|
||||||
usernameInput.dispatchEvent(new Event('blur'));
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(usernameInput.value).toEqual('username');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render no validation errors when the username and password are filled', () => {
|
it('should render no validation errors when the username and password are filled', () => {
|
||||||
usernameInput.value = 'fake-username';
|
usernameInput.value = 'fake-username';
|
||||||
passwordInput.value = 'fake-password';
|
passwordInput.value = 'fake-password';
|
||||||
@ -375,40 +374,13 @@ describe('LoginComponent', () => {
|
|||||||
expect(element.querySelector('#password-required')).toBeNull();
|
expect(element.querySelector('#password-required')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the new values after user and password values are changed', () => {
|
|
||||||
usernameInput.value = 'fake-change-username';
|
|
||||||
passwordInput.value = 'fake-change-password';
|
|
||||||
|
|
||||||
component.form.controls.username.markAsDirty();
|
|
||||||
component.form.controls.password.markAsDirty();
|
|
||||||
|
|
||||||
usernameInput.dispatchEvent(new Event('input'));
|
|
||||||
passwordInput.dispatchEvent(new Event('input'));
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(element.querySelector('input[type="text"]').value).toEqual('fake-change-username');
|
|
||||||
expect(element.querySelector('input[type="password"]').value).toEqual('fake-change-password');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return success event after the login have succeeded', (done) => {
|
|
||||||
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
|
||||||
|
|
||||||
expect(component.isError).toBe(false);
|
|
||||||
|
|
||||||
component.success.subscribe(() => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(component.isError).toBe(false);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
loginWithCredentials('fake-username', 'fake-password');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return error with a wrong username', (done) => {
|
it('should return error with a wrong username', (done) => {
|
||||||
|
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.error();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@ -423,6 +395,13 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return error with a wrong password', (done) => {
|
it('should return error with a wrong password', (done) => {
|
||||||
|
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.error();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
@ -437,6 +416,13 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return error with a wrong username and password', (done) => {
|
it('should return error with a wrong username and password', (done) => {
|
||||||
|
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.error();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
@ -507,7 +493,54 @@ describe('LoginComponent', () => {
|
|||||||
loginWithCredentials('fake-username-ECM-access-error', 'fake-password');
|
loginWithCredentials('fake-username-ECM-access-error', 'fake-password');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should trim the username value', () => {
|
||||||
|
usernameInput.value = 'username ';
|
||||||
|
component.form.controls.password.markAsDirty();
|
||||||
|
usernameInput.dispatchEvent(new Event('blur'));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(usernameInput.value).toEqual('username');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render the new values after user and password values are changed', () => {
|
||||||
|
usernameInput.value = 'fake-change-username';
|
||||||
|
passwordInput.value = 'fake-change-password';
|
||||||
|
|
||||||
|
component.form.controls.username.markAsDirty();
|
||||||
|
component.form.controls.password.markAsDirty();
|
||||||
|
|
||||||
|
usernameInput.dispatchEvent(new Event('input'));
|
||||||
|
passwordInput.dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('input[type="text"]').value).toEqual('fake-change-username');
|
||||||
|
expect(element.querySelector('input[type="password"]').value).toEqual('fake-change-password');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return success event after the login have succeeded', (done) => {
|
||||||
|
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||||
|
|
||||||
|
expect(component.isError).toBe(false);
|
||||||
|
|
||||||
|
component.success.subscribe(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(component.isError).toBe(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
loginWithCredentials('fake-username', 'fake-password');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
it('should emit success event after the login has succeeded and discard password', async(() => {
|
it('should emit success event after the login has succeeded and discard password', async(() => {
|
||||||
|
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||||
|
|
||||||
component.success.subscribe((event) => {
|
component.success.subscribe((event) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
@ -558,6 +591,13 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should emit only the username and not the password as part of the executeSubmit', async(() => {
|
it('should emit only the username and not the password as part of the executeSubmit', async(() => {
|
||||||
|
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
|
||||||
|
return new Observable((observer) => {
|
||||||
|
observer.next();
|
||||||
|
observer.complete();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
component.executeSubmit.subscribe((res) => {
|
component.executeSubmit.subscribe((res) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user