diff options
| author | 杨宇千 <crupest@outlook.com> | 2019-03-14 16:51:46 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-14 16:51:46 +0800 |
| commit | 19a12661e981718aebc418624c602b852e68d54d (patch) | |
| tree | bc467184f38d9ea2962f860af889e002320e22e8 /Timeline/ClientApp/src/app/user/user-login/user-login.component.spec.ts | |
| parent | 988e07fce184b72c35020e4bde4079bdd305fb7c (diff) | |
| parent | 780afcc14029d966f74fc8688aa040183ac23476 (diff) | |
| download | timeline-19a12661e981718aebc418624c602b852e68d54d.tar.gz timeline-19a12661e981718aebc418624c602b852e68d54d.tar.bz2 timeline-19a12661e981718aebc418624c602b852e68d54d.zip | |
Merge pull request #13 from crupest/auth-guard
Add auth guard.
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.ts | 19 |
1 files changed, 9 insertions, 10 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 9c9ee1dc..693d5b6e 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 @@ -7,7 +7,6 @@ import { ActivatedRoute } from '@angular/router'; import { of, throwError } from 'rxjs'; import { createMockInternalUserService } from '../internal-user-service/internal-user.service.mock'; -import { MockActivatedRoute } from '../../test-utilities/activated-route.mock'; import { UserLoginComponent } from './user-login.component'; import { InternalUserService } from '../internal-user-service/internal-user.service'; import { UserInfo } from '../entities'; @@ -16,17 +15,17 @@ describe('UserLoginComponent', () => { let component: UserLoginComponent; let fixture: ComponentFixture<UserLoginComponent>; let mockInternalUserService: jasmine.SpyObj<InternalUserService>; - let mockActivatedRoute: MockActivatedRoute; beforeEach(async(() => { mockInternalUserService = createMockInternalUserService(); - mockActivatedRoute = new MockActivatedRoute(); + + // mock property + (<any>mockInternalUserService).currentUserInfo = null; TestBed.configureTestingModule({ declarations: [UserLoginComponent], providers: [ - { provide: InternalUserService, useValue: mockInternalUserService }, - { provide: ActivatedRoute, useValue: mockActivatedRoute } + { provide: InternalUserService, useValue: mockInternalUserService } ], imports: [ReactiveFormsModule], schemas: [NO_ERRORS_SCHEMA] @@ -77,22 +76,22 @@ describe('UserLoginComponent', () => { component.onLoginButtonClick(); expect(mockInternalUserService.tryLogin).toHaveBeenCalledWith(mockValue); - expect(mockInternalUserService.userRouteNavigate).toHaveBeenCalledWith(['success', { reason: 'login' }]); + expect(mockInternalUserService.userRouteNavigate).toHaveBeenCalledWith(['success', { fromlogin: 'true' }]); }); describe('message display', () => { it('nologin reason should display', () => { - mockActivatedRoute.pushSnapshotWithParamMap({ reason: 'nologin' }); fixture.detectChanges(); - expect(component.message).toBe('nologin'); + component.message = 'nologin'; + fixture.detectChanges(); expect((fixture.debugElement.query(By.css('p.mat-body')).nativeElement as HTMLParagraphElement).textContent).toBe('You haven\'t login.'); }); it('invalid login reason should display', () => { - mockActivatedRoute.pushSnapshotWithParamMap({ reason: 'invalidlogin' }); fixture.detectChanges(); - expect(component.message).toBe('invalidlogin'); + component.message = 'invalidlogin'; + fixture.detectChanges(); expect((fixture.debugElement.query(By.css('p.mat-body')).nativeElement as HTMLParagraphElement).textContent).toBe('Your login is no longer valid.'); }); |
