diff --git a/ng2-components/ng2-alfresco-viewer/README.md b/ng2-components/ng2-alfresco-viewer/README.md index b7e5f23362..98aee38f34 100644 --- a/ng2-components/ng2-alfresco-viewer/README.md +++ b/ng2-components/ng2-alfresco-viewer/README.md @@ -109,7 +109,8 @@ Attribute | Options | Default | Description | Mandatory `urlFile` | *string* | | Url where to load the file | mandatory `fileName` | *string* | Parsed from `urlFile` | Name of the file to display in the title bar. If not specified will take the last part of the URL | `overlayMode` | *boolean* | `false` | if true Show the Viewer full page over the present content | -`showViewer` | *boolean* | `true` | Hide o show the viewer | +`showViewer` | *boolean* | `true` | Hide or show the viewer | +`mimeType` | *string* | `true` | MimeType of the file, used to detect if the browser can display the content. If not supplied the component will attempt to guess based on file extension of the `urlFile` | diff --git a/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts b/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts index 4d38af0240..28a6b1a887 100644 --- a/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts +++ b/ng2-components/ng2-alfresco-viewer/src/viewer.component.spec.ts @@ -215,4 +215,71 @@ describe('ViewerComponent', () => { }); })); }); + + /* tslint:disable:max-line-length */ + describe('MimeType handling', () => { + it('should display a PDF file identified by mimetype when the filename has no extension', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + return tcb + .createAsync(ViewerComponent) + .then((fixture) => { + let component = fixture.componentInstance; + let element = fixture.nativeElement; + component.urlFile = 'content'; + component.mimeType = 'application/pdf'; + + component.ngOnChanges().then(() => { + fixture.detectChanges(); + expect(element.querySelector('pdf-viewer')).not.toBeNull(); + }); + }); + })); + + it('should display a PDF file identified by mimetype when the file extension is wrong', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + return tcb + .createAsync(ViewerComponent) + .then((fixture) => { + let component = fixture.componentInstance; + let element = fixture.nativeElement; + component.urlFile = 'content.bin'; + component.mimeType = 'application/pdf'; + + component.ngOnChanges().then(() => { + fixture.detectChanges(); + expect(element.querySelector('pdf-viewer')).not.toBeNull(); + }); + }); + })); + + it('should display an image file identified by mimetype when the filename has no extension', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + return tcb + .createAsync(ViewerComponent) + .then((fixture) => { + let component = fixture.componentInstance; + let element = fixture.nativeElement; + component.urlFile = 'content'; + component.mimeType = 'image/png'; + + component.ngOnChanges().then(() => { + fixture.detectChanges(); + expect(element.querySelector('#viewer-image')).not.toBeNull(); + }); + }); + })); + + it('should display a image file identified by mimetype when the file extension is wrong', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + return tcb + .createAsync(ViewerComponent) + .then((fixture) => { + let component = fixture.componentInstance; + let element = fixture.nativeElement; + component.urlFile = 'content.bin'; + component.mimeType = 'image/png'; + + component.ngOnChanges().then(() => { + fixture.detectChanges(); + expect(element.querySelector('#viewer-image')).not.toBeNull(); + }); + }); + })); + }); });