nexus/ui/src/components/ChatSlashCommandPopover.test.tsx
Nexus Dev 8f0367d0b4 feat(22-04): slash command routing utility and ChatSlashCommandPopover
- Create ui/src/lib/slash-commands.ts with SLASH_COMMANDS (5 commands) and resolveAgentFromContent
- Create ChatSlashCommandPopover (260px, opens upward, /search greyed with Coming soon)
- Add test coverage for routing logic (slash commands, @mentions, fallback)
2026-04-04 03:55:47 +00:00

42 lines
1.5 KiB
TypeScript

// @vitest-environment jsdom
import { describe, it, expect } from "vitest";
import { SLASH_COMMANDS, resolveAgentFromContent } from "../lib/slash-commands";
describe("slash-commands", () => {
it("defines 5 slash commands", () => {
expect(SLASH_COMMANDS).toHaveLength(5);
});
it("/search is disabled", () => {
const search = SLASH_COMMANDS.find((c) => c.command === "/search");
expect(search?.disabled).toBe(true);
});
it("resolveAgentFromContent routes /ask-pm to pm agent", () => {
const agents = [
{ id: "a1", name: "PM", role: "pm" },
{ id: "a2", name: "Eng", role: "engineer" },
];
expect(resolveAgentFromContent("/ask-pm hello", agents, null)).toBe("a1");
});
it("resolveAgentFromContent routes @mention to matching agent", () => {
const agents = [
{ id: "a1", name: "PM Agent", role: "pm" },
{ id: "a2", name: "Engineer", role: "engineer" },
];
expect(resolveAgentFromContent("Hey @engineer help", agents, null)).toBe("a2");
});
it("resolveAgentFromContent returns activeAgentId when no match", () => {
const agents = [{ id: "a1", name: "PM", role: "pm" }];
expect(resolveAgentFromContent("just a message", agents, "fallback-id")).toBe("fallback-id");
});
});
describe("ChatSlashCommandPopover", () => {
it("exports ChatSlashCommandPopover component", async () => {
const mod = await import("./ChatSlashCommandPopover");
expect(mod.ChatSlashCommandPopover).toBeDefined();
});
});