Signs in with redirect to login and fixes failing tests

This commit is contained in:
Aaron Louie 2020-05-22 08:15:25 -04:00
parent a7a9983a4e
commit bc9c234903
9 changed files with 36 additions and 11 deletions

6
package-lock.json generated
View File

@ -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",

View File

@ -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"

View File

@ -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<OpenFileDialogComponent>;
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();

View File

@ -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<WorkflowSpecDialogComponent>;
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();

View File

@ -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<DiagramComponent>;
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},
]
});

View File

@ -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<HomeComponent>;
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();

View File

@ -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<ReferenceFilesComponent>;
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: {

View File

@ -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();
});

View File

@ -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.');
}