56 lines
1.8 KiB
TypeScript
56 lines
1.8 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("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();
|
|
});
|
|
});
|