@@ -151,14 +151,179 @@ describe('TopicComponent', () => {
151151
152152 describe ( 'actionBtnClick' , ( ) => {
153153 it ( 'should call downloadFile when index 0' , ( ) => {
154- component . actionBtnClick ( { } as any , 0 ) ;
154+ component . actionBtnClick ( { url : 'https://example.com/file.pdf' } as any , 0 ) ;
155155 expect ( utilsSpy . downloadFile ) . toHaveBeenCalled ( ) ;
156156 } ) ;
157157
158- it ( 'should call previewFile when index 1' , ( ) => {
158+ it ( 'should call previewFile when index 1 and url is filestack with supported type ' , ( ) => {
159159 spyOn ( component , 'previewFile' ) ;
160- component . actionBtnClick ( { } as any , 1 ) ;
161- expect ( component . previewFile ) . toHaveBeenCalled ( ) ;
160+ const file = { url : 'https://cdn.filestackcontent.com/abc123' , name : 'doc.pdf' } ;
161+ component . actionBtnClick ( file , 1 ) ;
162+ expect ( component . previewFile ) . toHaveBeenCalledWith ( file ) ;
163+ } ) ;
164+
165+ it ( 'should open video modal when index 1 and file is mp4 video' , ( ) => {
166+ spyOn ( component , 'previewVideoFile' ) ;
167+ const file = { url : 'https://cdn.filestackcontent.com/abc123.mp4' , name : 'video.mp4' } ;
168+ component . actionBtnClick ( file , 1 ) ;
169+ expect ( component . previewVideoFile ) . toHaveBeenCalledWith ( file ) ;
170+ } ) ;
171+
172+ it ( 'should open video modal when index 1 and file is webm video' , ( ) => {
173+ spyOn ( component , 'previewVideoFile' ) ;
174+ const file = { url : 'https://cdn.filestackcontent.com/abc123.webm' , name : 'video.webm' } ;
175+ component . actionBtnClick ( file , 1 ) ;
176+ expect ( component . previewVideoFile ) . toHaveBeenCalledWith ( file ) ;
177+ } ) ;
178+
179+ it ( 'should open video modal when index 1 and file is ogg video' , ( ) => {
180+ spyOn ( component , 'previewVideoFile' ) ;
181+ const file = { url : 'https://cdn.filestackcontent.com/abc123.ogg' , name : 'video.ogg' } ;
182+ component . actionBtnClick ( file , 1 ) ;
183+ expect ( component . previewVideoFile ) . toHaveBeenCalledWith ( file ) ;
184+ } ) ;
185+
186+ it ( 'should open new tab when index 1 and url is filestack but file is audio' , ( ) => {
187+ spyOn ( window , 'open' ) ;
188+ spyOn ( component , 'previewFile' ) ;
189+ const file = { url : 'https://cdn.filestackcontent.com/abc123' , name : 'recording.mp3' } ;
190+ component . actionBtnClick ( file , 1 ) ;
191+ expect ( component . previewFile ) . not . toHaveBeenCalled ( ) ;
192+ expect ( window . open ) . toHaveBeenCalledWith ( file . url , '_blank' ) ;
193+ } ) ;
194+
195+ it ( 'should open new tab when index 1 and url is not filestack' , ( ) => {
196+ spyOn ( window , 'open' ) ;
197+ const file = { url : 'https://example.com/document.pdf' , name : 'document.pdf' } ;
198+ component . actionBtnClick ( file , 1 ) ;
199+ expect ( window . open ) . toHaveBeenCalledWith ( file . url , '_blank' ) ;
200+ expect ( notificationSpy . presentToast ) . toHaveBeenCalled ( ) ;
201+ } ) ;
202+
203+ it ( 'should open new tab for non-filestack url even without extension' , ( ) => {
204+ spyOn ( window , 'open' ) ;
205+ const file = { url : 'https://storage.example.com/files/12345' , name : 'report' } ;
206+ component . actionBtnClick ( file , 1 ) ;
207+ expect ( window . open ) . toHaveBeenCalledWith ( file . url , '_blank' ) ;
208+ } ) ;
209+ } ) ;
210+
211+ describe ( 'getFileActionIcons' , ( ) => {
212+ it ( 'should return both download and search icons for filestack url with supported type' , ( ) => {
213+ const file = { url : 'https://cdn.filestackcontent.com/abc123' , name : 'document.pdf' } ;
214+ const icons = component . getFileActionIcons ( file ) ;
215+ expect ( icons ) . toEqual ( [ 'download' , 'search' ] ) ;
216+ } ) ;
217+
218+ it ( 'should return both download and search icons for video files' , ( ) => {
219+ const file = { url : 'https://cdn.filestackcontent.com/abc123.mp4' , name : 'video.mp4' } ;
220+ const icons = component . getFileActionIcons ( file ) ;
221+ expect ( icons ) . toEqual ( [ 'download' , 'search' ] ) ;
222+ } ) ;
223+
224+ it ( 'should return both download and search icons for non-filestack video' , ( ) => {
225+ const file = { url : 'https://example.com/video.mp4' , name : 'video.mp4' } ;
226+ const icons = component . getFileActionIcons ( file ) ;
227+ expect ( icons ) . toEqual ( [ 'download' , 'search' ] ) ;
228+ } ) ;
229+
230+ it ( 'should return only download icon for filestack url with audio' , ( ) => {
231+ const file = { url : 'https://cdn.filestackcontent.com/abc123' , name : 'audio.mp3' } ;
232+ const icons = component . getFileActionIcons ( file ) ;
233+ expect ( icons ) . toEqual ( [ 'download' ] ) ;
234+ } ) ;
235+
236+ it ( 'should return only download icon for non-filestack non-video file' , ( ) => {
237+ const file = { url : 'https://example.com/file.pdf' , name : 'document.pdf' } ;
238+ const icons = component . getFileActionIcons ( file ) ;
239+ expect ( icons ) . toEqual ( [ 'download' ] ) ;
240+ } ) ;
241+
242+ it ( 'should return both download and search icons for webm video' , ( ) => {
243+ const file = { url : 'https://example.com/video.webm' , name : 'video.webm' } ;
244+ const icons = component . getFileActionIcons ( file ) ;
245+ expect ( icons ) . toEqual ( [ 'download' , 'search' ] ) ;
246+ } ) ;
247+
248+ it ( 'should return both download and search icons for ogg video' , ( ) => {
249+ const file = { url : 'https://example.com/video.ogg' , name : 'video.ogg' } ;
250+ const icons = component . getFileActionIcons ( file ) ;
251+ expect ( icons ) . toEqual ( [ 'download' , 'search' ] ) ;
252+ } ) ;
253+
254+ it ( 'should return only download icon for unsupported video formats' , ( ) => {
255+ const formats = [
256+ { url : 'https://example.com/video.mov' , name : 'video.mov' } ,
257+ { url : 'https://cdn.filestackcontent.com/abc123' , name : 'file_example_AVI_640_800kB.avi' } ,
258+ { url : 'https://cdn.filestackcontent.com/abc123.wmv' , name : 'video.wmv' } ,
259+ { url : 'https://example.com/video.mkv' , name : 'video.mkv' } ,
260+ ] ;
261+ for ( const file of formats ) {
262+ const icons = component . getFileActionIcons ( file ) ;
263+ expect ( icons ) . withContext ( file . name ) . toEqual ( [ 'download' ] ) ;
264+ }
265+ } ) ;
266+ } ) ;
267+
268+ describe ( 'previewVideoFile' , ( ) => {
269+ it ( 'should open video modal with mp4 mime type' , async ( ) => {
270+ const modalSpy = jasmine . createSpyObj ( 'Modal' , [ 'present' ] ) ;
271+ spyOn ( component [ 'modalController' ] , 'create' ) . and . returnValue ( Promise . resolve ( modalSpy ) ) ;
272+
273+ const file = { url : 'https://example.com/video.mp4' , name : 'test.mp4' } ;
274+ await component . previewVideoFile ( file ) ;
275+
276+ expect ( component [ 'modalController' ] . create ) . toHaveBeenCalledWith ( {
277+ component : jasmine . anything ( ) ,
278+ componentProps : {
279+ file : {
280+ url : file . url ,
281+ name : file . name ,
282+ type : 'video/mp4' ,
283+ } ,
284+ } ,
285+ } ) ;
286+ expect ( modalSpy . present ) . toHaveBeenCalled ( ) ;
287+ } ) ;
288+
289+ it ( 'should open video modal with webm mime type' , async ( ) => {
290+ const modalSpy = jasmine . createSpyObj ( 'Modal' , [ 'present' ] ) ;
291+ spyOn ( component [ 'modalController' ] , 'create' ) . and . returnValue ( Promise . resolve ( modalSpy ) ) ;
292+
293+ const file = { url : 'https://example.com/video.webm' , name : 'test.webm' } ;
294+ await component . previewVideoFile ( file ) ;
295+
296+ expect ( component [ 'modalController' ] . create ) . toHaveBeenCalledWith ( {
297+ component : jasmine . anything ( ) ,
298+ componentProps : {
299+ file : {
300+ url : file . url ,
301+ name : file . name ,
302+ type : 'video/webm' ,
303+ } ,
304+ } ,
305+ } ) ;
306+ expect ( modalSpy . present ) . toHaveBeenCalled ( ) ;
307+ } ) ;
308+
309+ it ( 'should open video modal with ogg mime type' , async ( ) => {
310+ const modalSpy = jasmine . createSpyObj ( 'Modal' , [ 'present' ] ) ;
311+ spyOn ( component [ 'modalController' ] , 'create' ) . and . returnValue ( Promise . resolve ( modalSpy ) ) ;
312+
313+ const file = { url : 'https://example.com/video.ogg' , name : 'test.ogg' } ;
314+ await component . previewVideoFile ( file ) ;
315+
316+ expect ( component [ 'modalController' ] . create ) . toHaveBeenCalledWith ( {
317+ component : jasmine . anything ( ) ,
318+ componentProps : {
319+ file : {
320+ url : file . url ,
321+ name : file . name ,
322+ type : 'video/ogg' ,
323+ } ,
324+ } ,
325+ } ) ;
326+ expect ( modalSpy . present ) . toHaveBeenCalled ( ) ;
162327 } ) ;
163328 } ) ;
164329} ) ;
0 commit comments