1import { describe, expect, it } from "vite-plus/test";
2
3import { prepareVideoFirstFrame } from "./videoFirstFrame";
4
5type PreviewVideo = Parameters<typeof prepareVideoFirstFrame>[0];
6
7function previewVideo(overrides: Partial<PreviewVideo> = {}): PreviewVideo {
8 return {
9 autoplay: false,
10 paused: true,
11 seeking: false,
12 currentTime: 0,
13 duration: 5,
14 played: { length: 0, start: () => 0, end: () => 0 },
15 src: "https://environment.test/api/assets/signed/video.mp4?signature=example",
16 ...overrides,
17 };
18}
19
20describe("prepareVideoFirstFrame", () => {
21 it.each([
22 ["video.mp4#t=0,4", 0],
23 ["video.mp4#xywh=0,0,100,100&%74=3", 0],
24 ["video%23t=3.mp4", 0.1],
25 ])(
26 "distinguishes temporal fragments from encoded filename hashes: %s",
27 (path, expectedPosition) => {
28 const video = previewVideo({ src: `https://environment.test/${path}` });
29
30 prepareVideoFirstFrame(video);
31
32 expect(video.currentTime).toBe(expectedPosition);
33 },
34 );
35});