diff --git a/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.spec.ts b/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.spec.ts index c1633f55b9..d0b62c27b5 100644 --- a/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.spec.ts +++ b/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.spec.ts @@ -22,12 +22,14 @@ import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService, - CoreModule + CoreModule, + ContentService } from 'ng2-alfresco-core'; describe('Test ng2-alfresco-viewer Not Supported Format View component', () => { let component: NotSupportedFormat; + let service: ContentService; let fixture: ComponentFixture; let debug: DebugElement; let element: HTMLElement; @@ -41,14 +43,15 @@ describe('Test ng2-alfresco-viewer Not Supported Format View component', () => { providers: [ AlfrescoSettingsService, AlfrescoAuthenticationService, - AlfrescoApiService + AlfrescoApiService, + ContentService ] }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(NotSupportedFormat); - + service = fixture.debugElement.injector.get(ContentService); debug = fixture.debugElement; element = fixture.nativeElement; component = fixture.componentInstance; @@ -71,11 +74,23 @@ describe('Test ng2-alfresco-viewer Not Supported Format View component', () => { describe('User Interaction', () => { it('should call download method if Click on Download button', () => { spyOn(window, 'open'); + component.urlFile = 'test'; let downloadButton: any = element.querySelector('#viewer-download-button'); downloadButton.click(); 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(); + }); }); }); diff --git a/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.ts b/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.ts index 3632c5b51c..a00bd16440 100644 --- a/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/components/notSupportedFormat.component.ts @@ -16,6 +16,7 @@ */ import { Component, Input } from '@angular/core'; +import { ContentService } from 'ng2-alfresco-core'; @Component({ selector: 'not-supported-format', @@ -30,10 +31,21 @@ export class NotSupportedFormat { @Input() urlFile: string; + @Input() + blobFile: Blob; + + constructor(private contentService: ContentService) { + + } + /** * Download file opening it in a new window */ download() { - window.open(this.urlFile); + if (this.urlFile) { + window.open(this.urlFile); + } else { + this.contentService.downloadBlob(this.blobFile, this.nameFile); + } } } diff --git a/ng2-components/ng2-alfresco-viewer/src/components/viewer.component.html b/ng2-components/ng2-alfresco-viewer/src/components/viewer.component.html index 449b9c80eb..68b2d03ef6 100644 --- a/ng2-components/ng2-alfresco-viewer/src/components/viewer.component.html +++ b/ng2-components/ng2-alfresco-viewer/src/components/viewer.component.html @@ -64,7 +64,7 @@
- +