| import { describe, expect, it, vi } from "vitest"; |
|
|
| import { runLocalChatCommand } from "./chatCommands"; |
|
|
| describe("runLocalChatCommand", () => { |
| it("handles /reset locally and returns true", async () => { |
| const reset = vi.fn(); |
| const setToast = vi.fn(); |
| const handled = await runLocalChatCommand("/reset", { reset, setToast }); |
| expect(handled).toBe(true); |
| expect(reset).toHaveBeenCalledTimes(1); |
| expect(setToast).toHaveBeenCalledWith("Conversation reset"); |
| }); |
|
|
| it("ignores non-command input", async () => { |
| const handled = await runLocalChatCommand("hello there", { |
| reset: vi.fn(), |
| setToast: vi.fn(), |
| }); |
| expect(handled).toBe(false); |
| }); |
|
|
| it("reports unknown slash command without throwing", async () => { |
| const setToast = vi.fn(); |
| const handled = await runLocalChatCommand("/not-a-command", { |
| reset: vi.fn(), |
| setToast, |
| }); |
| expect(handled).toBe(true); |
| expect(setToast).toHaveBeenCalled(); |
| }); |
|
|
| it("does not show the reset toast when reset is cancelled", async () => { |
| const reset = vi.fn(async () => false); |
| const setToast = vi.fn(); |
| const handled = await runLocalChatCommand("/reset", { reset, setToast }); |
| expect(handled).toBe(true); |
| expect(reset).toHaveBeenCalledTimes(1); |
| expect(setToast).not.toHaveBeenCalled(); |
| }); |
| }); |
|
|