Files
writing-agent/tests/api-profile-usage.test.ts
T
chenmoranzhi e2413b0677 主题与字号从页面顶栏搬进设置页的「外观」,顶部导航加上预设入口。
顶栏那套汉堡菜单在每页都要单独挂载、样式也重复,收进设置页后只剩一处改;顺手把「整组都没有曾用型号」的配置组整组收起,不再留空卡片。
2026-10-26 01:09:43 +08:00

58 lines
1.6 KiB
TypeScript

import { beforeEach, describe, expect, it } from "vitest";
import {
filterUsedApiProfiles,
forgetApiProfileUsage,
loadApiProfileUsage,
recordApiProfileUsage,
} from "../web/api-profile-usage.js";
const store = new Map<string, string>();
beforeEach(() => {
store.clear();
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
value: {
getItem: (key: string) => store.get(key) ?? null,
setItem: (key: string, value: string) => {
store.set(key, value);
},
removeItem: (key: string) => {
store.delete(key);
},
},
});
});
describe("forgetApiProfileUsage", () => {
it("drops one used record and leaves the profile out of the shortcut list", () => {
recordApiProfileUsage("a");
recordApiProfileUsage("b");
expect(forgetApiProfileUsage("a")).toBe(true);
expect(loadApiProfileUsage().a).toBeUndefined();
expect(loadApiProfileUsage().b).toBeTruthy();
const visible = filterUsedApiProfiles(
[{ id: "a" }, { id: "b" }, { id: "c" }],
loadApiProfileUsage(),
"c",
);
expect(visible.map((item) => item.id)).toEqual(["b", "c"]);
});
it("does nothing when there is no record", () => {
expect(forgetApiProfileUsage("missing")).toBe(false);
});
});
describe("groups with no used model", () => {
it("shows nothing, so the settings page hides the whole group", () => {
recordApiProfileUsage("used");
const members = [{ id: "unused-a" }, { id: "unused-b" }];
expect(filterUsedApiProfiles(members, loadApiProfileUsage(), null)).toEqual(
[],
);
});
});