Gets signed-in state from API

This commit is contained in:
Aaron Louie 2020-05-11 16:22:16 -04:00
parent c46385ea29
commit 927356da9d
3 changed files with 25 additions and 11 deletions

View File

@ -1,2 +1,2 @@
<app-sign-in *ngIf="!isSignedIn()"></app-sign-in> <app-sign-in *ngIf="!isSignedIn"></app-sign-in>
<app-workflow-spec-list *ngIf="isSignedIn()"></app-workflow-spec-list> <app-workflow-spec-list *ngIf="isSignedIn"></app-workflow-spec-list>

View File

@ -1,6 +1,8 @@
import {Component, NO_ERRORS_SCHEMA} from '@angular/core'; import {HttpClient} from '@angular/common/http';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {Component} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {MockEnvironment} from 'sartography-workflow-lib'; import {ApiService, MockEnvironment} from 'sartography-workflow-lib';
import {HomeComponent} from './home.component'; import {HomeComponent} from './home.component';
@ -9,13 +11,15 @@ import {HomeComponent} from './home.component';
selector: 'app-sign-in', selector: 'app-sign-in',
template: '' template: ''
}) })
class MockSignInComponent {} class MockSignInComponent {
}
@Component({ @Component({
selector: 'app-workflow-spec-list', selector: 'app-workflow-spec-list',
template: '' template: ''
}) })
class MockWorkflowSpecListComponent {} class MockWorkflowSpecListComponent {
}
describe('HomeComponent', () => { describe('HomeComponent', () => {
let component: HomeComponent; let component: HomeComponent;
@ -28,8 +32,16 @@ describe('HomeComponent', () => {
MockSignInComponent, MockSignInComponent,
MockWorkflowSpecListComponent, MockWorkflowSpecListComponent,
], ],
imports: [
HttpClientTestingModule
],
providers: [
HttpClient,
ApiService,
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {
@ -43,7 +55,7 @@ describe('HomeComponent', () => {
}); });
it('should check signed-in state', () => { it('should check signed-in state', () => {
const result = component.isSignedIn(); const result = component.isSignedIn;
expect(result).toBeDefined(); expect(result).toBeDefined();
expect(typeof result).toEqual('boolean'); expect(typeof result).toEqual('boolean');
}); });

View File

@ -1,5 +1,5 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {isSignedIn} from 'sartography-workflow-lib'; import {ApiService, isSignedIn} from 'sartography-workflow-lib';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
@ -7,9 +7,11 @@ import {isSignedIn} from 'sartography-workflow-lib';
styleUrls: ['./home.component.scss'] styleUrls: ['./home.component.scss']
}) })
export class HomeComponent { export class HomeComponent {
isSignedIn = isSignedIn;
constructor() { constructor(private apiService: ApiService) {
} }
get isSignedIn(): boolean {
return this.apiService.isSignedIn();
}
} }