Fixes failing unit tests
This commit is contained in:
parent
20540d4824
commit
fba504d978
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
|
@ -37,6 +38,7 @@ describe('OpenFileDialogComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef} from '@angular/material/dialog';
|
||||
import {MatFormFieldModule} from '@angular/material/form-field';
|
||||
|
@ -13,7 +14,7 @@ import {FormlyMaterialModule} from '@ngx-formly/material';
|
|||
import {ApiService, MockEnvironment, mockWorkflowSpec0, mockWorkflowSpecCategories} from 'sartography-workflow-lib';
|
||||
import {WorkflowSpecDialogData} from '../../_interfaces/dialog-data';
|
||||
|
||||
import { WorkflowSpecDialogComponent } from './workflow-spec-dialog.component';
|
||||
import {WorkflowSpecDialogComponent} from './workflow-spec-dialog.component';
|
||||
|
||||
describe('WorkflowSpecDialogComponent', () => {
|
||||
let httpMock: HttpTestingController;
|
||||
|
@ -37,10 +38,11 @@ describe('WorkflowSpecDialogComponent', () => {
|
|||
ReactiveFormsModule,
|
||||
RouterTestingModule,
|
||||
],
|
||||
declarations: [ WorkflowSpecDialogComponent ],
|
||||
declarations: [WorkflowSpecDialogComponent],
|
||||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
@ -59,7 +61,7 @@ describe('WorkflowSpecDialogComponent', () => {
|
|||
{provide: Router, useValue: mockRouter},
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -7,8 +7,6 @@ import {HomeComponent} from './home/home.component';
|
|||
import {ModelerComponent} from './modeler/modeler.component';
|
||||
import {ProtocolBuilderComponent} from './protocol-builder/protocol-builder.component';
|
||||
import {ReferenceFilesComponent} from './reference-files/reference-files.component';
|
||||
import {SignInComponent} from './sign-in/sign-in.component';
|
||||
import {SignOutComponent} from './sign-out/sign-out.component';
|
||||
|
||||
@Injectable()
|
||||
export class ThisEnvironment implements AppEnvironment {
|
||||
|
@ -16,7 +14,6 @@ export class ThisEnvironment implements AppEnvironment {
|
|||
production = environment.production;
|
||||
api = environment.api;
|
||||
irbUrl = environment.irbUrl;
|
||||
baseHref = environment.baseHref;
|
||||
}
|
||||
|
||||
const routes: Routes = [
|
||||
|
@ -45,14 +42,6 @@ const routes: Routes = [
|
|||
path: 'modeler/:workflowSpecId/:fileMetaId',
|
||||
component: ModelerComponent
|
||||
},
|
||||
{
|
||||
path: 'sign-in',
|
||||
component: SignInComponent
|
||||
},
|
||||
{
|
||||
path: 'sign-out',
|
||||
component: SignOutComponent
|
||||
},
|
||||
{
|
||||
path: 'session/:token',
|
||||
component: SessionRedirectComponent
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
||||
import {Component} from '@angular/core';
|
||||
|
@ -42,6 +43,7 @@ describe('AppComponent', () => {
|
|||
HttpClient,
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
],
|
||||
})
|
||||
.compileComponents();
|
||||
|
|
|
@ -49,8 +49,6 @@ import {ModelerComponent} from './modeler/modeler.component';
|
|||
import {NavbarComponent} from './navbar/navbar.component';
|
||||
import {ProtocolBuilderComponent} from './protocol-builder/protocol-builder.component';
|
||||
import {ReferenceFilesComponent} from './reference-files/reference-files.component';
|
||||
import {SignInComponent} from './sign-in/sign-in.component';
|
||||
import {SignOutComponent} from './sign-out/sign-out.component';
|
||||
import {WorkflowSpecCardComponent} from './workflow-spec-card/workflow-spec-card.component';
|
||||
import {WorkflowSpecListComponent} from './workflow-spec-list/workflow-spec-list.component';
|
||||
|
||||
|
@ -60,7 +58,6 @@ export class ThisEnvironment implements AppEnvironment {
|
|||
production = environment.production;
|
||||
api = environment.api;
|
||||
irbUrl = environment.irbUrl;
|
||||
baseHref = environment.baseHref;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,8 +90,6 @@ export function getBaseHref(platformLocation: PlatformLocation): string {
|
|||
NavbarComponent,
|
||||
NewFileDialogComponent,
|
||||
OpenFileDialogComponent,
|
||||
SignInComponent,
|
||||
SignOutComponent,
|
||||
WorkflowSpecCategoryDialogComponent,
|
||||
WorkflowSpecDialogComponent,
|
||||
WorkflowSpecListComponent,
|
||||
|
@ -145,11 +140,9 @@ export function getBaseHref(platformLocation: PlatformLocation): string {
|
|||
providers: [
|
||||
{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {appearance: 'outline'}},
|
||||
{provide: 'APP_ENVIRONMENT', useClass: ThisEnvironment},
|
||||
// {provide: APP_BASE_HREF, useValue: environment.baseHref},
|
||||
{provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true},
|
||||
{provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true},
|
||||
{provide: APP_BASE_HREF, useFactory: getBaseHref, deps: [PlatformLocation]
|
||||
}
|
||||
{provide: APP_BASE_HREF, useFactory: getBaseHref, deps: [PlatformLocation]}
|
||||
]
|
||||
})
|
||||
export class AppModule {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {DebugNode} from '@angular/core';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
@ -31,6 +32,7 @@ describe('DiagramComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{provide: Router, useValue: mockRouter},
|
||||
]
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpHeaders} from '@angular/common/http';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
@ -8,6 +9,7 @@ import {MatSnackBarModule} from '@angular/material/snack-bar';
|
|||
import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/testing';
|
||||
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
import createClone from 'rfdc';
|
||||
import {of} from 'rxjs';
|
||||
import {
|
||||
ApiService,
|
||||
|
@ -22,7 +24,6 @@ import {DeleteFileDialogComponent} from '../_dialogs/delete-file-dialog/delete-f
|
|||
import {DeleteFileDialogData} from '../_interfaces/dialog-data';
|
||||
import {GetIconCodePipe} from '../_pipes/get-icon-code.pipe';
|
||||
import {FileListComponent} from './file-list.component';
|
||||
import createClone from 'rfdc';
|
||||
|
||||
|
||||
describe('FileListComponent', () => {
|
||||
|
@ -49,6 +50,7 @@ describe('FileListComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
||||
import {Component} from '@angular/core';
|
||||
|
@ -43,6 +44,7 @@ describe('HomeComponent', () => {
|
|||
HttpClient,
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{provide: Router, useValue: mockRouter},
|
||||
]
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpErrorResponse, HttpHeaders, HttpResponse} from '@angular/common/http';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {DebugNode} from '@angular/core';
|
||||
|
@ -75,6 +76,7 @@ describe('ModelerComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {MatIconModule} from '@angular/material/icon';
|
||||
|
@ -32,6 +33,7 @@ describe('NavbarComponent', () => {
|
|||
useValue: mockRouter
|
||||
},
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
],
|
||||
})
|
||||
.compileComponents();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpHeaders} from '@angular/common/http';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {MAT_DIALOG_DATA, MatDialogModule, MatDialogRef} from '@angular/material/dialog';
|
||||
import {MatIconModule} from '@angular/material/icon';
|
||||
import {MatSnackBarModule} from '@angular/material/snack-bar';
|
||||
|
@ -8,12 +9,12 @@ import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/tes
|
|||
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
|
||||
import {Router} from '@angular/router';
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
import * as FileSaver from 'file-saver';
|
||||
import createClone from 'rfdc';
|
||||
import {of} from 'rxjs';
|
||||
import {ApiService, FileMeta, FileType, MockEnvironment, mockFileMetaReference0} from 'sartography-workflow-lib';
|
||||
import {OpenFileDialogComponent} from '../_dialogs/open-file-dialog/open-file-dialog.component';
|
||||
import * as FileSaver from 'file-saver';
|
||||
import { ReferenceFilesComponent } from './reference-files.component';
|
||||
import createClone from 'rfdc';
|
||||
import {ReferenceFilesComponent} from './reference-files.component';
|
||||
|
||||
describe('ReferenceFilesComponent', () => {
|
||||
let httpMock: HttpTestingController;
|
||||
|
@ -53,6 +54,7 @@ describe('ReferenceFilesComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
@ -70,7 +72,7 @@ describe('ReferenceFilesComponent', () => {
|
|||
]
|
||||
}
|
||||
})
|
||||
.compileComponents();
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -96,7 +98,12 @@ describe('ReferenceFilesComponent', () => {
|
|||
|
||||
it('should update existing file from file dialog', () => {
|
||||
const openDialogSpy = spyOn(component.dialog, 'open')
|
||||
.and.returnValue({afterClosed: () => of({fileMetaId: mockFileMetaReference0.id, file: mockFileMetaReference0.file})} as any);
|
||||
.and.returnValue({
|
||||
afterClosed: () => of({
|
||||
fileMetaId: mockFileMetaReference0.id,
|
||||
file: mockFileMetaReference0.file
|
||||
})
|
||||
} as any);
|
||||
const _loadReferenceFilesSpy = spyOn((component as any), '_loadReferenceFiles').and.stub();
|
||||
|
||||
component.openFileDialog(mockFileMetaReference0);
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
<div class="full-height" fxLayout="column" fxLayoutAlign="center center">
|
||||
<h1>Fake UVA NetBadge Sign In (for testing only)</h1>
|
||||
<formly-form [fields]="fields" [form]="form" [model]="model">
|
||||
<mat-error *ngIf="error">{{error}}</mat-error>
|
||||
<button
|
||||
(click)="signIn()"
|
||||
[disabled]="form.invalid"
|
||||
color="primary"
|
||||
id="sign_in"
|
||||
mat-flat-button
|
||||
>
|
||||
Sign in
|
||||
</button>
|
||||
</formly-form>
|
||||
</div>
|
|
@ -1,9 +0,0 @@
|
|||
form {
|
||||
min-width: 150px;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MatFormFieldModule} from '@angular/material/form-field';
|
||||
import {MatInputModule} from '@angular/material/input';
|
||||
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
|
||||
import {ActivatedRoute, convertToParamMap, Router} from '@angular/router';
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
import {FormlyModule} from '@ngx-formly/core';
|
||||
import {FormlyMaterialModule} from '@ngx-formly/material';
|
||||
import {of} from 'rxjs';
|
||||
import {ApiService, MockEnvironment, mockUser} from 'sartography-workflow-lib';
|
||||
import {EmailValidator, EmailValidatorMessage} from '../_forms/validators/formly.validator';
|
||||
import {SignInComponent} from './sign-in.component';
|
||||
|
||||
describe('SignInComponent', () => {
|
||||
let component: SignInComponent;
|
||||
let fixture: ComponentFixture<SignInComponent>;
|
||||
let httpMock: HttpTestingController;
|
||||
const mockRouter = {navigate: jasmine.createSpy('navigate')};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SignInComponent],
|
||||
imports: [
|
||||
BrowserAnimationsModule,
|
||||
FormlyModule.forRoot({
|
||||
validators: [
|
||||
{name: 'email', validation: EmailValidator},
|
||||
],
|
||||
validationMessages: [
|
||||
{name: 'email', message: EmailValidatorMessage},
|
||||
],
|
||||
}),
|
||||
FormlyMaterialModule,
|
||||
HttpClientTestingModule,
|
||||
FormsModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
NoopAnimationsModule,
|
||||
RouterTestingModule,
|
||||
],
|
||||
providers: [
|
||||
ApiService,
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {paramMap: of(convertToParamMap({study_id: '0', workflow_id: '0', task_id: '0'}))}
|
||||
},
|
||||
{
|
||||
provide: Router,
|
||||
useValue: mockRouter
|
||||
},
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
],
|
||||
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
httpMock = TestBed.inject(HttpTestingController);
|
||||
fixture = TestBed.createComponent(SignInComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should fake sign in during testing', () => {
|
||||
const redirectToLoginSpy = spyOn((component as any).api, 'redirectToLogin').and.stub();
|
||||
(component as any).environment.production = false;
|
||||
component.model = mockUser;
|
||||
component.signIn();
|
||||
expect(redirectToLoginSpy).toHaveBeenCalledWith(jasmine.any(String), mockUser);
|
||||
expect(component.error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should display an error if sign in is called on production', () => {
|
||||
const redirectToLoginSpy = spyOn((component as any).api, 'redirectToLogin').and.stub();
|
||||
(component as any).environment.production = true;
|
||||
component.signIn();
|
||||
expect(redirectToLoginSpy).not.toHaveBeenCalled();
|
||||
expect(component.error).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should verify the user and redirect to home page on production', () => {
|
||||
const getUserSpy = spyOn((component as any).api, 'getUser').and.returnValue(of(mockUser));
|
||||
(component as any).environment.production = true;
|
||||
(component as any)._redirectOnProduction();
|
||||
expect(getUserSpy).toHaveBeenCalled();
|
||||
expect(mockRouter.navigate).toHaveBeenCalledWith(['/']);
|
||||
});
|
||||
});
|
|
@ -1,90 +0,0 @@
|
|||
import {PlatformLocation} from '@angular/common';
|
||||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import {FormGroup} from '@angular/forms';
|
||||
import {Router} from '@angular/router';
|
||||
import {FormlyFieldConfig} from '@ngx-formly/core';
|
||||
import {ApiService, AppEnvironment, User} from 'sartography-workflow-lib';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sign-in',
|
||||
templateUrl: './sign-in.component.html',
|
||||
styleUrls: ['./sign-in.component.scss']
|
||||
})
|
||||
export class SignInComponent implements OnInit {
|
||||
form = new FormGroup({});
|
||||
model: any = {};
|
||||
fields: FormlyFieldConfig[] = [
|
||||
{
|
||||
key: 'uid',
|
||||
type: 'input',
|
||||
defaultValue: 'czn1z',
|
||||
templateOptions: {
|
||||
required: true,
|
||||
label: 'UVA Computing ID',
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'email_address',
|
||||
type: 'input',
|
||||
defaultValue: 'czn1z@virginia.edu',
|
||||
templateOptions: {
|
||||
required: true,
|
||||
type: 'email',
|
||||
label: 'UVA Email Address',
|
||||
},
|
||||
validators: {validation: ['email']},
|
||||
},
|
||||
{
|
||||
key: 'first_name',
|
||||
type: 'input',
|
||||
defaultValue: 'Addison',
|
||||
templateOptions: {
|
||||
label: 'First Name',
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'last_name',
|
||||
type: 'input',
|
||||
defaultValue: 'Minh',
|
||||
templateOptions: {
|
||||
label: 'First Name',
|
||||
},
|
||||
},
|
||||
];
|
||||
error: Error;
|
||||
|
||||
|
||||
constructor(
|
||||
@Inject('APP_ENVIRONMENT') private environment: AppEnvironment,
|
||||
private router: Router,
|
||||
private api: ApiService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this._redirectOnProduction();
|
||||
}
|
||||
|
||||
signIn() {
|
||||
this.error = undefined;
|
||||
localStorage.removeItem('token');
|
||||
|
||||
// For testing purposes, create a user to simulate login.
|
||||
this.api.redirectToLogin();
|
||||
}
|
||||
|
||||
// If this is production, verify the user and redirect to home page.
|
||||
private _redirectOnProduction() {
|
||||
if (this.environment.production) {
|
||||
this.api.getUser().subscribe((user: User) => {
|
||||
this.router.navigate(['/']);
|
||||
}, e => {
|
||||
this.error = e;
|
||||
localStorage.removeItem('token');
|
||||
this.router.navigate(['/']);
|
||||
});
|
||||
} else {
|
||||
localStorage.removeItem('token');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<div class="full-height" fxLayout="column" fxLayoutAlign="center center">
|
||||
<h1>You have been signed out.</h1>
|
||||
<button
|
||||
mat-flat-button
|
||||
color="accent"
|
||||
(click)="goHome()">Ok</button>
|
||||
</div>
|
|
@ -1,49 +0,0 @@
|
|||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
import {ApiService, MockEnvironment} from 'sartography-workflow-lib';
|
||||
|
||||
import {SignOutComponent} from './sign-out.component';
|
||||
|
||||
describe('SignOutComponent', () => {
|
||||
let component: SignOutComponent;
|
||||
let fixture: ComponentFixture<SignOutComponent>;
|
||||
let httpMock: HttpTestingController;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SignOutComponent],
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
RouterTestingModule,
|
||||
],
|
||||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
],
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
httpMock = TestBed.inject(HttpTestingController);
|
||||
fixture = TestBed.createComponent(SignOutComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should go home', () => {
|
||||
const openUrlSpy = spyOn((component as any).api, 'openUrl').and.stub();
|
||||
component.goHome();
|
||||
expect(openUrlSpy).toHaveBeenCalledWith('/');
|
||||
});
|
||||
});
|
|
@ -1,22 +0,0 @@
|
|||
import {Component, OnInit} from '@angular/core';
|
||||
import {ApiService} from 'sartography-workflow-lib';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sign-out',
|
||||
templateUrl: './sign-out.component.html',
|
||||
styleUrls: ['./sign-out.component.scss']
|
||||
})
|
||||
export class SignOutComponent implements OnInit {
|
||||
|
||||
constructor(private api: ApiService, private router: Router) {
|
||||
localStorage.removeItem('token');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
goHome() {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {MatCardModule} from '@angular/material/card';
|
||||
|
@ -34,6 +35,7 @@ describe('WorkflowSpecCardComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {MAT_BOTTOM_SHEET_DATA, MatBottomSheetModule, MatBottomSheetRef} from '@angular/material/bottom-sheet';
|
||||
|
@ -15,11 +16,14 @@ import {
|
|||
ApiService,
|
||||
MockEnvironment,
|
||||
mockWorkflowSpec0,
|
||||
mockWorkflowSpec1, mockWorkflowSpec2,
|
||||
mockWorkflowSpec1,
|
||||
mockWorkflowSpec2,
|
||||
mockWorkflowSpecCategories,
|
||||
mockWorkflowSpecCategory0,
|
||||
mockWorkflowSpecCategory1, mockWorkflowSpecCategory2,
|
||||
mockWorkflowSpecs, moveArrayElementUp, WorkflowSpec, WorkflowSpecCategory
|
||||
mockWorkflowSpecCategory1,
|
||||
mockWorkflowSpecCategory2,
|
||||
mockWorkflowSpecs,
|
||||
WorkflowSpec
|
||||
} from 'sartography-workflow-lib';
|
||||
import {ApiError} from 'sartography-workflow-lib/lib/types/api';
|
||||
import {DeleteWorkflowSpecDialogComponent} from '../_dialogs/delete-workflow-spec-dialog/delete-workflow-spec-dialog.component';
|
||||
|
@ -32,7 +36,7 @@ import {
|
|||
import {GetIconCodePipe} from '../_pipes/get-icon-code.pipe';
|
||||
import {ApiErrorsComponent} from '../api-errors/api-errors.component';
|
||||
import {FileListComponent} from '../file-list/file-list.component';
|
||||
import {WorkflowSpecCategoryGroup, WorkflowSpecListComponent} from './workflow-spec-list.component';
|
||||
import {WorkflowSpecListComponent} from './workflow-spec-list.component';
|
||||
|
||||
describe('WorkflowSpecListComponent', () => {
|
||||
let httpMock: HttpTestingController;
|
||||
|
@ -62,6 +66,7 @@ describe('WorkflowSpecListComponent', () => {
|
|||
providers: [
|
||||
ApiService,
|
||||
{provide: 'APP_ENVIRONMENT', useClass: MockEnvironment},
|
||||
{provide: APP_BASE_HREF, useValue: ''},
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
|
@ -366,7 +371,7 @@ describe('WorkflowSpecListComponent', () => {
|
|||
const snackBarSpy = spyOn((component as any).snackBar, 'open').and.stub();
|
||||
const moveUpSpy = spyOn(component, 'moveUp').and.callThrough();
|
||||
const moveDownSpy = spyOn(component, 'moveDown').and.callThrough();
|
||||
const expectedCatsAfter = [ mockWorkflowSpecCategory1, mockWorkflowSpecCategory0, mockWorkflowSpecCategory2 ];
|
||||
const expectedCatsAfter = [mockWorkflowSpecCategory1, mockWorkflowSpecCategory0, mockWorkflowSpecCategory2];
|
||||
|
||||
expect((component as any)._reorder(99, 1, mockWorkflowSpecCategories)).toEqual([]);
|
||||
expect(snackBarSpy).toHaveBeenCalled();
|
||||
|
|
|
@ -9,5 +9,4 @@ export const environment: AppEnvironment = {
|
|||
production: _has(ENV, 'production', '$PRODUCTION') ? (ENV.production === 'true') : false,
|
||||
api: _has(ENV, 'api', '$API_URL') ? ENV.api : 'http://localhost:5000/v1.0',
|
||||
irbUrl: _has(ENV, 'irbUrl', '$IRB_URL') ? ENV.irbUrl : 'http://localhost:5001',
|
||||
baseHref: _has(ENV, 'baseHref', '$BASE_HREF') ? ENV.baseHref : '/',
|
||||
};
|
||||
|
|
|
@ -10,7 +10,6 @@ describe('Environments', () => {
|
|||
expect(environment.api).toEqual('apiRoot');
|
||||
expect(environment.irbUrl).toEqual('irbUrl');
|
||||
expect(environment.homeRoute).toEqual('home');
|
||||
expect(environment.baseHref).toEqual('/');
|
||||
});
|
||||
|
||||
it('should check if environment variables are defined', () => {
|
||||
|
@ -19,37 +18,31 @@ describe('Environments', () => {
|
|||
production: '$PRODUCTION',
|
||||
api: '$API_URL',
|
||||
irbUrl: '$IRB_URL',
|
||||
baseHref: '$BASE_HREF',
|
||||
};
|
||||
|
||||
expect(_has(env, 'homeRoute', '$HOME_ROUTE')).toBeFalse();
|
||||
expect(_has(env, 'production', '$PRODUCTION')).toBeFalse();
|
||||
expect(_has(env, 'api', '$API_URL')).toBeFalse();
|
||||
expect(_has(env, 'irbUrl', '$IRB_URL')).toBeFalse();
|
||||
expect(_has(env, 'baseHref', '$BASE_HREF')).toBeFalse();
|
||||
|
||||
env.homeRoute = undefined;
|
||||
env.production = undefined;
|
||||
env.api = undefined;
|
||||
env.irbUrl = undefined;
|
||||
env.baseHref = undefined;
|
||||
|
||||
expect(_has(env, 'homeRoute', '$HOME_ROUTE')).toBeFalse();
|
||||
expect(_has(env, 'production', '$PRODUCTION')).toBeFalse();
|
||||
expect(_has(env, 'api', '$API_URL')).toBeFalse();
|
||||
expect(_has(env, 'irbUrl', '$IRB_URL')).toBeFalse();
|
||||
expect(_has(env, 'baseHref', '$BASE_HREF')).toBeFalse();
|
||||
|
||||
env.homeRoute = 'something';
|
||||
env.production = 'something';
|
||||
env.api = 'something';
|
||||
env.irbUrl = 'something';
|
||||
env.baseHref = 'something';
|
||||
|
||||
expect(_has(env, 'homeRoute', '$HOME_ROUTE')).toBeTrue();
|
||||
expect(_has(env, 'production', '$PRODUCTION')).toBeTrue();
|
||||
expect(_has(env, 'api', '$API_URL')).toBeTrue();
|
||||
expect(_has(env, 'irbUrl', '$IRB_URL')).toBeTrue();
|
||||
expect(_has(env, 'baseHref', '$BASE_HREF')).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue