[AAE-2041] [APS-1] [ADF] download process audit log not working (#5568)

* [AAE-2041] [APS-1] [ADF] download process audit log not working

* * updates JS API

* * clean up
This commit is contained in:
dhrn 2020-03-30 14:06:21 +05:30 committed by GitHub
parent 8f3f5b3879
commit 7195a384e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 48 deletions

View File

@ -17,32 +17,31 @@
import { Component } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { of, throwError } from 'rxjs';
import { ProcessService } from './../services/process.service';
import { ProcessAuditDirective } from './process-audit.directive';
import { setupTestBed, CoreModule } from '@alfresco/adf-core';
declare let jasmine: any;
import { setupTestBed, CoreModule, DownloadService } from '@alfresco/adf-core';
@Component({
selector: 'adf-basic-button',
template: `
<button id="auditButton"
adf-process-audit
[process-id]="currentProcessId"
[process-id]="1234"
[download]="download"
[fileName]="fileName"
[format]="format"
(error)="onAuditError($event)"
(clicked)="onAuditClick($event)">My button
</button>`
})
class BasicButtonComponent {
download: boolean = false;
fileName: string;
format: string;
onAuditClick() {}
onAuditError() {}
}
describe('ProcessAuditDirective', () => {
@ -68,6 +67,7 @@ describe('ProcessAuditDirective', () => {
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
return new Blob([pdfData], {type: 'application/pdf'});
}
const blob = createFakePdfBlob();
setupTestBed({
imports: [
@ -84,18 +84,13 @@ describe('ProcessAuditDirective', () => {
fixture = TestBed.createComponent(BasicButtonComponent);
component = fixture.componentInstance;
service = TestBed.get(ProcessService);
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
afterEach(() => fixture.destroy());
it('should fetch the pdf Blob when the format is pdf', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.format = 'pdf';
const blob = createFakePdfBlob();
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(of(blob));
spyOn(component, 'onAuditClick').and.callThrough();
@ -109,7 +104,40 @@ describe('ProcessAuditDirective', () => {
});
button.click();
}));
it('should download the audit in PDF format (default mode)', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.download = true;
const downloadService = TestBed.get(DownloadService);
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(of(blob));
spyOn(downloadService, 'downloadBlob').and.stub();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(downloadService.downloadBlob).toHaveBeenCalledWith(blob, 'FakeAuditName.pdf');
});
button.click();
}));
it('should throw error if download audit failed', fakeAsync(() => {
const expectedError = 'Failed to get audit';
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(throwError(expectedError));
spyOn(component, 'onAuditError').and.stub();
fixture.detectChanges();
const button = fixture.nativeElement.querySelector('#auditButton');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.onAuditError).toHaveBeenCalledWith(expectedError);
});
button.click();
}));
it('should fetch the json info when the format is json', fakeAsync(() => {
@ -145,13 +173,11 @@ describe('ProcessAuditDirective', () => {
});
button.click();
}));
it('should fetch the pdf Blob as default when the format is UNKNOW', fakeAsync(() => {
component.fileName = 'FakeAuditName';
component.format = 'fakeFormat';
const blob = createFakePdfBlob();
spyOn(service, 'fetchProcessAuditPdfById').and.returnValue(of(blob));
spyOn(component, 'onAuditClick').and.callThrough();
@ -165,6 +191,5 @@ describe('ProcessAuditDirective', () => {
});
button.click();
}));
});

View File

@ -17,7 +17,7 @@
/* tslint:disable:no-input-rename */
import { ContentService } from '@alfresco/adf-core';
import { DownloadService } from '@alfresco/adf-core';
import { Directive, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { ProcessService } from './../services/process.service';
@ -57,14 +57,11 @@ export class ProcessAuditDirective implements OnChanges {
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
public audit: any;
/**
*
* @param translateService
* @param downloadService
* @param processListService
*/
constructor(private contentService: ContentService,
constructor(private downloadService: DownloadService,
private processListService: ProcessService) {
}
@ -75,10 +72,7 @@ export class ProcessAuditDirective implements OnChanges {
}
isValidType() {
if (this.format && (this.isJsonFormat() || this.isPdfFormat())) {
return true;
}
return false;
return this.format && (this.isJsonFormat() || this.isPdfFormat());
}
setDefaultFormatType(): void {
@ -92,24 +86,16 @@ export class ProcessAuditDirective implements OnChanges {
if (this.isPdfFormat()) {
this.processListService.fetchProcessAuditPdfById(this.processId).subscribe(
(blob: Blob) => {
this.audit = blob;
if (this.download) {
this.contentService.downloadBlob(this.audit, this.fileName + '.pdf');
this.downloadService.downloadBlob(blob, this.fileName + '.pdf');
}
this.clicked.emit({ format: this.format, value: this.audit, fileName: this.fileName });
this.clicked.emit({ format: this.format, value: blob, fileName: this.fileName });
},
(err) => {
this.error.emit(err);
});
(err) => this.error.emit(err));
} else {
this.processListService.fetchProcessAuditJsonById(this.processId).subscribe(
(res) => {
this.audit = res;
this.clicked.emit({ format: this.format, value: this.audit, fileName: this.fileName });
},
(err) => {
this.error.emit(err);
});
(res) => this.clicked.emit({ format: this.format, value: res, fileName: this.fileName }),
(err) => this.error.emit(err));
}
}

18
package-lock.json generated
View File

@ -77,9 +77,9 @@
}
},
"@alfresco/js-api": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-3.7.0.tgz",
"integrity": "sha512-5bAk+RVC/VkmYHTI+LQVrOC2xqE308ns/Z4FF+FYUikhhqgB1OJIyt3vPSVP4hNSaxFsvan1owmVXMVqqCCgeA==",
"version": "3.8.0-3a40c5996640ecadb0861606ff7692210d9ec2fd",
"resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-3.8.0-3a40c5996640ecadb0861606ff7692210d9ec2fd.tgz",
"integrity": "sha512-oHW5wPMjLOgKILpDUH41eduKgpiXbydaFQDKcb7Cz7a2RdtDArExqMu2PRMwg4Dkm2Kx6PDa441aYi+8C7qo/w==",
"requires": {
"event-emitter": "^0.3.5",
"minimatch": "3.0.4",
@ -6861,9 +6861,9 @@
"dev": true
},
"formidable": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz",
"integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg=="
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz",
"integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q=="
},
"forwarded": {
"version": "0.1.2",
@ -17953,9 +17953,9 @@
"integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA=="
},
"qs": {
"version": "6.9.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.1.tgz",
"integrity": "sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA=="
"version": "6.9.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw=="
},
"readable-stream": {
"version": "3.6.0",

View File

@ -85,7 +85,7 @@
"@alfresco/adf-process-services": "3.7.0",
"@alfresco/adf-process-services-cloud": "3.7.0",
"@alfresco/adf-testing": "3.7.0",
"@alfresco/js-api": "3.7.0",
"@alfresco/js-api": "3.8.0-3a40c5996640ecadb0861606ff7692210d9ec2fd",
"@angular/animations": "^7.2.15",
"@angular/cdk": "7.3.7",
"@angular/common": "^7.2.15",