From eb21d014a68561afe07b1b500d63444dbf861428 Mon Sep 17 00:00:00 2001 From: trtshen Date: Fri, 6 Feb 2026 18:13:22 +0800 Subject: [PATCH] [CORE-8137] preview compatibility --- .../components/topic/topic.component.spec.ts | 24 +++++++++++++++---- .../app/components/topic/topic.component.ts | 15 +++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) 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 c254ad6b1..734aaa53a 100644 --- a/projects/v3/src/app/components/topic/topic.component.ts +++ b/projects/v3/src/app/components/topic/topic.component.ts @@ -299,11 +299,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);