File size: 1,730 Bytes
ba0ce97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 ");
	});
});