Removes extraneous method.

This commit is contained in:
Aaron Louie 2021-08-13 15:03:33 -04:00
parent 53badb187a
commit 011f0a7356
2 changed files with 7 additions and 13 deletions

View File

@ -28,13 +28,13 @@ describe('DiagramComponent', () => {
const mockRouter = {navigate: jasmine.createSpy('navigate')}; const mockRouter = {navigate: jasmine.createSpy('navigate')};
const testSaveAs = async (fileType: FileType, xml: string, callMethod: string, filename: string) => { const testSaveAs = async (fileType: FileType, xml: string, callMethod: string, filename: string) => {
const saveDiagramSpy = spyOn(component, 'saveDiagram').and.callThrough(); const saveDiagramSpy = spyOn(component, 'saveDiagram').and.callThrough();
const _fileSaveAsSpy = spyOn((component as any), '_fileSaveAs').and.stub(); const fileSaveAsSpy = spyOn(FileSaver, 'saveAs').and.stub();
component.fileName = filename + '.' + fileType; component.fileName = filename + '.' + fileType;
component.diagramType = fileType; component.diagramType = fileType;
component.xml = xml; component.xml = xml;
await component[callMethod](); await component[callMethod]();
await expect(saveDiagramSpy).toHaveBeenCalled(); await expect(saveDiagramSpy).toHaveBeenCalled();
await expect(_fileSaveAsSpy).toHaveBeenCalledWith(jasmine.any(Blob), jasmine.stringMatching(filename)); await expect(fileSaveAsSpy).toHaveBeenCalledWith(jasmine.any(Blob), jasmine.stringMatching(filename));
}; };
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {

View File

@ -1,5 +1,4 @@
import { formatDate } from '@angular/common'; import { formatDate } from '@angular/common';
import { HttpErrorResponse } from '@angular/common/http';
import { import {
AfterViewInit, AfterViewInit,
Component, Component,
@ -43,7 +42,7 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
@Input() validation_data: { [key: string]: any } = {}; @Input() validation_data: { [key: string]: any } = {};
@Input() validation_state: string; @Input() validation_state: string;
@Output() validationStart: EventEmitter<string> = new EventEmitter(); @Output() validationStart: EventEmitter<string> = new EventEmitter();
@Output() private importDone: EventEmitter<ImportEvent> = new EventEmitter(); @Output() importDone: EventEmitter<ImportEvent> = new EventEmitter();
public eventBus; public eventBus;
private diagramType: FileType; private diagramType: FileType;
private modeler: BpmnModeler | DmnModeler; private modeler: BpmnModeler | DmnModeler;
@ -170,7 +169,7 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
await this.saveDiagram(); await this.saveDiagram();
const {svg} = await this.modeler.saveSVG(); const {svg} = await this.modeler.saveSVG();
const blob = new Blob([svg], {type: 'image/svg+xml'}); const blob = new Blob([svg], {type: 'image/svg+xml'});
this._fileSaveAs(blob, this.insertDateIntoFileName()); fileSaver.saveAs(blob, this.insertDateIntoFileName());
} }
async saveDiagram() { async saveDiagram() {
@ -186,9 +185,9 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
async saveXML() { async saveXML() {
await this.saveDiagram(); await this.saveDiagram();
const {xml} = await this.modeler.saveXML({format: true}) const {xml} = await this.modeler.saveXML({format: true});
const blob = new Blob([xml], {type: 'text/xml'}); const blob = new Blob([xml], {type: 'text/xml'});
this._fileSaveAs(blob, this.insertDateIntoFileName()); fileSaver.saveAs(blob, this.insertDateIntoFileName());
} }
onImport(err?: Error | BpmnError, warnings?: BpmnWarning[]) { onImport(err?: Error | BpmnError, warnings?: BpmnWarning[]) {
@ -242,7 +241,7 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
const diagramType = getDiagramTypeFromXml(xml); const diagramType = getDiagramTypeFromXml(xml);
this.openDiagram(xml, diagramType); this.openDiagram(xml, diagramType);
}, },
error => this._handleErrors(error) error => this._handleErrors(error),
); );
} }
@ -377,9 +376,4 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
return `${this.fileName}_${dateString}.${this.diagramType}`; return `${this.fileName}_${dateString}.${this.diagramType}`;
} }
} }
private _fileSaveAs(blob: Blob, filename: string) {
fileSaver.saveAs(blob, filename);
};
} }