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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import { describe, expect, test } from "bun:test";
import type { Transform } from "@/rendering";
import type { SceneTracks, VideoElement } from "@/timeline";
import { applyElementUpdate } from "@/timeline/update-pipeline";
import { mediaTime, ZERO_MEDIA_TIME } from "@/wasm";
function buildTransform(): Transform {
return {
scaleX: 1,
scaleY: 1,
position: { x: 0, y: 0 },
rotate: 0,
};
}
function buildVideoElement(overrides: Partial<VideoElement> = {}): VideoElement {
return {
id: "video-1",
type: "video",
name: "Video 1",
startTime: ZERO_MEDIA_TIME,
duration: mediaTime({ ticks: 10 }),
trimStart: ZERO_MEDIA_TIME,
trimEnd: ZERO_MEDIA_TIME,
mediaId: "media-1",
params: {
"transform.positionX": 0,
"transform.positionY": 0,
"transform.scaleX": 1,
"transform.scaleY": 1,
"transform.rotate": 0,
opacity: 1,
},
...overrides,
};
}
function buildTracks(element: VideoElement): SceneTracks {
return {
overlay: [],
main: {
id: "main-track",
type: "video",
name: "Main",
muted: false,
hidden: false,
elements: [element],
},
audio: [],
};
}
describe("applyElementUpdate", () => {
test("rounds retimed durations back to integer media time", () => {
const element = buildVideoElement();
const tracks = buildTracks(element);
const updatedElement = applyElementUpdate({
element,
patch: {
retime: { rate: 1.5 },
},
context: {
tracks,
trackId: tracks.main.id,
},
});
expect(updatedElement.duration).toBe(7);
expect(Number.isInteger(updatedElement.duration)).toBe(true);
});
});
|