Spaces:
Paused
Paused
Download src/lib/components/agent/AgentSlashCommands.svelte.test.ts from Mike0021/chat-ui-agent-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/components/agent/AgentSlashCommands.svelte.test.ts
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-demo/src/lib/components/agent/AgentSlashCommands.svelte.test.ts
-
curl -L -o AgentSlashCommands.svelte.test.ts https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/components/agent/AgentSlashCommands.svelte.test.ts
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 "); | |
| }); | |
| }); | |