Files
whisper_web/tests/longform-setting.test.ts
T
Lucas WintherandClaude Opus 5.5 96d100bd45 Turn "Skip silence" on by default (opt-out, D-052)
Owner's decision: the long-form pipeline's gain on the long real recording
outweighs the spec's strict every-clip rollout rule. A stored "off" still wins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 01:56:57 +01:00

62 lines
2.1 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { emptyTranscriptNotice } from "../src/lib/export";
import {
LONG_FORM_DEFAULT,
LONG_FORM_KEY,
loadLongFormChoice,
saveLongFormChoice,
} from "../src/lib/longForm";
function memoryStorage(initial: Record<string, string> = {}) {
const data = { ...initial };
return {
data,
getItem: (key: string) => data[key] ?? null,
setItem: (key: string, value: string) => {
data[key] = value;
},
};
}
describe("long-form setting persistence (D-049)", () => {
test("defaults when nothing is stored or storage is unavailable", () => {
expect(loadLongFormChoice(memoryStorage())).toBe(LONG_FORM_DEFAULT);
expect(loadLongFormChoice(null)).toBe(LONG_FORM_DEFAULT);
const throwing = {
getItem: () => {
throw new Error("denied");
},
setItem: () => {
throw new Error("denied");
},
};
expect(loadLongFormChoice(throwing)).toBe(LONG_FORM_DEFAULT);
expect(() => saveLongFormChoice(true, throwing)).not.toThrow();
});
test("is on unless the user turned it off (opt-out, D-052)", () => {
expect(LONG_FORM_DEFAULT).toBe(true);
expect(loadLongFormChoice(memoryStorage())).toBe(true);
expect(loadLongFormChoice(memoryStorage({ [LONG_FORM_KEY]: "off" }))).toBe(false);
});
test("round-trips an explicit choice", () => {
const storage = memoryStorage();
saveLongFormChoice(!LONG_FORM_DEFAULT, storage);
expect(storage.data[LONG_FORM_KEY]).toBeDefined();
expect(loadLongFormChoice(storage)).toBe(!LONG_FORM_DEFAULT);
});
});
describe("emptyTranscriptNotice (plan 001-0 Review Focus 4)", () => {
test("a finished transcript with no words says so plainly", () => {
expect(emptyTranscriptNotice({ text: "" })).toBe("No speech was found in this recording.");
expect(emptyTranscriptNotice({ text: " \n" })).toBe("No speech was found in this recording.");
});
test("no notice while running or when there is text", () => {
expect(emptyTranscriptNotice(null)).toBeNull();
expect(emptyTranscriptNotice({ text: " Hello." })).toBeNull();
});
});