6
6
*/
7
7
8
8
import { beforeEach , describe , expect , it , vi } from 'vitest' ;
9
- import { ComplexTextClip , Font , MediaClip , TextClip } from '../../clips' ;
9
+ import { ComplexTextClip , MediaClip , TextClip } from '../../clips' ;
10
10
import { Composition } from '../../composition' ;
11
11
import { CaptionTrack } from './caption' ;
12
12
import { Transcript , Word , WordGroup } from '../../models' ;
@@ -19,33 +19,6 @@ import { VerdantCaptionPreset } from './preset.verdant';
19
19
20
20
import type { frame , hex } from '../../types' ;
21
21
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
-
49
22
describe ( '(0) The Caption Presets' , ( ) => {
50
23
const mockFn = vi . fn ( ) ;
51
24
Object . assign ( document , { fonts : { add : mockFn } } ) ;
@@ -194,34 +167,10 @@ describe('(0) The Caption Presets', () => {
194
167
} ) ;
195
168
196
169
await strategy . applyTo ( track ) ;
197
- expect ( strategy . clip ) . toBeInstanceOf ( TextClip ) ;
198
-
199
- await styleBaseClip ( strategy . clip ) ;
200
170
201
171
const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
202
172
expect ( loadedStrategy ) . toBeInstanceOf ( ClassicCaptionPreset ) ;
203
-
204
- expect ( loadedStrategy . clip ) . toBeInstanceOf ( TextClip ) ;
205
- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
206
173
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
- }
225
174
} ) ;
226
175
227
176
it ( 'should be able to be loaded from json, base strategy, harmozi strategy' , async ( ) => {
@@ -230,62 +179,20 @@ describe('(0) The Caption Presets', () => {
230
179
231
180
await strategy . applyTo ( track ) ;
232
181
233
- await styleBaseClip ( strategy . clip ) ;
234
-
235
182
const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
236
183
expect ( loadedStrategy ) . toBeInstanceOf ( GuineaCaptionPreset ) ;
237
184
238
- expect ( loadedStrategy . clip ) . toBeInstanceOf ( ComplexTextClip ) ;
239
- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
240
185
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
- }
257
186
} ) ;
258
187
259
188
it ( 'should be able to be loaded from json, base strategy, highlight strategy' , async ( ) => {
260
189
const color = '#ABCDEF' ;
261
190
const strategy = new SpotlightCaptionPreset ( { color } ) ;
262
191
await strategy . applyTo ( track ) ;
263
192
264
- await styleBaseClip ( strategy . clip ) ;
265
-
266
193
const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
267
194
expect ( loadedStrategy ) . toBeInstanceOf ( SpotlightCaptionPreset ) ;
268
-
269
- expect ( loadedStrategy . clip ) . toBeInstanceOf ( ComplexTextClip ) ;
270
- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
271
195
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
- }
289
196
} ) ;
290
197
291
198
it ( 'should be able to be loaded from json, hide strategy' , async ( ) => {
@@ -295,33 +202,9 @@ describe('(0) The Caption Presets', () => {
295
202
} ) ;
296
203
297
204
await strategy . applyTo ( track ) ;
298
- expect ( strategy . clip ) . toBeInstanceOf ( TextClip ) ;
299
-
300
- await styleBaseClip ( strategy . clip ) ;
301
205
302
206
const loadedStrategy = CaptionPresetDeserializer . fromJSON ( JSON . parse ( JSON . stringify ( strategy ) ) ) ;
303
207
expect ( loadedStrategy ) . toBeInstanceOf ( CascadeCaptionPreset ) ;
304
-
305
- expect ( loadedStrategy . clip ) . toBeInstanceOf ( TextClip ) ;
306
- expect ( loadedStrategy . clip ?. font ?. loaded ) . toBe ( false ) ;
307
208
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
- }
326
209
} ) ;
327
210
} ) ;
0 commit comments