|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { |
| 3 | + GLOBAL_COMMANDS, |
| 4 | + getGlobalCommand, |
| 5 | + getGlobalCommandsForAutocomplete, |
| 6 | + type GlobalCommand, |
| 7 | + type GlobalCommandAction, |
| 8 | +} from "../globalCommands.js" |
| 9 | + |
| 10 | +describe("globalCommands", () => { |
| 11 | + describe("GLOBAL_COMMANDS", () => { |
| 12 | + it("should contain the /new command", () => { |
| 13 | + const newCommand = GLOBAL_COMMANDS.find((cmd) => cmd.name === "new") |
| 14 | + expect(newCommand).toBeDefined() |
| 15 | + expect(newCommand?.action).toBe("clearTask") |
| 16 | + expect(newCommand?.description).toBe("Start a new task") |
| 17 | + }) |
| 18 | + |
| 19 | + it("should have valid structure for all commands", () => { |
| 20 | + for (const cmd of GLOBAL_COMMANDS) { |
| 21 | + expect(cmd.name).toBeTruthy() |
| 22 | + expect(typeof cmd.name).toBe("string") |
| 23 | + expect(cmd.description).toBeTruthy() |
| 24 | + expect(typeof cmd.description).toBe("string") |
| 25 | + expect(cmd.action).toBeTruthy() |
| 26 | + expect(typeof cmd.action).toBe("string") |
| 27 | + } |
| 28 | + }) |
| 29 | + }) |
| 30 | + |
| 31 | + describe("getGlobalCommand", () => { |
| 32 | + it("should return the command when found", () => { |
| 33 | + const cmd = getGlobalCommand("new") |
| 34 | + expect(cmd).toBeDefined() |
| 35 | + expect(cmd?.name).toBe("new") |
| 36 | + expect(cmd?.action).toBe("clearTask") |
| 37 | + }) |
| 38 | + |
| 39 | + it("should return undefined for unknown commands", () => { |
| 40 | + const cmd = getGlobalCommand("unknown-command") |
| 41 | + expect(cmd).toBeUndefined() |
| 42 | + }) |
| 43 | + |
| 44 | + it("should be case-sensitive", () => { |
| 45 | + const cmd = getGlobalCommand("NEW") |
| 46 | + expect(cmd).toBeUndefined() |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + describe("getGlobalCommandsForAutocomplete", () => { |
| 51 | + it("should return commands in autocomplete format", () => { |
| 52 | + const commands = getGlobalCommandsForAutocomplete() |
| 53 | + expect(commands.length).toBe(GLOBAL_COMMANDS.length) |
| 54 | + |
| 55 | + for (const cmd of commands) { |
| 56 | + expect(cmd.name).toBeTruthy() |
| 57 | + expect(cmd.source).toBe("global") |
| 58 | + expect(cmd.action).toBeTruthy() |
| 59 | + } |
| 60 | + }) |
| 61 | + |
| 62 | + it("should include the /new command with correct format", () => { |
| 63 | + const commands = getGlobalCommandsForAutocomplete() |
| 64 | + const newCommand = commands.find((cmd) => cmd.name === "new") |
| 65 | + |
| 66 | + expect(newCommand).toBeDefined() |
| 67 | + expect(newCommand?.description).toBe("Start a new task") |
| 68 | + expect(newCommand?.source).toBe("global") |
| 69 | + expect(newCommand?.action).toBe("clearTask") |
| 70 | + }) |
| 71 | + |
| 72 | + it("should not include argumentHint for action commands", () => { |
| 73 | + const commands = getGlobalCommandsForAutocomplete() |
| 74 | + // Action commands don't have argument hints |
| 75 | + for (const cmd of commands) { |
| 76 | + expect(cmd).not.toHaveProperty("argumentHint") |
| 77 | + } |
| 78 | + }) |
| 79 | + }) |
| 80 | + |
| 81 | + describe("type safety", () => { |
| 82 | + it("should have valid GlobalCommandAction types", () => { |
| 83 | + // This test ensures the type is properly constrained |
| 84 | + const validActions: GlobalCommandAction[] = ["clearTask"] |
| 85 | + |
| 86 | + for (const cmd of GLOBAL_COMMANDS) { |
| 87 | + expect(validActions).toContain(cmd.action) |
| 88 | + } |
| 89 | + }) |
| 90 | + |
| 91 | + it("should match GlobalCommand interface", () => { |
| 92 | + const testCommand: GlobalCommand = { |
| 93 | + name: "test", |
| 94 | + description: "Test command", |
| 95 | + action: "clearTask", |
| 96 | + } |
| 97 | + |
| 98 | + expect(testCommand.name).toBe("test") |
| 99 | + expect(testCommand.description).toBe("Test command") |
| 100 | + expect(testCommand.action).toBe("clearTask") |
| 101 | + }) |
| 102 | + }) |
| 103 | +}) |
0 commit comments