evOo-local/packages/core/src/bot-sections.test.ts
cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

62 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { groupBotsForSidebar, reorderBotTo } from "./bot-sections.js";
const sections = [
{ id: "work", name: "Work" },
{ id: "home", name: "Home" },
];
describe("groupBotsForSidebar", () => {
it("keeps pinned bots in one top-level group without duplicating them", () => {
const groups = groupBotsForSidebar(
[
{ id: "pinned", pinned: true, sectionId: "home" },
{ id: "work", pinned: false, sectionId: "work" },
{ id: "home", pinned: false, sectionId: "home" },
{ id: "loose", pinned: false, sectionId: null },
],
sections,
);
expect(groups.map((group) => [group.title, group.bots.map((bot) => bot.id)])).toEqual([
["Pinned", ["pinned"]],
["Work", ["work"]],
["Home", ["home"]],
["Unassigned", ["loose"]],
]);
});
it("treats bots pointing at an unavailable section as unassigned", () => {
const groups = groupBotsForSidebar(
[{ id: "orphan", pinned: false, sectionId: "missing" }],
sections,
);
expect(groups).toEqual([
{
key: "unassigned",
title: "Unassigned",
bots: [{ id: "orphan", pinned: false, sectionId: "missing" }],
},
]);
});
it("does not add a heading before sections or pins exist", () => {
const groups = groupBotsForSidebar([{ id: "first", pinned: false, sectionId: null }], []);
expect(groups[0]?.title).toBeNull();
});
});
describe("reorderBotTo", () => {
const bots = [{ id: "a" }, { id: "b" }, { id: "c" }];
it("moves a bot to the target bot's position in either direction", () => {
expect(reorderBotTo(bots, "a", "c").map((bot) => bot.id)).toEqual(["b", "c", "a"]);
expect(reorderBotTo(bots, "c", "a").map((bot) => bot.id)).toEqual(["c", "a", "b"]);
});
it("leaves the list alone when either bot is missing or unchanged", () => {
expect(reorderBotTo(bots, "a", "missing")).toBe(bots);
expect(reorderBotTo(bots, "a", "a")).toBe(bots);
});
});