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 | c65db42c9ce3532509bbd0b4abfc500692cfe4d3 (patch) | |
| tree | 9e6a91af019e14fa3fb40e03bf84507a98a33d4c /Timeline/ClientApp/src/app/user/user-dialog | |
| parent | 4535d1fd30eb02b3fe60718235a0725e3b30049e (diff) | |
| parent | 7b929db4fcfa34acc82885b75a573e6e4bd40465 (diff) | |
| download | timeline-c65db42c9ce3532509bbd0b4abfc500692cfe4d3.tar.gz timeline-c65db42c9ce3532509bbd0b4abfc500692cfe4d3.tar.bz2 timeline-c65db42c9ce3532509bbd0b4abfc500692cfe4d3.zip  | |
Merge pull request #13 from crupest/auth-guard
Add auth guard.
Diffstat (limited to 'Timeline/ClientApp/src/app/user/user-dialog')
4 files changed, 11 insertions, 81 deletions
diff --git a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.css b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.css index a443e3c0..e69de29b 100644 --- a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.css +++ b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.css @@ -1,5 +0,0 @@ -.container { -  display: flex; -  justify-content: center; -  align-content: center; -} diff --git a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.html b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.html index 58dff0e4..e8dbb003 100644 --- a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.html +++ b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.html @@ -1,4 +1 @@ -<div class="container"> -  <mat-progress-spinner *ngIf="isLoading" mode="indeterminate" diameter="50"></mat-progress-spinner> -  <router-outlet name="user"></router-outlet> -</div> +<router-outlet name="user"></router-outlet> diff --git a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.spec.ts b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.spec.ts index c56e1ed1..47860eee 100644 --- a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.spec.ts +++ b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.spec.ts @@ -1,20 +1,10 @@  import { Component } from '@angular/core'; -import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing';  import { Router, Event } from '@angular/router'; -import { of, Observable } from 'rxjs'; -import { delay } from 'rxjs/operators'; -import { UserDialogComponent } from './user-dialog.component'; -import { createMockInternalUserService } from '../internal-user-service/internal-user.service.mock'; -import { InternalUserService, UserLoginState } from '../internal-user-service/internal-user.service'; +import { Observable } from 'rxjs'; -@Component({ -  /* tslint:disable-next-line:component-selector*/ -  selector: 'mat-progress-spinner', -  template: '' -}) -class MatProgressSpinnerStubComponent { } +import { UserDialogComponent } from './user-dialog.component';  @Component({    /* tslint:disable-next-line:component-selector*/ @@ -27,16 +17,12 @@ class RouterOutletStubComponent { }  describe('UserDialogComponent', () => {    let component: UserDialogComponent;    let fixture: ComponentFixture<UserDialogComponent>; -  let mockInternalUserService: jasmine.SpyObj<InternalUserService>;    beforeEach(async(() => { -    mockInternalUserService = createMockInternalUserService(); -      TestBed.configureTestingModule({ -      declarations: [UserDialogComponent, MatProgressSpinnerStubComponent, RouterOutletStubComponent], -      providers: [{ provide: InternalUserService, useValue: mockInternalUserService }, -      { // for the workaround +      declarations: [UserDialogComponent, RouterOutletStubComponent], +      providers: [{ // for the workaround          provide: Router, useValue: {            events: new Observable<Event>()          } @@ -48,41 +34,10 @@ describe('UserDialogComponent', () => {    beforeEach(() => {      fixture = TestBed.createComponent(UserDialogComponent);      component = fixture.componentInstance; -  }); - -  it('progress spinner should work well', fakeAsync(() => { -    mockInternalUserService.refreshAndGetUserState.and.returnValue(of(<UserLoginState>'nologin').pipe(delay(10)));      fixture.detectChanges(); -    expect(fixture.debugElement.query(By.css('mat-progress-spinner'))).toBeTruthy(); -    tick(10); -    fixture.detectChanges(); -    expect(fixture.debugElement.query(By.css('mat-progress-spinner'))).toBeFalsy(); -  })); - -  it('nologin should work well', () => { -    mockInternalUserService.refreshAndGetUserState.and.returnValue(of(<UserLoginState>'nologin')); - -    fixture.detectChanges(); - -    expect(mockInternalUserService.refreshAndGetUserState).toHaveBeenCalled(); -    expect(mockInternalUserService.userRouteNavigate).toHaveBeenCalledWith(['login', { reason: 'nologin' }]);    }); -  it('invalid login should work well', () => { -    mockInternalUserService.refreshAndGetUserState.and.returnValue(of(<UserLoginState>'invalidlogin')); - -    fixture.detectChanges(); - -    expect(mockInternalUserService.refreshAndGetUserState).toHaveBeenCalled(); -    expect(mockInternalUserService.userRouteNavigate).toHaveBeenCalledWith(['login',  { reason: 'invalidlogin' }]); -  }); - -  it('success should work well', () => { -    mockInternalUserService.refreshAndGetUserState.and.returnValue(of(<UserLoginState>'success')); - -    fixture.detectChanges(); - -    expect(mockInternalUserService.refreshAndGetUserState).toHaveBeenCalled(); -    expect(mockInternalUserService.userRouteNavigate).toHaveBeenCalledWith(['success', { reason: 'already' }]); +  it('should create', () => { +    expect(component).toBeTruthy();    });  }); diff --git a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts index cf5f3643..2887f0a6 100644 --- a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts +++ b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts @@ -1,5 +1,4 @@ -import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; -import { InternalUserService } from '../internal-user-service/internal-user.service'; +import { Component, OnInit, ViewChild } from '@angular/core';  import { RouterOutlet, Router, ActivationStart } from '@angular/router';  @Component({ @@ -7,14 +6,12 @@ import { RouterOutlet, Router, ActivationStart } from '@angular/router';    templateUrl: './user-dialog.component.html',    styleUrls: ['./user-dialog.component.css']  }) -export class UserDialogComponent implements OnInit, OnDestroy { +export class UserDialogComponent implements OnInit { -  constructor(private userService: InternalUserService, private router: Router) { } +  constructor(private router: Router) { }    @ViewChild(RouterOutlet) outlet!: RouterOutlet; -  isLoading = true; -    ngOnInit() {      // this is a workaround for a bug. see https://github.com/angular/angular/issues/20694      const subscription = this.router.events.subscribe(e => { @@ -23,19 +20,5 @@ export class UserDialogComponent implements OnInit, OnDestroy {          subscription.unsubscribe();        }      }); - - -    this.userService.refreshAndGetUserState().subscribe(result => { -      this.isLoading = false; -      if (result === 'success') { -        this.userService.userRouteNavigate(['success', { reason: 'already' }]); -      } else { -        this.userService.userRouteNavigate(['login', { reason: result }]); -      } -    }); -  } - -  ngOnDestroy() { -    this.userService.userRouteNavigate(null);    }  }  | 
