aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-03-06 23:29:12 +0800
committerGitHub <noreply@github.com>2019-03-06 23:29:12 +0800
commitd4410036b62a65cedbe977efdcea023440a3198e (patch)
treefdc6e957aed9cd0f1433f2c42e1e4ed89d13b4ee /Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts
parent8033d6523885486c24af2bdd57a24b0fd62d0b00 (diff)
parent7107d431fe7019ccc20e90e5aecb5feb64fc53b3 (diff)
downloadtimeline-d4410036b62a65cedbe977efdcea023440a3198e.tar.gz
timeline-d4410036b62a65cedbe977efdcea023440a3198e.tar.bz2
timeline-d4410036b62a65cedbe977efdcea023440a3198e.zip
Merge pull request #3 from crupest/user
Develop user dialog.
Diffstat (limited to 'Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts')
-rw-r--r--Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts60
1 files changed, 60 insertions, 0 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
new file mode 100644
index 00000000..acd13721
--- /dev/null
+++ b/Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts
@@ -0,0 +1,60 @@
+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, LoginEvent } from './user-login.component';
+
+describe('UserLoginComponent', () => {
+ let component: UserLoginComponent;
+ let fixture: ComponentFixture<UserLoginComponent>;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [UserLoginComponent],
+ imports: [ReactiveFormsModule],
+ schemas: [NO_ERRORS_SCHEMA]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(UserLoginComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ 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);
+ }));
+});