|
| 1 | +import { assertType, describe, expect, expectTypeOf, it } from "vitest"; |
| 2 | +import { test, build } from "../../src/options/videoThumbnailAnimation"; |
| 3 | +import { VideoThumbnailAnimation } from "../../src/types/videoThumbnailAnimation"; |
| 4 | +import { Options } from "../../src/types"; |
| 5 | + |
| 6 | +describe("videoThumbnailAnimation", () => { |
| 7 | + describe("test", () => { |
| 8 | + it("should return true if video_thumbnail_animation option is defined", () => { |
| 9 | + const vta: VideoThumbnailAnimation = { |
| 10 | + step: 1, |
| 11 | + delay: 100, |
| 12 | + frames: 10, |
| 13 | + frame_width: 320, |
| 14 | + frame_height: 240, |
| 15 | + }; |
| 16 | + expect(test({ video_thumbnail_animation: vta })).toEqual(true); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should return true if vta option is defined", () => { |
| 20 | + const vta: VideoThumbnailAnimation = { |
| 21 | + step: 2, |
| 22 | + delay: 200, |
| 23 | + frames: 5, |
| 24 | + frame_width: 320, |
| 25 | + frame_height: 240, |
| 26 | + }; |
| 27 | + expect(test({ vta })).toEqual(true); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should return false if video_thumbnail_animation option is undefined", () => { |
| 31 | + expect(test({})).toEqual(false); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe("build", () => { |
| 36 | + it("should throw an error if video_thumbnail_animation option is undefined", () => { |
| 37 | + expect(() => build({})).toThrow( |
| 38 | + "video_thumbnail_animation option is undefined" |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should build basic vta option with required parameters", () => { |
| 43 | + const vta: VideoThumbnailAnimation = { |
| 44 | + step: 1.5, |
| 45 | + delay: 100, |
| 46 | + frames: 10, |
| 47 | + frame_width: 320, |
| 48 | + frame_height: 240, |
| 49 | + }; |
| 50 | + expect(build({ video_thumbnail_animation: vta })).toEqual( |
| 51 | + "vta:1.5:100:10:320:240" |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should build vta option with extend_frame as boolean", () => { |
| 56 | + const vta: VideoThumbnailAnimation = { |
| 57 | + step: 1, |
| 58 | + delay: 100, |
| 59 | + frames: 10, |
| 60 | + frame_width: 320, |
| 61 | + frame_height: 240, |
| 62 | + extend_frame: true, |
| 63 | + }; |
| 64 | + expect(build({ vta })).toEqual("vta:1:100:10:320:240:t"); |
| 65 | + }); |
| 66 | + |
| 67 | + it("should build vta option with extend_frame as number", () => { |
| 68 | + const vta: VideoThumbnailAnimation = { |
| 69 | + step: 1, |
| 70 | + delay: 100, |
| 71 | + frames: 10, |
| 72 | + frame_width: 320, |
| 73 | + frame_height: 240, |
| 74 | + extend_frame: 1, |
| 75 | + }; |
| 76 | + expect(build({ vta })).toEqual("vta:1:100:10:320:240:t"); |
| 77 | + }); |
| 78 | + |
| 79 | + it("should build vta option with extend_frame as string", () => { |
| 80 | + const vta: VideoThumbnailAnimation = { |
| 81 | + step: 1, |
| 82 | + delay: 100, |
| 83 | + frames: 10, |
| 84 | + frame_width: 320, |
| 85 | + frame_height: 240, |
| 86 | + extend_frame: "t", |
| 87 | + }; |
| 88 | + expect(build({ vta })).toEqual("vta:1:100:10:320:240:t"); |
| 89 | + }); |
| 90 | + |
| 91 | + it("should build vta option with trim flag", () => { |
| 92 | + const vta: VideoThumbnailAnimation = { |
| 93 | + step: 1, |
| 94 | + delay: 100, |
| 95 | + frames: 10, |
| 96 | + frame_width: 320, |
| 97 | + frame_height: 240, |
| 98 | + trim: true, |
| 99 | + }; |
| 100 | + expect(build({ vta })).toEqual("vta:1:100:10:320:240::t"); |
| 101 | + }); |
| 102 | + |
| 103 | + it("should build vta option with fill flag", () => { |
| 104 | + const vta: VideoThumbnailAnimation = { |
| 105 | + step: 1, |
| 106 | + delay: 100, |
| 107 | + frames: 10, |
| 108 | + frame_width: 320, |
| 109 | + frame_height: 240, |
| 110 | + fill: true, |
| 111 | + }; |
| 112 | + expect(build({ vta })).toEqual("vta:1:100:10:320:240:::t"); |
| 113 | + }); |
| 114 | + |
| 115 | + it("should build vta option with focus coordinates", () => { |
| 116 | + const vta: VideoThumbnailAnimation = { |
| 117 | + step: 1, |
| 118 | + delay: 100, |
| 119 | + frames: 10, |
| 120 | + frame_width: 320, |
| 121 | + frame_height: 240, |
| 122 | + fill: true, |
| 123 | + focus_x: 0.3, |
| 124 | + focus_y: 0.7, |
| 125 | + }; |
| 126 | + expect(build({ vta })).toEqual("vta:1:100:10:320:240:::t:0.3:0.7"); |
| 127 | + }); |
| 128 | + |
| 129 | + it("should build vta option with all parameters", () => { |
| 130 | + const vta: VideoThumbnailAnimation = { |
| 131 | + step: -1, |
| 132 | + delay: 200, |
| 133 | + frames: 15, |
| 134 | + frame_width: 640, |
| 135 | + frame_height: 480, |
| 136 | + extend_frame: true, |
| 137 | + trim: true, |
| 138 | + fill: true, |
| 139 | + focus_x: 0.5, |
| 140 | + focus_y: 0.5, |
| 141 | + }; |
| 142 | + expect(build({ video_thumbnail_animation: vta })).toEqual( |
| 143 | + "vta:-1:200:15:640:480:t:t:t:0.5:0.5" |
| 144 | + ); |
| 145 | + }); |
| 146 | + }); |
| 147 | +}); |
| 148 | + |
| 149 | +describe("Check `video_thumbnail_animation` type declarations", () => { |
| 150 | + it("video_thumbnail_animation option should have correct type", () => { |
| 151 | + expectTypeOf(build).parameter(0).toEqualTypeOf<{ |
| 152 | + video_thumbnail_animation?: VideoThumbnailAnimation; |
| 153 | + vta?: VideoThumbnailAnimation; |
| 154 | + }>(); |
| 155 | + expectTypeOf(build).returns.toEqualTypeOf<string>(); |
| 156 | + }); |
| 157 | + |
| 158 | + it("check TS type declaration", () => { |
| 159 | + assertType<Options>({ |
| 160 | + video_thumbnail_animation: { |
| 161 | + step: 1, |
| 162 | + delay: 100, |
| 163 | + frames: 10, |
| 164 | + frame_width: 320, |
| 165 | + frame_height: 240, |
| 166 | + }, |
| 167 | + }); |
| 168 | + |
| 169 | + assertType<Options>({ |
| 170 | + vta: { |
| 171 | + step: 1, |
| 172 | + delay: 100, |
| 173 | + frames: 10, |
| 174 | + frame_width: 320, |
| 175 | + frame_height: 240, |
| 176 | + extend_frame: true, |
| 177 | + trim: true, |
| 178 | + fill: true, |
| 179 | + focus_x: 0.5, |
| 180 | + focus_y: 0.5, |
| 181 | + }, |
| 182 | + }); |
| 183 | + }); |
| 184 | +}); |
0 commit comments