Fix tests + primary process selection
This commit is contained in:
parent
3247614f8d
commit
50bd604583
|
@ -7,11 +7,11 @@
|
|||
>
|
||||
<mat-icon (click)="editFile(fm)" mat-list-icon>{{fm.type | getIconCode}}</mat-icon>
|
||||
<ng-container *ngIf="fm.type === fileType.BPMN && !this.workflowSpec.library">
|
||||
<button (click)="makePrimary(fm)" *ngIf="!(fm.name === workflowSpec.primary_file_name)" mat-flat-button class="make-primary">
|
||||
<button (click)="makePrimary(fm)" *ngIf="!(fm.name === this.workflowSpec.primary_file_name)" mat-flat-button class="make-primary">
|
||||
<mat-icon>radio_button_unchecked</mat-icon>
|
||||
Make primary process
|
||||
</button>
|
||||
<button *ngIf="fm.name === workflowSpec.primary_file_name" mat-flat-button class="make-primary">
|
||||
<button *ngIf="fm.name === this.workflowSpec.primary_file_name" mat-flat-button class="make-primary">
|
||||
<mat-icon>radio_button_checked</mat-icon>
|
||||
Primary process
|
||||
</button>
|
||||
|
|
|
@ -24,6 +24,7 @@ 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 * as http from "http";
|
||||
|
||||
|
||||
describe('FileListComponent', () => {
|
||||
|
@ -81,11 +82,15 @@ describe('FileListComponent', () => {
|
|||
fixture.detectChanges();
|
||||
|
||||
|
||||
const fmsReq = httpMock.expectOne(`apiRoot/spec_file?workflow_spec_id=${mockWorkflowSpec0.id}`);
|
||||
const fmsReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file?workflow_spec_id=${mockWorkflowSpec0.id}`);
|
||||
expect(fmsReq.request.method).toEqual('GET');
|
||||
fmsReq.flush(mockFileMetas);
|
||||
expect(component.fileMetas.length).toBeGreaterThan(0);
|
||||
|
||||
const wfsReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}`);
|
||||
expect(fmsReq.request.method).toEqual('GET');
|
||||
wfsReq.flush(mockWorkflowSpec0);
|
||||
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -133,7 +138,7 @@ describe('FileListComponent', () => {
|
|||
it('should delete a file', () => {
|
||||
const loadFileMetasSpy = spyOn((component as any), '_loadFileMetas').and.stub();
|
||||
(component as any)._deleteFile(mockFileMeta0);
|
||||
const fmsReq = httpMock.expectOne(`apiRoot/spec_file/${mockFileMeta0.id}`);
|
||||
const fmsReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file/${mockFileMeta0.name}`);
|
||||
expect(fmsReq.request.method).toEqual('DELETE');
|
||||
fmsReq.flush(null);
|
||||
|
||||
|
@ -144,13 +149,13 @@ describe('FileListComponent', () => {
|
|||
const routerNavigateSpy = spyOn((component as any).router, 'navigate');
|
||||
component.workflowSpec = mockWorkflowSpec0;
|
||||
component.editFile(mockFileMeta0);
|
||||
expect(routerNavigateSpy).toHaveBeenCalledWith([`/modeler/${mockWorkflowSpec0.id}/${mockFileMeta0.id}`]);
|
||||
expect(routerNavigateSpy).toHaveBeenCalledWith([`/modeler/${mockWorkflowSpec0.id}/file/${mockFileMeta0.name}`]);
|
||||
|
||||
routerNavigateSpy.calls.reset();
|
||||
const mockDmnMeta = cloneDeep(mockFileMeta0);
|
||||
mockDmnMeta.type = FileType.DMN;
|
||||
component.editFile(mockDmnMeta);
|
||||
expect(routerNavigateSpy).toHaveBeenCalledWith([`/modeler/${mockWorkflowSpec0.id}/${mockDmnMeta.id}`]);
|
||||
expect(routerNavigateSpy).toHaveBeenCalledWith([`/modeler/${mockWorkflowSpec0.id}/file/${mockDmnMeta.name}`]);
|
||||
});
|
||||
|
||||
it('should open file metadata dialog for non-BPMN files', () => {
|
||||
|
@ -181,7 +186,7 @@ describe('FileListComponent', () => {
|
|||
type: mockDocMeta.content_type,
|
||||
lastModified: timeCode
|
||||
});
|
||||
const fReq = httpMock.expectOne(`apiRoot/spec_file/${mockDocMeta.id}/data`);
|
||||
const fReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file/${mockDocMeta.name}/data`);
|
||||
|
||||
const mockHeaders = new HttpHeaders()
|
||||
.append('last-modified', expectedFile.lastModified.toString())
|
||||
|
@ -204,8 +209,8 @@ describe('FileListComponent', () => {
|
|||
component.workflowSpec = mockWorkflowSpec0;
|
||||
|
||||
(component as any)._openFileDialog();
|
||||
const addReq = httpMock.expectOne(`apiRoot/spec_file?workflow_spec_id=${mockWorkflowSpec0.id}`);
|
||||
expect(addReq.request.method).toEqual('POST');
|
||||
const addReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file?workflow_spec_id=${mockWorkflowSpec0.id}`);
|
||||
|
||||
addReq.flush(mockFileMeta0);
|
||||
|
||||
expect(openDialogSpy).toHaveBeenCalled();
|
||||
|
@ -219,8 +224,7 @@ describe('FileListComponent', () => {
|
|||
component.workflowSpec = mockWorkflowSpec0;
|
||||
|
||||
(component as any)._openFileDialog(mockFileMeta0, mockFile0);
|
||||
const updateReq = httpMock.expectOne(`apiRoot/spec_file/${mockFileMeta0.id}/data`);
|
||||
expect(updateReq.request.method).toEqual('PUT');
|
||||
const updateReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file/${mockFileMeta0.name}/data`);
|
||||
updateReq.flush(mockFileMeta0);
|
||||
|
||||
expect(openDialogSpy).toHaveBeenCalled();
|
||||
|
@ -228,14 +232,14 @@ describe('FileListComponent', () => {
|
|||
});
|
||||
|
||||
it('should flag a file as primary', () => {
|
||||
const updateFileMetaSpy = spyOn((component as any).api, 'updateFileMeta').and.returnValue(of(mockFileMeta0));
|
||||
const _loadFileMetasSpy = spyOn((component as any), '_loadFileMetas').and.stub();
|
||||
expect(component.fileMetas.length).toEqual(mockFileMetas.length);
|
||||
component.makePrimary(mockFileMeta0);
|
||||
|
||||
expect(updateFileMetaSpy).toHaveBeenCalledTimes(mockFileMetas.length);
|
||||
const updateReq = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file/${mockFileMeta0.name}?is_primary=true`);
|
||||
updateReq.flush(mockFileMeta0);
|
||||
|
||||
expect(component.fileMetas.length).toEqual(mockFileMetas.length);
|
||||
expect(component.fileMetas.reduce((sum, fm) => fm.primary ? sum + 1 : sum, 0)).toEqual(1);
|
||||
expect(_loadFileMetasSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -138,5 +138,8 @@ export class FileListComponent implements OnInit, OnChanges {
|
|||
this.api.getSpecFileMetas(this.workflowSpec.id).subscribe(fms => {
|
||||
this.fileMetas = fms.sort((a, b) => (a.name > b.name) ? 1 : -1);
|
||||
});
|
||||
this.api.getWorkflowSpecification(this.workflowSpec.id).subscribe(wfs => {
|
||||
this.workflowSpec = wfs;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,13 +129,10 @@ describe('ModelerComponent', () => {
|
|||
wfsReq.flush(mockWorkflowSpec0);
|
||||
expect(component.workflowSpec).toEqual(mockWorkflowSpec0);
|
||||
|
||||
const req = httpMock.expectOne(`apiRoot/spec_file?workflow_spec_id=${mockWorkflowSpec0.id}`);
|
||||
const req = httpMock.expectOne(`apiRoot/workflow-specification/${mockWorkflowSpec0.id}/file?workflow_spec_id=${mockWorkflowSpec0.id}`);
|
||||
expect(req.request.method).toEqual('GET');
|
||||
req.flush(mockFileMetas);
|
||||
|
||||
const fmReq = httpMock.expectOne(`apiRoot/spec_file/${mockFileMeta0.id}/data`);
|
||||
|
||||
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -218,14 +215,6 @@ describe('ModelerComponent', () => {
|
|||
expect(handleImportedSpy).toHaveBeenCalledWith(expectedParams);
|
||||
});
|
||||
|
||||
it('should get the diagram file name', () => {
|
||||
expect(component.getFileName()).toEqual(mockFileMeta0.name);
|
||||
|
||||
const filename = 'one-fish.bpmn';
|
||||
component.diagramFileMeta.name = filename;
|
||||
expect(component.getFileName()).toEqual(filename);
|
||||
});
|
||||
|
||||
it('should get the diagram file from the file input form control', () => {
|
||||
const expectedFile = new File([], 'filename.jpg', {type: 'image/jpeg'});
|
||||
const event = {target: {files: [expectedFile]}};
|
||||
|
@ -287,7 +276,7 @@ describe('ModelerComponent', () => {
|
|||
component.diagramComponent.writeValue(BPMN_DIAGRAM_EMPTY.replace(/REPLACE_ME/g, 'cream_colored_ponies'));
|
||||
component.saveFileChanges();
|
||||
|
||||
expect(updateFileDataSpy).toHaveBeenCalledWith(mockFileMeta0, mockFile0);
|
||||
expect(updateFileDataSpy).toHaveBeenCalledWith(mockWorkflowSpec0, mockFileMeta0, mockFile0);
|
||||
expect(snackBarOpenSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -311,6 +300,7 @@ describe('ModelerComponent', () => {
|
|||
fileName: mockFileMeta0.name,
|
||||
fileType: FileType.BPMN,
|
||||
};
|
||||
|
||||
const updateFileMetaSpy = spyOn(component.api, 'updateSpecFileMeta')
|
||||
.and.returnValue(of(mockFileMeta0));
|
||||
const updateFileDataSpy = spyOn(component.api, 'updateSpecFileData')
|
||||
|
@ -319,54 +309,22 @@ describe('ModelerComponent', () => {
|
|||
const snackBarSpy = spyOn(component.snackBar, 'open').and.stub();
|
||||
const noDateOrVersion: FileMeta = {
|
||||
content_type: mockFileMeta0.content_type,
|
||||
id: mockFileMeta0.id,
|
||||
name: mockFileMeta0.name,
|
||||
type: mockFileMeta0.type,
|
||||
workflow_spec_id: mockFileMeta0.workflow_spec_id,
|
||||
};
|
||||
|
||||
// upsert original file
|
||||
component.draftXml = newXml;
|
||||
component._upsertFileMeta(data);
|
||||
|
||||
expect(component.xml).toEqual(newXml);
|
||||
expect(updateFileMetaSpy).toHaveBeenCalledWith(noDateOrVersion);
|
||||
expect(updateFileDataSpy).toHaveBeenCalledWith(noDateOrVersion, mockFile0);
|
||||
expect(updateFileMetaSpy).toHaveBeenCalledWith(mockWorkflowSpec0, noDateOrVersion, false);
|
||||
expect(updateFileDataSpy).toHaveBeenCalledWith(mockWorkflowSpec0, noDateOrVersion, mockFile0);
|
||||
expect(loadFilesFromDbSpy).toHaveBeenCalled();
|
||||
expect(snackBarSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create new file metadata for new file', () => {
|
||||
const newXml = BPMN_DIAGRAM_EMPTY.replace(/REPLACE_ME/g, 'doorbells');
|
||||
const data: FileMetaDialogData = {
|
||||
fileName: mockFileMeta0.name,
|
||||
fileType: FileType.BPMN,
|
||||
};
|
||||
|
||||
const noDateOrVersion: FileMeta = {
|
||||
id: undefined,
|
||||
content_type: mockFileMeta0.content_type,
|
||||
name: mockFileMeta0.name,
|
||||
type: mockFileMeta0.type,
|
||||
workflow_spec_id: mockFileMeta0.workflow_spec_id,
|
||||
};
|
||||
|
||||
const addFileMetaSpy = spyOn(component.api, 'addSpecFile')
|
||||
.and.returnValue(of(mockFileMeta0));
|
||||
const loadFilesFromDbSpy = spyOn(component, 'loadFilesFromDb').and.stub();
|
||||
const routerNavigateSpy = spyOn(component.router, 'navigate').and.stub();
|
||||
const snackBarSpy = spyOn(component.snackBar, 'open').and.stub();
|
||||
|
||||
component.newDiagram(FileType.BPMN);
|
||||
expect(component.diagramFileMeta).toBeFalsy();
|
||||
|
||||
component.draftXml = newXml;
|
||||
component._upsertFileMeta(data);
|
||||
expect(component.xml).toEqual(newXml);
|
||||
expect(addFileMetaSpy).toHaveBeenCalledWith(mockWorkflowSpec0, noDateOrVersion, mockFile0);
|
||||
expect(loadFilesFromDbSpy).not.toHaveBeenCalled();
|
||||
expect(routerNavigateSpy).toHaveBeenCalled();
|
||||
expect(snackBarSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should load files from the database', () => {
|
||||
const mockHeaders = new HttpHeaders()
|
||||
.append('last-modified', mockFileMeta0.last_modified.toString())
|
||||
|
|
|
@ -207,6 +207,7 @@ export class ModelerComponent implements AfterViewInit {
|
|||
|
||||
onFileSelected($event: Event) {
|
||||
this.diagramFile = ($event.target as HTMLFormElement).files[0];
|
||||
this.fileName = this.diagramFile.name;
|
||||
this.onSubmitFileToOpen();
|
||||
this.isNew = true;
|
||||
}
|
||||
|
@ -390,11 +391,7 @@ export class ModelerComponent implements AfterViewInit {
|
|||
};
|
||||
this.diagramFile = new File([this.xml], data.fileName, {type: 'text/xml'});
|
||||
|
||||
|
||||
//TODO: if filename not in bpmnFiles, AND data.fileName is not equal to the params filename (ie you changed the name)
|
||||
// todo: then delete the old paramsFileName thing too
|
||||
if (data.fileName in this.bpmnFiles) {
|
||||
// If the filename has changed, delete the old version
|
||||
if (this.bpmnFiles.find(x => x.name === data.fileName)) {
|
||||
// Update the existing file meta
|
||||
this.api.updateSpecFileData(this.workflowSpec, this.diagramFileMeta, this.diagramFile).subscribe(() => {
|
||||
this.api.updateSpecFileMeta(this.workflowSpec, this.diagramFileMeta, false).subscribe(() => {
|
||||
|
@ -403,6 +400,7 @@ export class ModelerComponent implements AfterViewInit {
|
|||
});
|
||||
});
|
||||
} else {
|
||||
// If the filename has changed, delete the old version
|
||||
if (this.fileMetaName !== data.fileName && this.fileMetaName !== null) {
|
||||
this.api.deleteSpecFileMeta(this.workflowSpec, this.fileMetaName).subscribe(() => {
|
||||
this.api.getSpecFileMetas(this.workflowSpec.id).subscribe(fms => {
|
||||
|
|
Loading…
Reference in New Issue