diff --git a/package-lock.json b/package-lock.json index 02361d8..04b9176 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12291,9 +12291,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "sartography-workflow-lib": { - "version": "0.0.175", - "resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.175.tgz", - "integrity": "sha512-hU86cbCNvj2bGOUftIlOBCbWs6Zl+09g2sUAtuhCP5ZIoZ76xCWAPBUggPGltcEHvQU4Tc1bbMwM8EdfxJuqAQ==" + "version": "0.0.176", + "resolved": "https://registry.npmjs.org/sartography-workflow-lib/-/sartography-workflow-lib-0.0.176.tgz", + "integrity": "sha512-eIYGwLMVDUXFEyu3SWIRsvCiMdswSQnJPJvuKH0vhl4i79Ts0ADolaAGo8Gn9Bukm7IMx7QnTXrqa4whJw+FMQ==" }, "sass": { "version": "1.23.3", diff --git a/package.json b/package.json index d005162..87207c9 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "ngx-file-drop": "^8.0.8", "ngx-markdown": "^9.0.0", "rxjs": "~6.5.4", - "sartography-workflow-lib": "^0.0.175", + "sartography-workflow-lib": "^0.0.176", "tslib": "^1.11.1", "uuid": "^7.0.2", "zone.js": "^0.10.3" diff --git a/src/app/_dialogs/open-file-dialog/open-file-dialog.component.spec.ts b/src/app/_dialogs/open-file-dialog/open-file-dialog.component.spec.ts index f90f557..9ccc7fc 100644 --- a/src/app/_dialogs/open-file-dialog/open-file-dialog.component.spec.ts +++ b/src/app/_dialogs/open-file-dialog/open-file-dialog.component.spec.ts @@ -6,6 +6,8 @@ import {MatFormFieldModule} from '@angular/material/form-field'; import {MatIconModule} from '@angular/material/icon'; import {MatInputModule} from '@angular/material/input'; import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; +import {Router} from '@angular/router'; +import {RouterTestingModule} from '@angular/router/testing'; import {ApiService, MockEnvironment, mockFileMeta0} from 'sartography-workflow-lib'; import {OpenFileDialogData} from '../../_interfaces/dialog-data'; @@ -15,6 +17,7 @@ describe('OpenFileDialogComponent', () => { let httpMock: HttpTestingController; let component: OpenFileDialogComponent; let fixture: ComponentFixture; + const mockRouter = {navigate: jasmine.createSpy('navigate')}; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -28,6 +31,7 @@ describe('OpenFileDialogComponent', () => { MatInputModule, NoopAnimationsModule, ReactiveFormsModule, + RouterTestingModule, ], declarations: [ OpenFileDialogComponent ], providers: [ @@ -48,6 +52,7 @@ describe('OpenFileDialogComponent', () => { } }, {provide: MAT_DIALOG_DATA, useValue: []}, + {provide: Router, useValue: mockRouter}, ] }) .compileComponents(); diff --git a/src/app/_dialogs/workflow-spec-dialog/workflow-spec-dialog.component.spec.ts b/src/app/_dialogs/workflow-spec-dialog/workflow-spec-dialog.component.spec.ts index 7e7bb90..4be8eec 100644 --- a/src/app/_dialogs/workflow-spec-dialog/workflow-spec-dialog.component.spec.ts +++ b/src/app/_dialogs/workflow-spec-dialog/workflow-spec-dialog.component.spec.ts @@ -6,6 +6,8 @@ import {MatFormFieldModule} from '@angular/material/form-field'; import {MatIconModule} from '@angular/material/icon'; import {MatInputModule} from '@angular/material/input'; import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; +import {Router} from '@angular/router'; +import {RouterTestingModule} from '@angular/router/testing'; import {FormlyModule} from '@ngx-formly/core'; import {FormlyMaterialModule} from '@ngx-formly/material'; import {ApiService, MockEnvironment, mockWorkflowSpec0, mockWorkflowSpecCategories} from 'sartography-workflow-lib'; @@ -17,6 +19,7 @@ describe('WorkflowSpecDialogComponent', () => { let httpMock: HttpTestingController; let component: WorkflowSpecDialogComponent; let fixture: ComponentFixture; + const mockRouter = {navigate: jasmine.createSpy('navigate')}; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -32,6 +35,7 @@ describe('WorkflowSpecDialogComponent', () => { MatInputModule, NoopAnimationsModule, ReactiveFormsModule, + RouterTestingModule, ], declarations: [ WorkflowSpecDialogComponent ], providers: [ @@ -52,6 +56,7 @@ describe('WorkflowSpecDialogComponent', () => { } }, {provide: MAT_DIALOG_DATA, useValue: []}, + {provide: Router, useValue: mockRouter}, ] }) .compileComponents(); diff --git a/src/app/diagram/diagram.component.spec.ts b/src/app/diagram/diagram.component.spec.ts index 3cd9c35..2937bde 100644 --- a/src/app/diagram/diagram.component.spec.ts +++ b/src/app/diagram/diagram.component.spec.ts @@ -2,6 +2,8 @@ import {HttpClientTestingModule, HttpTestingController} from '@angular/common/ht import {DebugNode} from '@angular/core'; import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {MatIconModule} from '@angular/material/icon'; +import {Router} from '@angular/router'; +import {RouterTestingModule} from '@angular/router/testing'; import * as FileSaver from 'file-saver'; import {ApiService, BPMN_DIAGRAM_DEFAULT, FileType, MockEnvironment} from 'sartography-workflow-lib'; import { @@ -16,17 +18,20 @@ describe('DiagramComponent', () => { let httpMock: HttpTestingController; let fixture: ComponentFixture; let component: DebugNode['componentInstance']; + const mockRouter = {navigate: jasmine.createSpy('navigate')}; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ HttpClientTestingModule, MatIconModule, + RouterTestingModule, ], declarations: [DiagramComponent], providers: [ ApiService, - {provide: 'APP_ENVIRONMENT', useClass: MockEnvironment} + {provide: 'APP_ENVIRONMENT', useClass: MockEnvironment}, + {provide: Router, useValue: mockRouter}, ] }); diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index f047fdf..2a42f0b 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -2,6 +2,8 @@ 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 {Router} from '@angular/router'; +import {RouterTestingModule} from '@angular/router/testing'; import {ApiService, MockEnvironment} from 'sartography-workflow-lib'; import {HomeComponent} from './home.component'; @@ -24,6 +26,7 @@ class MockWorkflowSpecListComponent { describe('HomeComponent', () => { let component: HomeComponent; let fixture: ComponentFixture; + const mockRouter = {navigate: jasmine.createSpy('navigate')}; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -33,12 +36,14 @@ describe('HomeComponent', () => { MockWorkflowSpecListComponent, ], imports: [ - HttpClientTestingModule + HttpClientTestingModule, + RouterTestingModule, ], providers: [ HttpClient, ApiService, {provide: 'APP_ENVIRONMENT', useClass: MockEnvironment}, + {provide: Router, useValue: mockRouter}, ] }) .compileComponents(); diff --git a/src/app/reference-files/reference-files.component.spec.ts b/src/app/reference-files/reference-files.component.spec.ts index 8e16284..e65b11d 100644 --- a/src/app/reference-files/reference-files.component.spec.ts +++ b/src/app/reference-files/reference-files.component.spec.ts @@ -6,6 +6,8 @@ import {MatIconModule} from '@angular/material/icon'; import {MatSnackBarModule} from '@angular/material/snack-bar'; import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/testing'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; +import {Router} from '@angular/router'; +import {RouterTestingModule} from '@angular/router/testing'; 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'; @@ -17,6 +19,7 @@ describe('ReferenceFilesComponent', () => { let httpMock: HttpTestingController; let component: ReferenceFilesComponent; let fixture: ComponentFixture; + const mockRouter = {navigate: jasmine.createSpy('navigate')}; // Mock file and response headers const mockDocMeta: FileMeta = createClone()(mockFileMetaReference0); @@ -41,6 +44,7 @@ describe('ReferenceFilesComponent', () => { MatDialogModule, MatIconModule, MatSnackBarModule, + RouterTestingModule, ], declarations: [ OpenFileDialogComponent, @@ -57,6 +61,7 @@ describe('ReferenceFilesComponent', () => { } }, {provide: MAT_DIALOG_DATA, useValue: []}, + {provide: Router, useValue: mockRouter}, ] }).overrideModule(BrowserDynamicTestingModule, { set: { diff --git a/src/app/sign-in/sign-in.component.spec.ts b/src/app/sign-in/sign-in.component.spec.ts index 9baa1a7..2e39e7c 100644 --- a/src/app/sign-in/sign-in.component.spec.ts +++ b/src/app/sign-in/sign-in.component.spec.ts @@ -74,19 +74,19 @@ describe('SignInComponent', () => { }); it('should fake sign in during testing', () => { - const openSessionSpy = spyOn((component as any).api, 'openSession').and.stub(); + const redirectToLoginSpy = spyOn((component as any).api, 'redirectToLogin').and.stub(); (component as any).environment.production = false; component.model = mockUser; component.signIn(); - expect(openSessionSpy).toHaveBeenCalledWith(mockUser); + expect(redirectToLoginSpy).toHaveBeenCalledWith(jasmine.any(String), mockUser); expect(component.error).toBeUndefined(); }); it('should display an error if sign in is called on production', () => { - const openSessionSpy = spyOn((component as any).api, 'openSession').and.stub(); + const redirectToLoginSpy = spyOn((component as any).api, 'redirectToLogin').and.stub(); (component as any).environment.production = true; component.signIn(); - expect(openSessionSpy).not.toHaveBeenCalled(); + expect(redirectToLoginSpy).not.toHaveBeenCalled(); expect(component.error).toBeTruthy(); }); diff --git a/src/app/sign-in/sign-in.component.ts b/src/app/sign-in/sign-in.component.ts index f0e521e..9de40ea 100644 --- a/src/app/sign-in/sign-in.component.ts +++ b/src/app/sign-in/sign-in.component.ts @@ -72,7 +72,7 @@ export class SignInComponent implements OnInit { // For testing purposes, create a user to simulate login. if (!this.environment.production) { this.model.redirect_url = location.origin + '/session'; - this.api.openSession(this.model); + this.api.redirectToLogin(location.href, this.model); } else { this.error = new Error('This feature does not work in production.'); }