66 */
77
88import { beforeEach , describe , expect , it , vi } from 'vitest' ;
9- import { ComplexTextClip , Font , MediaClip , TextClip } from '../../clips' ;
9+ import { ComplexTextClip , MediaClip , TextClip } from '../../clips' ;
1010import { Composition } from '../../composition' ;
1111import { CaptionTrack } from './caption' ;
1212import { Transcript , Word , WordGroup } from '../../models' ;
@@ -19,33 +19,6 @@ import { VerdantCaptionPreset } from './preset.verdant';
1919
2020import type { frame , hex } from '../../types' ;
2121
22- async function styleBaseClip ( clip ?: TextClip ) {
23- await clip ?. set ( {
24- fontSize : 23 ,
25- fillStyle : '#0000FF' ,
26- stroke : {
27- miterLimit : 1 ,
28- join : 'miter' ,
29- width : 10 ,
30- color : '#FF0000' ,
31- } ,
32- shadow : {
33- color : '#00FF00' ,
34- alpha : 0.5 ,
35- angle : Math . PI / 4 ,
36- blur : 32 ,
37- distance : 12 ,
38- } ,
39- font : new Font ( {
40- family : 'Komika Axis' ,
41- source : 'url(komika-axis.ttf)' ,
42- style : 'normal' ,
43- } ) ,
44- } ) ;
45-
46- await clip ?. font . load ( ) ;
47- }
48-
4922describe ( '(0) The Caption Presets' , ( ) => {
5023 const mockFn = vi . fn ( ) ;
5124 Object . assign ( document , { fonts : { add : mockFn } } ) ;
@@ -194,34 +167,10 @@ describe('(0) The Caption Presets', () => {
194167 } ) ;
195168
196169 await strategy . applyTo ( track ) ;
197- expect ( strategy . clip ) . toBeInstanceOf ( TextClip ) ;
198-
199- await styleBaseClip ( strategy . clip ) ;
200170
201171 const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
202172 expect ( loadedStrategy ) . toBeInstanceOf ( ClassicCaptionPreset ) ;
203-
204- expect ( loadedStrategy . clip ) . toBeInstanceOf ( TextClip ) ;
205- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
206173 expect ( ( loadedStrategy as any ) . generatorOptions . count ?. toString ( ) ) . toBe ( '3' ) ;
207-
208- track . clips = [ ] ;
209- expect ( track . clips . length ) . toBe ( 0 ) ;
210- await loadedStrategy . applyTo ( track ) ;
211- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( true ) ;
212- expect ( track . clips . length ) . toBeGreaterThan ( 1 ) ;
213-
214- for ( const clip of track . clips ) {
215- expect ( clip . font ?. name ) . toBe ( 'Komika Axis normal' ) ;
216- expect ( clip . font ?. family ) . toBe ( 'Komika Axis' ) ;
217- expect ( clip . fontSize ) . toBe ( 23 ) ;
218- expect ( clip . stroke ?. miterLimit ) . toBe ( 1 ) ;
219- expect ( clip . stroke ?. join ) . toBe ( 'miter' ) ;
220- expect ( clip . stroke ?. width ) . toBe ( 10 ) ;
221- expect ( clip . stroke ?. color ) . toBe ( '#FF0000' ) ;
222- expect ( clip . shadow ?. color ) . toBe ( '#00FF00' ) ;
223- expect ( clip . fillStyle ) . toBe ( '#0000FF' ) ;
224- }
225174 } ) ;
226175
227176 it ( 'should be able to be loaded from json, base strategy, harmozi strategy' , async ( ) => {
@@ -230,62 +179,20 @@ describe('(0) The Caption Presets', () => {
230179
231180 await strategy . applyTo ( track ) ;
232181
233- await styleBaseClip ( strategy . clip ) ;
234-
235182 const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
236183 expect ( loadedStrategy ) . toBeInstanceOf ( GuineaCaptionPreset ) ;
237184
238- expect ( loadedStrategy . clip ) . toBeInstanceOf ( ComplexTextClip ) ;
239- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
240185 expect ( ( loadedStrategy as any ) . colors . toString ( ) ) . toBe ( '#000000,#111111,#222222' ) ;
241-
242- track . clips = [ ] ;
243- await loadedStrategy . applyTo ( track ) ;
244- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( true ) ;
245- expect ( track . clips . length ) . toBeGreaterThan ( 1 ) ;
246-
247- for ( const clip of track . clips ) {
248- expect ( clip . font ?. name ) . toBe ( 'Komika Axis normal' ) ;
249- expect ( clip . font ?. family ) . toBe ( 'Komika Axis' ) ;
250- expect ( clip . fontSize ) . toBe ( 23 ) ;
251- expect ( clip . stroke ?. miterLimit ) . toBe ( 1 ) ;
252- expect ( clip . stroke ?. join ) . toBe ( 'miter' ) ;
253- expect ( clip . stroke ?. width ) . toBe ( 10 ) ;
254- expect ( clip . stroke ?. color ) . toBe ( '#FF0000' ) ;
255- expect ( clip . shadow ?. color ) . toBe ( '#00FF00' ) ;
256- }
257186 } ) ;
258187
259188 it ( 'should be able to be loaded from json, base strategy, highlight strategy' , async ( ) => {
260189 const color = '#ABCDEF' ;
261190 const strategy = new SpotlightCaptionPreset ( { color } ) ;
262191 await strategy . applyTo ( track ) ;
263192
264- await styleBaseClip ( strategy . clip ) ;
265-
266193 const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
267194 expect ( loadedStrategy ) . toBeInstanceOf ( SpotlightCaptionPreset ) ;
268-
269- expect ( loadedStrategy . clip ) . toBeInstanceOf ( ComplexTextClip ) ;
270- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
271195 expect ( ( loadedStrategy as any ) . color ) . toBe ( '#ABCDEF' ) ;
272-
273- track . clips = [ ] ;
274- await loadedStrategy . applyTo ( track ) ;
275- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( true ) ;
276- expect ( track . clips . length ) . toBeGreaterThan ( 1 ) ;
277-
278- for ( const clip of track . clips ) {
279- expect ( clip . font ?. name ) . toBe ( 'Komika Axis normal' ) ;
280- expect ( clip . font ?. family ) . toBe ( 'Komika Axis' ) ;
281- expect ( clip . fontSize ) . toBe ( 23 ) ;
282- expect ( clip . stroke ?. miterLimit ) . toBe ( 1 ) ;
283- expect ( clip . stroke ?. join ) . toBe ( 'miter' ) ;
284- expect ( clip . stroke ?. width ) . toBe ( 10 ) ;
285- expect ( clip . stroke ?. color ) . toBe ( '#FF0000' ) ;
286- expect ( clip . shadow ?. color ) . toBe ( '#00FF00' ) ;
287- expect ( clip . fillStyle ) . toBe ( '#0000FF' ) ;
288- }
289196 } ) ;
290197
291198 it ( 'should be able to be loaded from json, hide strategy' , async ( ) => {
@@ -295,33 +202,9 @@ describe('(0) The Caption Presets', () => {
295202 } ) ;
296203
297204 await strategy . applyTo ( track ) ;
298- expect ( strategy . clip ) . toBeInstanceOf ( TextClip ) ;
299-
300- await styleBaseClip ( strategy . clip ) ;
301205
302206 const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
303207 expect ( loadedStrategy ) . toBeInstanceOf ( CascadeCaptionPreset ) ;
304-
305- expect ( loadedStrategy . clip ) . toBeInstanceOf ( TextClip ) ;
306- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
307208 expect ( ( loadedStrategy as any ) . generatorOptions . count ?. toString ( ) ) . toBe ( '9' ) ;
308-
309- track . clips = [ ] ;
310- expect ( track . clips . length ) . toBe ( 0 ) ;
311- await loadedStrategy . applyTo ( track ) ;
312- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( true ) ;
313- expect ( track . clips . length ) . toBeGreaterThan ( 1 ) ;
314-
315- for ( const clip of track . clips ) {
316- expect ( clip . font ?. name ) . toBe ( 'Komika Axis normal' ) ;
317- expect ( clip . font ?. family ) . toBe ( 'Komika Axis' ) ;
318- expect ( clip . fontSize ) . toBe ( 23 ) ;
319- expect ( clip . stroke ?. miterLimit ) . toBe ( 1 ) ;
320- expect ( clip . stroke ?. join ) . toBe ( 'miter' ) ;
321- expect ( clip . stroke ?. width ) . toBe ( 10 ) ;
322- expect ( clip . stroke ?. color ) . toBe ( '#FF0000' ) ;
323- expect ( clip . shadow ?. color ) . toBe ( '#00FF00' ) ;
324- expect ( clip . fillStyle ) . toBe ( '#0000FF' ) ;
325- }
326209 } ) ;
327210} ) ;
0 commit comments