import { describe, expect, it } from "vitest"; import type { EditorModsList } from "../src/ipc.js"; import { enabledModsCount, isModEnabled, toggleEnabled } from "../src/renderer/mods-model.js"; function list(enabled: string[] | null, ids: string[]): EditorModsList { return { enabled, mods: ids.map((id) => ({ id, version: "1.0.0", hooks: ["onDayStart"], loaded: true })) }; } describe("mods-model toggle logic (F1)", () => { it("a null enabled list means every known mod is enabled", () => { const l = list(null, ["a-mod", "b-mod"]); expect(isModEnabled(l, "a-mod")).toBe(true); expect(isModEnabled(l, "b-mod")).toBe(true); expect(enabledModsCount(l)).toBe(2); }); it("disabling a mod with no explicit list makes the rest explicit", () => { const l = list(null, ["a-mod", "b-mod", "c-mod"]); const next = toggleEnabled(l, "b-mod", false); expect(next).toEqual(["a-mod", "c-mod"]); const l2 = list(next, ["a-mod", "b-mod", "c-mod"]); expect(isModEnabled(l2, "b-mod")).toBe(false); expect(enabledModsCount(l2)).toBe(2); }); it("re-enabling appends the id back", () => { const l = list(["a-mod", "c-mod"], ["a-mod", "b-mod", "c-mod"]); const next = toggleEnabled(l, "b-mod", true); expect(next).toEqual(["a-mod", "c-mod", "b-mod"]); }); it("disabling with an explicit list removes only that id", () => { const l = list(["a-mod", "b-mod", "c-mod"], ["a-mod", "b-mod", "c-mod"]); expect(toggleEnabled(l, "a-mod", false)).toEqual(["b-mod", "c-mod"]); }); it("disabling the last mod yields an empty list (all disabled), never a deletion", () => { const l = list(null, ["a-mod"]); expect(toggleEnabled(l, "a-mod", false)).toEqual([]); const l2 = list([], ["a-mod"]); expect(toggleEnabled(l2, "a-mod", true)).toEqual(["a-mod"]); expect(enabledModsCount(list([], ["a-mod"]))).toBe(0); }); it("an unknown id in the enabled list is counted but never toggles others", () => { const l = list(["ghost"], ["a-mod"]); expect(enabledModsCount(l)).toBe(0); expect(isModEnabled(l, "a-mod")).toBe(false); }); });