ai-chatbot/tests/routes/video-clip-tools.test.ts

26 lines
923 B
TypeScript

import { expect, test } from "@playwright/test";
import {
DEFAULT_VIDEO_CLIP_RANGE,
getVideoClipDuration,
normalizeVideoClipRange,
snapVideoClipRatio,
} from "../../lib/video-canvas/video-clip";
test.describe("video canvas clip tools", () => {
test("defaults the clip selection to the first third", () => {
expect(normalizeVideoClipRange(undefined)).toEqual(DEFAULT_VIDEO_CLIP_RANGE);
expect(getVideoClipDuration(DEFAULT_VIDEO_CLIP_RANGE, 5)).toBeCloseTo(5 / 3, 8);
});
test("keeps clip handles ordered and inside the source", () => {
expect(normalizeVideoClipRange({ start: -2, end: 4 })).toEqual({ start: 0, end: 1 });
expect(normalizeVideoClipRange({ start: 0.8, end: 0.8 })).toEqual({ start: 0.8, end: 0.84 });
});
test("snaps drag positions to integer seconds", () => {
expect(snapVideoClipRatio(0.34, 5)).toBe(0.4);
expect(snapVideoClipRatio(0.99, 5)).toBe(1);
});
});