|
| 1 | +import { describe, it, expect, vi, beforeEach } from "vitest" |
| 2 | +import { configCommand } from "../config.js" |
| 3 | +import type { CommandContext } from "../core/types.js" |
| 4 | +import openConfigFile from "../../config/openConfig.js" |
| 5 | + |
| 6 | +// Mock the openConfigFile function |
| 7 | +vi.mock("../../config/openConfig.js", () => ({ |
| 8 | + default: vi.fn(), |
| 9 | +})) |
| 10 | + |
| 11 | +describe("configCommand", () => { |
| 12 | + let mockContext: CommandContext |
| 13 | + let addMessageSpy: ReturnType<typeof vi.fn> |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + vi.clearAllMocks() |
| 17 | + addMessageSpy = vi.fn() |
| 18 | + |
| 19 | + mockContext = { |
| 20 | + input: "/config", |
| 21 | + args: [], |
| 22 | + options: {}, |
| 23 | + sendMessage: vi.fn(), |
| 24 | + addMessage: addMessageSpy, |
| 25 | + clearMessages: vi.fn(), |
| 26 | + replaceMessages: vi.fn(), |
| 27 | + clearTask: vi.fn(), |
| 28 | + setMode: vi.fn(), |
| 29 | + exit: vi.fn(), |
| 30 | + routerModels: null, |
| 31 | + currentProvider: null, |
| 32 | + kilocodeDefaultModel: "", |
| 33 | + updateProviderModel: vi.fn(), |
| 34 | + refreshRouterModels: vi.fn(), |
| 35 | + updateProvider: vi.fn(), |
| 36 | + profileData: null, |
| 37 | + balanceData: null, |
| 38 | + profileLoading: false, |
| 39 | + balanceLoading: false, |
| 40 | + } |
| 41 | + }) |
| 42 | + |
| 43 | + it("should have correct metadata", () => { |
| 44 | + expect(configCommand.name).toBe("config") |
| 45 | + expect(configCommand.aliases).toContain("c") |
| 46 | + expect(configCommand.aliases).toContain("settings") |
| 47 | + expect(configCommand.category).toBe("settings") |
| 48 | + expect(configCommand.priority).toBe(8) |
| 49 | + }) |
| 50 | + |
| 51 | + it("should open config file successfully", async () => { |
| 52 | + vi.mocked(openConfigFile).mockResolvedValue(undefined) |
| 53 | + |
| 54 | + await configCommand.handler(mockContext) |
| 55 | + |
| 56 | + expect(addMessageSpy).toHaveBeenCalledWith( |
| 57 | + expect.objectContaining({ |
| 58 | + type: "system", |
| 59 | + content: "Opening configuration file...", |
| 60 | + }), |
| 61 | + ) |
| 62 | + expect(openConfigFile).toHaveBeenCalled() |
| 63 | + }) |
| 64 | +}) |
0 commit comments