diff --git a/projects/v3/src/app/components/topic/topic.component.spec.ts b/projects/v3/src/app/components/topic/topic.component.spec.ts index 14a66447f..b4bcfa9ec 100644 --- a/projects/v3/src/app/components/topic/topic.component.spec.ts +++ b/projects/v3/src/app/components/topic/topic.component.spec.ts @@ -151,14 +151,30 @@ describe('TopicComponent', () => { describe('actionBtnClick', () => { it('should call downloadFile when index 0', () => { - component.actionBtnClick({} as any, 0); + component.actionBtnClick({ url: 'https://example.com/file.pdf' } as any, 0); expect(utilsSpy.downloadFile).toHaveBeenCalled(); }); - it('should call previewFile when index 1', () => { + it('should call previewFile when index 1 and url is filestack', () => { spyOn(component, 'previewFile'); - component.actionBtnClick({} as any, 1); - expect(component.previewFile).toHaveBeenCalled(); + const file = { url: 'https://cdn.filestackcontent.com/abc123', name: 'doc.pdf' }; + component.actionBtnClick(file, 1); + expect(component.previewFile).toHaveBeenCalledWith(file); + }); + + it('should open new tab when index 1 and url is not filestack', () => { + spyOn(window, 'open'); + const file = { url: 'https://example.com/video.mp4', name: 'video.mp4' }; + component.actionBtnClick(file, 1); + expect(window.open).toHaveBeenCalledWith(file.url, '_blank'); + expect(notificationSpy.presentToast).toHaveBeenCalled(); + }); + + it('should open new tab for non-filestack url even without extension', () => { + spyOn(window, 'open'); + const file = { url: 'https://storage.example.com/files/12345', name: 'report' }; + component.actionBtnClick(file, 1); + expect(window.open).toHaveBeenCalledWith(file.url, '_blank'); }); }); }); diff --git a/projects/v3/src/app/components/topic/topic.component.ts b/projects/v3/src/app/components/topic/topic.component.ts index 1311f72ca..343b10ade 100644 --- a/projects/v3/src/app/components/topic/topic.component.ts +++ b/projects/v3/src/app/components/topic/topic.component.ts @@ -304,11 +304,24 @@ export class TopicComponent implements OnInit, OnChanges, AfterViewChecked, OnDe this.utils.downloadFile(file.url); break; case 1: - this.previewFile(file); + if (this._isFilestackUrl(file.url)) { + this.previewFile(file); + } else { + // non-filestack files: open in new tab as download fallback + this.notification.presentToast('Preview not available. Opening file in a new tab.'); + window.open(file.url, '_blank'); + } break; } } + /** + * @description checks if a url is a filestack cdn url + */ + private _isFilestackUrl(url: string): boolean { + return url?.includes('filestackcontent') || false; + } + async actionBarContinue(topic): Promise { if (this.continueAction$) { this.continueAction$.next(topic);