Files
ThothII/frontend/src/workspaces/preferences.test.ts
T

40 lines
1.3 KiB
TypeScript

import { beforeEach, expect, test } from "vitest";
import { workspacePreferences } from "./preferences";
beforeEach(() => {
localStorage.clear();
workspacePreferences.reset();
});
test("keeps selections only in current application memory", () => {
localStorage.setItem("unrelated", "keep-me");
workspacePreferences.save({
workspaceId: "research",
provider: "deepseek",
model: "deepseek-v4-pro",
thinking: "high",
});
expect(workspacePreferences.load()).toEqual({
workspaceId: "research",
provider: "deepseek",
model: "deepseek-v4-pro",
thinking: "high",
});
expect(localStorage.length).toBe(1);
expect(localStorage.getItem("unrelated")).toBe("keep-me");
expect(localStorage.getItem("thothii.workspace-registry.v1.preferences")).toBeNull();
});
test("seeds memory from backend settings once and returns defensive copies", () => {
expect(workspacePreferences.migrate({
workspaceId: "psd-clinical", provider: "zai", model: "glm-5.2", thinking: "medium",
})).toMatchObject({ workspaceId: "psd-clinical", model: "glm-5.2" });
const snapshot = workspacePreferences.load();
snapshot.workspaceId = "mutated-copy";
expect(workspacePreferences.migrate({ workspaceId: "legacy" })).toMatchObject({
workspaceId: "psd-clinical", provider: "zai", model: "glm-5.2", thinking: "medium",
});
});