chat-ui-agent-demo / src /lib /components /agent /AgentSlashCommands.svelte.test.ts
Mike0021's picture
Deploy verified chat and coding agent UX
ba0ce97 verified
Raw History Blame Contribute Delete
1.73 kB
import { page } from "@vitest/browser/context";
import { render } from "vitest-browser-svelte";
import { describe, expect, it, vi } from "vitest";
import AgentSlashCommands from "./AgentSlashCommands.svelte";
import {
agentSlashCommandDraft,
filterAgentCommands,
getAgentSlashCommandQuery,
type AgentCommand,
} from "./contextTypes";
const commands: AgentCommand[] = [
{
name: "review",
description: "Review current changes",
source: "skill",
sourceLabel: "Skill",
},
{
name: "/build",
description: "Compile this project",
source: "extension",
sourceLabel: "Project",
},
];
describe("AgentSlashCommands", () => {
it("exposes an accessible command list and selects without executing", async () => {
const onselect = vi.fn();
render(AgentSlashCommands, { commands, activeIndex: 1, onselect });
await expect
.element(page.getByRole("listbox", { name: "Agent slash commands" }))
.toBeInTheDocument();
await expect
.element(page.getByRole("option", { name: /build/i }))
.toHaveAttribute("aria-selected", "true");
await page.getByRole("option", { name: /review/i }).click();
expect(onselect).toHaveBeenCalledWith(commands[0]);
});
it("discovers only a leading slash token and formats selection as a draft", () => {
expect(getAgentSlashCommandQuery("/")).toBe("");
expect(getAgentSlashCommandQuery("/REV")).toBe("rev");
expect(getAgentSlashCommandQuery("please /review")).toBeUndefined();
expect(getAgentSlashCommandQuery("/review now")).toBeUndefined();
expect(filterAgentCommands(commands, "rev")).toEqual([commands[0]]);
expect(filterAgentCommands(commands, "compile")).toEqual([commands[1]]);
expect(agentSlashCommandDraft(commands[1])).toBe("/build ");
});
});