|
| 1 | +import { EffectPresetBuilder } from "@animations/effect-preset-builder"; |
| 2 | +import { sec } from "@core/timing/types"; |
| 3 | +import type { ResolvedClip } from "@schemas"; |
| 4 | + |
| 5 | +const EDIT = { width: 1920, height: 1080 }; |
| 6 | + |
| 7 | +const build = (effect: string, clipSize = EDIT, fit: ResolvedClip["fit"] = "crop") => |
| 8 | + new EffectPresetBuilder({ |
| 9 | + id: "clip-1", |
| 10 | + asset: { type: "image", src: "https://example.com/a.png" }, |
| 11 | + start: sec(0), |
| 12 | + length: sec(5), |
| 13 | + fit, |
| 14 | + effect: effect as ResolvedClip["effect"] |
| 15 | + }).buildRelative(EDIT, clipSize); |
| 16 | + |
| 17 | +describe("EffectPresetBuilder", () => { |
| 18 | + it.each([ |
| 19 | + ["slideLeft", 0.08], |
| 20 | + ["slideLeftSlow", 0.03], |
| 21 | + ["slideLeftFast", 0.12] |
| 22 | + ])("pans %s by the render's %s of the frame, enlarged to cover it", (effect, distance) => { |
| 23 | + const { offsetXKeyframes, scaleKeyframes } = build(effect); |
| 24 | + |
| 25 | + expect(offsetXKeyframes).toEqual([{ from: distance, to: -distance, start: 0, length: 5 }]); |
| 26 | + expect(scaleKeyframes[0]).toMatchObject({ from: 1 + 2 * distance, to: 1 + 2 * distance }); |
| 27 | + }); |
| 28 | + |
| 29 | + it.each([ |
| 30 | + ["slideUp", -0.08, 0.08], |
| 31 | + ["slideDown", 0.08, -0.08] |
| 32 | + ])("pans %s the way its name says (offset y points up)", (effect, from, to) => { |
| 33 | + expect(build(effect).offsetYKeyframes).toEqual([{ from, to, start: 0, length: 5 }]); |
| 34 | + }); |
| 35 | + |
| 36 | + it("enlarges narrow media by the same amount whatever its fit", () => { |
| 37 | + const { scaleKeyframes } = build("slideLeft", { width: 1080, height: 1920 }, "contain"); |
| 38 | + |
| 39 | + expect(scaleKeyframes[0]).toMatchObject({ from: 1.16, to: 1.16 }); |
| 40 | + }); |
| 41 | + |
| 42 | + it.each(["crop", "contain"] as const)("pans the overflow of media fitted to the frame's height (%s)", fit => { |
| 43 | + const { offsetXKeyframes, scaleKeyframes } = build("slideRight", { width: 4000, height: 1000 }, fit); |
| 44 | + |
| 45 | + expect(offsetXKeyframes).toEqual([{ from: -0.625, to: 0.625, start: 0, length: 5 }]); |
| 46 | + expect(scaleKeyframes).toEqual([]); |
| 47 | + }); |
| 48 | +}); |
0 commit comments