52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import {
|
|
formatAudioPlaybackRate,
|
|
formatAudioPlaybackRateSuffix,
|
|
getAudioDownloadExtension,
|
|
getDefaultAudioTrimRange,
|
|
getProcessedAudioTitle,
|
|
normalizeAudioPlaybackRate,
|
|
normalizeAudioTrimRange,
|
|
stepAudioPlaybackRate,
|
|
} from "../../lib/video-canvas/audio-tools";
|
|
|
|
test.describe("video canvas audio tools", () => {
|
|
test("clamps playback rate to the competitor range", () => {
|
|
expect(normalizeAudioPlaybackRate(0)).toBe(0.1);
|
|
expect(normalizeAudioPlaybackRate(9)).toBe(4);
|
|
expect(normalizeAudioPlaybackRate("2.25x")).toBe(2.25);
|
|
});
|
|
|
|
test("uses 0.1x step controls and two-decimal editor labels", () => {
|
|
expect(stepAudioPlaybackRate(1, 1)).toBe(1.1);
|
|
expect(stepAudioPlaybackRate(1, -1)).toBe(0.9);
|
|
expect(formatAudioPlaybackRate(1.1)).toBe("1.10x");
|
|
});
|
|
|
|
test("formats compact speed suffixes for result node titles", () => {
|
|
expect(formatAudioPlaybackRateSuffix(2)).toBe("2x");
|
|
expect(formatAudioPlaybackRateSuffix(1.5)).toBe("1.5x");
|
|
expect(getProcessedAudioTitle("背景音", { kind: "speed", playbackRate: 2 })).toBe(
|
|
"背景音_2x",
|
|
);
|
|
});
|
|
|
|
test("defaults trim selection to the first third of the source", () => {
|
|
expect(getDefaultAudioTrimRange(5)).toEqual({ startSeconds: 0, endSeconds: 5 / 3 });
|
|
expect(getProcessedAudioTitle("背景音", { kind: "trim", startSeconds: 0, endSeconds: 1.69 })).toBe(
|
|
"背景音_截取",
|
|
);
|
|
});
|
|
|
|
test("keeps trim handles inside the source with a nonzero range", () => {
|
|
expect(normalizeAudioTrimRange(5, -2, 9)).toEqual({ startSeconds: 0, endSeconds: 5 });
|
|
expect(normalizeAudioTrimRange(5, 4.9, 4.9)).toEqual({ startSeconds: 4.9, endSeconds: 4.95 });
|
|
});
|
|
|
|
test("keeps processed audio download extensions truthful", () => {
|
|
expect(getAudioDownloadExtension("/uploads/local/result.wav?version=1")).toBe("wav");
|
|
expect(getAudioDownloadExtension("https://example.com/source.MP3#preview")).toBe("mp3");
|
|
expect(getAudioDownloadExtension("https://example.com/audio")).toBe("mp3");
|
|
});
|
|
});
|