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-workflow-spec-list *ngIf="isSignedIn()"></app-workflow-spec-list>
<app-sign-in *ngIf="!isSignedIn"></app-sign-in>
<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 {MockEnvironment} from 'sartography-workflow-lib';
import {ApiService, MockEnvironment} from 'sartography-workflow-lib';
import {HomeComponent} from './home.component';
@ -9,13 +11,15 @@ import {HomeComponent} from './home.component';
selector: 'app-sign-in',
template: ''
})
class MockSignInComponent {}
class MockSignInComponent {
}
@Component({
selector: 'app-workflow-spec-list',
template: ''
})
class MockWorkflowSpecListComponent {}
class MockWorkflowSpecListComponent {
}
describe('HomeComponent', () => {
let component: HomeComponent;
@ -28,8 +32,16 @@ describe('HomeComponent', () => {
MockSignInComponent,
MockWorkflowSpecListComponent,
],
imports: [
HttpClientTestingModule
],
providers: [
HttpClient,
ApiService,
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
]
})
.compileComponents();
.compileComponents();
}));
beforeEach(() => {
@ -43,7 +55,7 @@ describe('HomeComponent', () => {
});
it('should check signed-in state', () => {
const result = component.isSignedIn();
const result = component.isSignedIn;
expect(result).toBeDefined();
expect(typeof result).toEqual('boolean');
});

View File

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