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

View File

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

18
package-lock.json generated
View File

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

View File

@ -85,7 +85,7 @@
"@alfresco/adf-process-services": "3.7.0", "@alfresco/adf-process-services": "3.7.0",
"@alfresco/adf-process-services-cloud": "3.7.0", "@alfresco/adf-process-services-cloud": "3.7.0",
"@alfresco/adf-testing": "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/animations": "^7.2.15",
"@angular/cdk": "7.3.7", "@angular/cdk": "7.3.7",
"@angular/common": "^7.2.15", "@angular/common": "^7.2.15",