@@ -317,6 +317,71 @@ describe('The composition', () => {
317317 expect ( composition . tracks [ 0 ] . clips [ 0 ] ) . toBeInstanceOf ( TextClip ) ;
318318 } ) ;
319319
320+ it ( 'should be able to remove tracks' , ( ) => {
321+ const track0 = composition . createTrack ( 'video' ) ;
322+ const track1 = composition . createTrack ( 'text' ) ;
323+ const track2 = composition . createTrack ( 'image' ) ;
324+
325+ expect ( composition . tracks . length ) . toBe ( 3 )
326+ expect ( composition . stage . children . length ) . toBe ( 3 ) ;
327+
328+ const detachFn = vi . fn ( ) ;
329+ composition . on ( 'detach' , detachFn ) ;
330+
331+ let res = composition . removeTrack ( track1 ) ;
332+
333+ expect ( detachFn ) . toBeCalledTimes ( 1 ) ;
334+ expect ( res ) . toBeInstanceOf ( TextTrack ) ;
335+
336+ expect ( composition . tracks . length ) . toBe ( 2 ) ;
337+ expect ( composition . stage . children . length ) . toBe ( 2 ) ;
338+ expect ( composition . tracks [ 0 ] ) . toBeInstanceOf ( ImageTrack ) ;
339+ expect ( composition . tracks [ 1 ] ) . toBeInstanceOf ( VideoTrack ) ;
340+ expect ( composition . tracks . findIndex ( ( l ) => l . id == track1 . id ) ) . toBe ( - 1 ) ;
341+ expect ( composition . stage . children . findIndex ( c => c . uid == track0 . view . uid ) ) . toBe ( 0 ) ;
342+ expect ( composition . stage . children . findIndex ( c => c . uid == track2 . view . uid ) ) . toBe ( 1 ) ;
343+
344+ // try again
345+ res = composition . removeTrack ( track1 ) ;
346+
347+ expect ( res ) . toBeUndefined ( ) ;
348+ expect ( composition . tracks . length ) . toBe ( 2 ) ;
349+ expect ( composition . stage . children . length ) . toBe ( 2 ) ;
350+ } ) ;
351+
352+ it ( 'should be able to remove clips' , async ( ) => {
353+ const track0 = composition . createTrack ( 'base' ) ;
354+ const track1 = composition . createTrack ( 'base' ) ;
355+
356+ const clip = new Clip ( { stop : 10 } ) ;
357+
358+ await track0 . add ( clip ) ;
359+ await track0 . add ( new Clip ( { stop : 20 , start : 10 } ) ) ;
360+ await track1 . add ( new Clip ( { stop : 9 } ) ) ;
361+ await track1 . add ( new Clip ( { stop : 12 , start : 9 } ) ) ;
362+
363+ expect ( track0 . clips . length ) . toBe ( 2 ) ;
364+ expect ( track1 . clips . length ) . toBe ( 2 ) ;
365+
366+ // clip that does not exist
367+ let res = composition . remove ( new Clip ( ) ) ;
368+
369+ expect ( res ) . toBe ( undefined ) ;
370+ expect ( track0 . clips . length ) . toBe ( 2 ) ;
371+ expect ( track1 . clips . length ) . toBe ( 2 ) ;
372+
373+ res = composition . remove ( clip ) ;
374+
375+ expect ( res ?. id ) . toBe ( clip . id ) ;
376+ expect ( track0 . clips . length ) . toBe ( 1 ) ;
377+ expect ( track1 . clips . length ) . toBe ( 2 ) ;
378+
379+ res = composition . remove ( clip ) ;
380+
381+ expect ( res ) . toBe ( undefined ) ;
382+ expect ( track0 . clips . length ) . toBe ( 1 ) ;
383+ expect ( track1 . clips . length ) . toBe ( 2 ) ;
384+ } ) ;
320385
321386 afterEach ( ( ) => {
322387 frameMock . mockClear ( ) ;
0 commit comments