Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions projects/v3/src/app/components/topic/topic.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
15 changes: 14 additions & 1 deletion projects/v3/src/app/components/topic/topic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (this.continueAction$) {
this.continueAction$.next(topic);
Expand Down