diff --git a/lib/core/viewer/components/viewer.component.spec.ts b/lib/core/viewer/components/viewer.component.spec.ts index ad230bbdf2..27fe94af6a 100644 --- a/lib/core/viewer/components/viewer.component.spec.ts +++ b/lib/core/viewer/components/viewer.component.spec.ts @@ -592,6 +592,41 @@ describe('ViewerComponent', () => { })); }); + describe('error handling', () => { + + it('should show unknown view when node file not found', async(() => { + spyOn(alfrescoApiService.getInstance().nodes, 'getNodeInfo') + .and.returnValue(Promise.reject({})); + + component.nodeId = 'the-node-id-of-the-file-to-preview'; + component.urlFile = null; + component.mimeType = null; + + component.ngOnChanges(null); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('adf-viewer-unknown-format')).not.toBeNull(); + }); + })); + + it('should show unknown view when sharedLink file not found', async(() => { + spyOn(alfrescoApiService.getInstance().core.sharedlinksApi, 'getSharedLink') + .and.returnValue(Promise.reject({})); + + component.sharedLinkId = 'the-Shared-Link-id'; + component.urlFile = null; + component.mimeType = null; + + component.ngOnChanges(null); + fixture.whenStable().then(() => { + fixture.detectChanges(); + expect(element.querySelector('adf-viewer-unknown-format')).not.toBeNull(); + }); + + })); + + }); + describe('MimeType handling', () => { it('should display a PDF file identified by mimetype when the filename has no extension', async(() => { diff --git a/lib/core/viewer/components/viewer.component.ts b/lib/core/viewer/components/viewer.component.ts index e0f08ecd40..baecf60df6 100644 --- a/lib/core/viewer/components/viewer.component.ts +++ b/lib/core/viewer/components/viewer.component.ts @@ -298,10 +298,15 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy { ); } else if (this.sharedLinkId) { - this.apiService.sharedLinksApi.getSharedLink(this.sharedLinkId).then(details => { - this.setUpSharedLinkFile(details); - this.isLoading = false; - }); + this.apiService.sharedLinksApi.getSharedLink(this.sharedLinkId).then( + details => { + this.setUpSharedLinkFile(details); + this.isLoading = false; + }, + () => { + this.isLoading = false; + this.logService.error('This sharedLink does not exist'); + }); } } }