aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/user-login
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-06 23:14:45 +0800
committercrupest <crupest@outlook.com>2019-03-06 23:14:45 +0800
commit2ee5c455152a0553453e400b387109b0b518ec99 (patch)
tree71ae02cba29f42589ece492ec0840609e71debde /Timeline/ClientApp/src/app/user/user-login
parent63735a8267d44892a64da5b599b7c2e20f373464 (diff)
downloadtimeline-2ee5c455152a0553453e400b387109b0b518ec99.tar.gz
timeline-2ee5c455152a0553453e400b387109b0b518ec99.tar.bz2
timeline-2ee5c455152a0553453e400b387109b0b518ec99.zip
Write all unit tests.
Diffstat (limited to 'Timeline/ClientApp/src/app/user/user-login')
-rw-r--r--Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts43
1 files changed, 39 insertions, 4 deletions
diff --git a/Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts b/Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts
index b606b7b4..acd13721 100644
--- a/Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts
+++ b/Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts
@@ -1,6 +1,9 @@
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { NO_ERRORS_SCHEMA } from '@angular/core';
+import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
+import { ReactiveFormsModule } from '@angular/forms';
+import { By } from '@angular/platform-browser';
-import { UserLoginComponent } from './user-login.component';
+import { UserLoginComponent, LoginEvent } from './user-login.component';
describe('UserLoginComponent', () => {
let component: UserLoginComponent;
@@ -8,9 +11,11 @@ describe('UserLoginComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [ UserLoginComponent ]
+ declarations: [UserLoginComponent],
+ imports: [ReactiveFormsModule],
+ schemas: [NO_ERRORS_SCHEMA]
})
- .compileComponents();
+ .compileComponents();
}));
beforeEach(() => {
@@ -22,4 +27,34 @@ describe('UserLoginComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('reactive form should work well', () => {
+ const usernameInput = fixture.debugElement.query(By.css('input[type=text]')).nativeElement as HTMLInputElement;
+ const passwordInput = fixture.debugElement.query(By.css('input[type=password]')).nativeElement as HTMLInputElement;
+
+ usernameInput.value = 'user';
+ usernameInput.dispatchEvent(new Event('input'));
+ passwordInput.value = 'user';
+ passwordInput.dispatchEvent(new Event('input'));
+
+ fixture.detectChanges();
+
+ expect(component.form.value).toEqual({
+ username: 'user',
+ password: 'user'
+ });
+ });
+
+ it('login event should work well', fakeAsync(() => {
+ let userCredential: LoginEvent;
+ component.login.subscribe((e: LoginEvent) => { userCredential = e; });
+ fixture.detectChanges();
+ const mockValue = {
+ username: 'user',
+ password: 'user'
+ };
+ component.form.setValue(mockValue);
+ component.onLoginButtonClick();
+ expect(userCredential).toEqual(mockValue);
+ }));
});