test(editor): cover whisper preferences and caption source selection

This commit is contained in:
webadderall
2026-03-23 19:22:40 +11:00
parent e8a8eae2d2
commit 409e492160
2 changed files with 71 additions and 0 deletions
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { resolveAutoCaptionSourcePath } from "./autoCaptionSource";
describe("resolveAutoCaptionSourcePath", () => {
it("prefers the video loaded in the editor over stale session state", () => {
expect(
resolveAutoCaptionSourcePath({
videoSourcePath: "/videos/current.mp4",
recordingSessionVideoPath: "/videos/stale.mp4",
currentVideoPath: "/videos/fallback.mp4",
}),
).toBe("/videos/current.mp4");
});
it("falls back to the loaded file URL when no normalized source path exists", () => {
expect(
resolveAutoCaptionSourcePath({
videoPath: "file:///Users/test/Desktop/capture.mp4",
recordingSessionVideoPath: "/videos/stale.mp4",
}),
).toBe("/Users/test/Desktop/capture.mp4");
});
it("uses session and current video fallbacks only when nothing is loaded", () => {
expect(
resolveAutoCaptionSourcePath({
recordingSessionVideoPath: "/videos/session.mp4",
currentVideoPath: "/videos/fallback.mp4",
}),
).toBe("/videos/session.mp4");
expect(
resolveAutoCaptionSourcePath({
currentVideoPath: "/videos/fallback.mp4",
}),
).toBe("/videos/fallback.mp4");
});
});
@@ -177,6 +177,23 @@ describe("editorPreferences", () => {
});
});
it("preserves custom Whisper paths from stored preferences", () => {
vi.stubGlobal(
"localStorage",
createStorageMock({
[EDITOR_PREFERENCES_STORAGE_KEY]: JSON.stringify({
whisperExecutablePath: "/usr/local/bin/whisper-cli",
whisperModelPath: "/Users/test/models/ggml-base.bin",
}),
}),
);
expect(loadEditorPreferences()).toMatchObject({
whisperExecutablePath: "/usr/local/bin/whisper-cli",
whisperModelPath: "/Users/test/models/ggml-base.bin",
});
});
it("saves all editor controls with normalization", () => {
const localStorage = createStorageMock();
vi.stubGlobal("localStorage", localStorage);
@@ -256,4 +273,19 @@ describe("editorPreferences", () => {
whisperModelPath: DEFAULT_EDITOR_PREFERENCES.whisperModelPath,
});
});
it("saves custom Whisper paths", () => {
const localStorage = createStorageMock();
vi.stubGlobal("localStorage", localStorage);
saveEditorPreferences({
whisperExecutablePath: "/opt/homebrew/bin/whisper-cli",
whisperModelPath: "/Users/test/models/ggml-small.bin",
});
expect(loadEditorPreferences()).toMatchObject({
whisperExecutablePath: "/opt/homebrew/bin/whisper-cli",
whisperModelPath: "/Users/test/models/ggml-small.bin",
});
});
});