forked from heygen-com/hyperframes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.thumbnail.test.ts
More file actions
56 lines (52 loc) · 1.88 KB
/
Copy pathvite.thumbnail.test.ts
File metadata and controls
56 lines (52 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { describe, expect, it, vi } from "vitest";
import { seekThumbnailPreview } from "./vite.thumbnail";
describe("seekThumbnailPreview", () => {
it("prefers the HyperFrames player seek path over raw timelines", async () => {
const evaluate = vi.fn(async (fn: (time: number) => string, time: number) => {
const playerSeek = vi.fn();
const timelinePause = vi.fn();
const previousWindow = globalThis.window;
vi.stubGlobal("window", {
__player: { seek: playerSeek },
__timelines: {
main: { pause: timelinePause },
nested: { pause: timelinePause },
},
});
try {
const result = fn(time);
expect(playerSeek).toHaveBeenCalledWith(10);
expect(timelinePause).not.toHaveBeenCalled();
return result;
} finally {
vi.stubGlobal("window", previousWindow);
}
});
await expect(seekThumbnailPreview({ evaluate }, 10)).resolves.toBe("player");
});
it("falls back to all registered timelines for standalone composition pages", async () => {
const evaluate = vi.fn(async (fn: (time: number) => string, time: number) => {
const firstPause = vi.fn();
const secondPause = vi.fn();
const tickerTick = vi.fn();
const previousWindow = globalThis.window;
vi.stubGlobal("window", {
__timelines: {
first: { pause: firstPause },
second: { pause: secondPause },
},
gsap: { ticker: { tick: tickerTick } },
});
try {
const result = fn(time);
expect(firstPause).toHaveBeenCalledWith(2.5);
expect(secondPause).toHaveBeenCalledWith(2.5);
expect(tickerTick).toHaveBeenCalled();
return result;
} finally {
vi.stubGlobal("window", previousWindow);
}
});
await expect(seekThumbnailPreview({ evaluate }, 2.5)).resolves.toBe("timelines");
});
});