From e8cf6f6f3877d297c4f01d911a04f6e4568c6eb8 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 21 May 2018 16:44:16 +0100 Subject: [PATCH] fix no content node display (#3351) --- .../components/viewer.component.spec.ts | 55 ++++++++++++++----- .../viewer/components/viewer.component.ts | 5 +- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/core/viewer/components/viewer.component.spec.ts b/lib/core/viewer/components/viewer.component.spec.ts index 79ceacc5ea..0d2c503a2d 100644 --- a/lib/core/viewer/components/viewer.component.spec.ts +++ b/lib/core/viewer/components/viewer.component.spec.ts @@ -41,7 +41,8 @@ import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock'; ` }) -class ViewerWithCustomToolbarComponent {} +class ViewerWithCustomToolbarComponent { +} @Component({ selector: 'adf-viewer-container-toolbar-actions', @@ -55,7 +56,8 @@ class ViewerWithCustomToolbarComponent {} ` }) -class ViewerWithCustomToolbarActionsComponent {} +class ViewerWithCustomToolbarActionsComponent { +} @Component({ selector: 'adf-viewer-container-sidebar', @@ -67,7 +69,8 @@ class ViewerWithCustomToolbarActionsComponent {} ` }) -class ViewerWithCustomSidebarComponent {} +class ViewerWithCustomSidebarComponent { +} @Component({ selector: 'adf-viewer-container-open-with', @@ -90,7 +93,8 @@ class ViewerWithCustomSidebarComponent {} ` }) -class ViewerWithCustomOpenWithComponent {} +class ViewerWithCustomOpenWithComponent { +} @Component({ selector: 'adf-viewer-container-more-actions', @@ -113,7 +117,8 @@ class ViewerWithCustomOpenWithComponent {} ` }) -class ViewerWithCustomMoreActionsComponent {} +class ViewerWithCustomMoreActionsComponent { +} describe('ViewerComponent', () => { @@ -135,11 +140,13 @@ describe('ViewerComponent', () => { ], providers: [ { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }, - {provide: RenditionsService, useValue: { + { + provide: RenditionsService, useValue: { getRendition: () => { return Observable.throw('throwed'); } - }}, + } + }, RenderingQueueServices, { provide: Location, useClass: SpyLocation } ] @@ -671,6 +678,28 @@ describe('ViewerComponent', () => { expect(element.querySelector('adf-media-player')).not.toBeNull(); }); })); + + it('should node without content show unkonwn', async(() => { + const displayName = 'the-name'; + const nodeDetails = { name: displayName, id: '12' }; + const contentUrl = '/content/url/path'; + const alfrescoApiInstanceMock = { + nodes: { getNodeInfo: () => Promise.resolve(nodeDetails) }, + content: { getContentUrl: () => contentUrl } + }; + + component.fileNodeId = '12'; + component.urlFile = null; + component.displayName = null; + spyOn(alfrescoApiService, 'getInstance').and.returnValue(alfrescoApiInstanceMock); + + component.ngOnChanges(null); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('adf-viewer-unknown-format')).toBeDefined(); + }); + })); + }); describe('Events', () => { @@ -689,7 +718,7 @@ describe('ViewerComponent', () => { describe('display name property override by urlFile', () => { - it('should displayName override the default name if is present and urlFile is set' , async(() => { + it('should displayName override the default name if is present and urlFile is set', async(() => { component.urlFile = 'base/src/assets/fake-test-file.pdf'; component.displayName = 'test name'; fixture.detectChanges(); @@ -701,7 +730,7 @@ describe('ViewerComponent', () => { }); })); - it('should use the urlFile name if displayName is NOT set and urlFile is set' , async(() => { + it('should use the urlFile name if displayName is NOT set and urlFile is set', async(() => { component.urlFile = 'base/src/assets/fake-test-file.pdf'; component.displayName = null; fixture.detectChanges(); @@ -716,9 +745,9 @@ describe('ViewerComponent', () => { describe('display name property override by blobFile', () => { - it('should displayName override the name if is present and blobFile is set' , async(() => { + it('should displayName override the name if is present and blobFile is set', async(() => { component.displayName = 'blob file display name'; - component.blobFile = new Blob(['This is my blob content'], {type : 'text/plain'}); + component.blobFile = new Blob(['This is my blob content'], { type: 'text/plain' }); fixture.detectChanges(); component.ngOnChanges(null); @@ -728,9 +757,9 @@ describe('ViewerComponent', () => { }); })); - it('should show uknownn name if displayName is NOT set and blobFile is set' , async(() => { + it('should show uknownn name if displayName is NOT set and blobFile is set', async(() => { component.displayName = null; - component.blobFile = new Blob(['This is my blob content'], {type : 'text/plain'}); + component.blobFile = new Blob(['This is my blob content'], { type: 'text/plain' }); fixture.detectChanges(); component.ngOnChanges(null); diff --git a/lib/core/viewer/components/viewer.component.ts b/lib/core/viewer/components/viewer.component.ts index 8f20870b71..768c92b6f8 100644 --- a/lib/core/viewer/components/viewer.component.ts +++ b/lib/core/viewer/components/viewer.component.ts @@ -334,7 +334,10 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy { } private setUpNodeFile(data: MinimalNodeEntryEntity) { - this.mimeType = data.content.mimeType; + if (data.content) { + this.mimeType = data.content.mimeType; + } + this.displayName = data.name; this.urlFileContent = this.apiService.contentApi.getContentUrl(data.id);