[ADF-686] add blobFile as input (#1933)

This commit is contained in:
Maurizio Vitale
2017-06-05 21:33:20 +01:00
committed by Eugenio Romano
parent 033c0f0a6b
commit 23fbc8f858
3 changed files with 32 additions and 5 deletions

View File

@@ -22,12 +22,14 @@ import {
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoApiService, AlfrescoApiService,
CoreModule CoreModule,
ContentService
} from 'ng2-alfresco-core'; } from 'ng2-alfresco-core';
describe('Test ng2-alfresco-viewer Not Supported Format View component', () => { describe('Test ng2-alfresco-viewer Not Supported Format View component', () => {
let component: NotSupportedFormat; let component: NotSupportedFormat;
let service: ContentService;
let fixture: ComponentFixture<NotSupportedFormat>; let fixture: ComponentFixture<NotSupportedFormat>;
let debug: DebugElement; let debug: DebugElement;
let element: HTMLElement; let element: HTMLElement;
@@ -41,14 +43,15 @@ describe('Test ng2-alfresco-viewer Not Supported Format View component', () => {
providers: [ providers: [
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
AlfrescoApiService AlfrescoApiService,
ContentService
] ]
}).compileComponents(); }).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(NotSupportedFormat); fixture = TestBed.createComponent(NotSupportedFormat);
service = fixture.debugElement.injector.get(ContentService);
debug = fixture.debugElement; debug = fixture.debugElement;
element = fixture.nativeElement; element = fixture.nativeElement;
component = fixture.componentInstance; component = fixture.componentInstance;
@@ -71,11 +74,23 @@ describe('Test ng2-alfresco-viewer Not Supported Format View component', () => {
describe('User Interaction', () => { describe('User Interaction', () => {
it('should call download method if Click on Download button', () => { it('should call download method if Click on Download button', () => {
spyOn(window, 'open'); spyOn(window, 'open');
component.urlFile = 'test';
let downloadButton: any = element.querySelector('#viewer-download-button'); let downloadButton: any = element.querySelector('#viewer-download-button');
downloadButton.click(); downloadButton.click();
expect(window.open).toHaveBeenCalled(); expect(window.open).toHaveBeenCalled();
}); });
it('should call content service download method if Click on Download button', () => {
spyOn(service, 'downloadBlob');
component.blobFile = new Blob();
let downloadButton: any = element.querySelector('#viewer-download-button');
downloadButton.click();
expect(service.downloadBlob).toHaveBeenCalled();
});
}); });
}); });

View File

@@ -16,6 +16,7 @@
*/ */
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { ContentService } from 'ng2-alfresco-core';
@Component({ @Component({
selector: 'not-supported-format', selector: 'not-supported-format',
@@ -30,10 +31,21 @@ export class NotSupportedFormat {
@Input() @Input()
urlFile: string; urlFile: string;
@Input()
blobFile: Blob;
constructor(private contentService: ContentService) {
}
/** /**
* Download file opening it in a new window * Download file opening it in a new window
*/ */
download() { download() {
if (this.urlFile) {
window.open(this.urlFile); window.open(this.urlFile);
} else {
this.contentService.downloadBlob(this.blobFile, this.nameFile);
}
} }
} }

View File

@@ -64,7 +64,7 @@
</span> </span>
<div *ngIf="!supportedExtension()"> <div *ngIf="!supportedExtension()">
<not-supported-format *ngIf="!extensionTemplate" [urlFile]="urlFileContent" [nameFile]="displayName"></not-supported-format> <not-supported-format *ngIf="!extensionTemplate" [urlFile]="urlFileContent" [blobFile]="blobFile" [nameFile]="displayName"></not-supported-format>
</div> </div>
<!-- End View Switch --> <!-- End View Switch -->