summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/retime/__tests__/resolve.test.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-25 16:47:22 +0100
committerMaze Winther <mazewinther@gmail.com>2026-03-29 15:48:22 +0200
commit8db3bead13441a5882d8689dfc6a9f09c82375d9 (patch)
treee9d0cafa93904ffcbec3188c37961bcc16c6422d /apps/web/src/lib/retime/__tests__/resolve.test.ts
parent39ea298a9ccba3104c549c0ca079c231981811f5 (diff)
downloadopencut-8db3bead13441a5882d8689dfc6a9f09c82375d9.tar.gz
feat: masks, properties refactor, shaders, storage migrations, and more
Diffstat (limited to 'apps/web/src/lib/retime/__tests__/resolve.test.ts')
-rw-r--r--apps/web/src/lib/retime/__tests__/resolve.test.ts61
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/web/src/lib/retime/__tests__/resolve.test.ts b/apps/web/src/lib/retime/__tests__/resolve.test.ts
new file mode 100644
index 00000000..4fcf6249
--- /dev/null
+++ b/apps/web/src/lib/retime/__tests__/resolve.test.ts
@@ -0,0 +1,61 @@
+import { describe, expect, test } from "bun:test";
+import {
+ getClipTimeAtSourceTime,
+ getEffectiveRateAt,
+ getSourceTimeAtClipTime,
+ getTimelineDurationForSourceSpan,
+} from "@/lib/retime";
+import type { RetimeConfig } from "@/lib/timeline";
+
+const twoX: RetimeConfig = { rate: 2 };
+const halfX: RetimeConfig = { rate: 0.5 };
+
+describe("retime resolve", () => {
+ test("maps clip time to source time at 2x speed", () => {
+ expect(getSourceTimeAtClipTime({ clipTime: 5, retime: twoX })).toBe(10);
+ });
+
+ test("maps clip time to source time at 0.5x speed", () => {
+ expect(getSourceTimeAtClipTime({ clipTime: 4, retime: halfX })).toBe(2);
+ });
+
+ test("returns clip time unchanged when no retime", () => {
+ expect(getSourceTimeAtClipTime({ clipTime: 7 })).toBe(7);
+ });
+
+ test("inverts source time back to clip time at 2x speed", () => {
+ expect(getClipTimeAtSourceTime({ sourceTime: 10, retime: twoX })).toBe(5);
+ });
+
+ test("returns effective rate", () => {
+ expect(getEffectiveRateAt({ retime: twoX })).toBe(2);
+ expect(getEffectiveRateAt({})).toBe(1);
+ });
+
+ test("derives timeline duration for a visible source span", () => {
+ expect(
+ getTimelineDurationForSourceSpan({ sourceSpan: 10, retime: twoX }),
+ ).toBe(5);
+ expect(
+ getTimelineDurationForSourceSpan({ sourceSpan: 10, retime: halfX }),
+ ).toBe(20);
+ });
+
+ test("clamps invalid rates to 1", () => {
+ expect(getSourceTimeAtClipTime({ clipTime: 5, retime: { rate: 0 } })).toBe(
+ 5,
+ );
+ expect(
+ getSourceTimeAtClipTime({ clipTime: 5, retime: { rate: -1 } }),
+ ).toBe(5);
+ });
+
+ test("caps retime rates above 5x", () => {
+ expect(getSourceTimeAtClipTime({ clipTime: 5, retime: { rate: 100 } })).toBe(
+ 25,
+ );
+ expect(
+ getTimelineDurationForSourceSpan({ sourceSpan: 10, retime: { rate: 100 } }),
+ ).toBe(2);
+ });
+});