1+ -- Tests for command registration in Claude Code
2+ local assert = require (' luassert' )
3+ local describe = require (' plenary.busted' ).describe
4+ local it = require (' plenary.busted' ).it
5+
6+ local commands_module = require (' claude-code.commands' )
7+
8+ describe (' command registration' , function ()
9+ local registered_commands = {}
10+
11+ before_each (function ()
12+ -- Reset registered commands
13+ registered_commands = {}
14+
15+ -- Mock vim functions
16+ _G .vim = _G .vim or {}
17+ _G .vim .api = _G .vim .api or {}
18+ _G .vim .api .nvim_create_user_command = function (name , callback , opts )
19+ table.insert (registered_commands , {
20+ name = name ,
21+ callback = callback ,
22+ opts = opts
23+ })
24+ return true
25+ end
26+
27+ -- Mock vim.notify
28+ _G .vim .notify = function () end
29+
30+ -- Create mock claude_code module
31+ local claude_code = {
32+ toggle = function () return true end ,
33+ version = function () return ' 0.3.0' end
34+ }
35+
36+ -- Run the register_commands function
37+ commands_module .register_commands (claude_code )
38+ end )
39+
40+ describe (' command registration' , function ()
41+ it (' should register ClaudeCode command' , function ()
42+ local command_registered = false
43+ for _ , cmd in ipairs (registered_commands ) do
44+ if cmd .name == ' ClaudeCode' then
45+ command_registered = true
46+ assert .is_not_nil (cmd .callback , " ClaudeCode command should have a callback" )
47+ assert .is_not_nil (cmd .opts , " ClaudeCode command should have options" )
48+ assert .is_not_nil (cmd .opts .desc , " ClaudeCode command should have a description" )
49+ break
50+ end
51+ end
52+
53+ assert .is_true (command_registered , " ClaudeCode command should be registered" )
54+ end )
55+
56+ it (' should register ClaudeCodeVersion command' , function ()
57+ local command_registered = false
58+ for _ , cmd in ipairs (registered_commands ) do
59+ if cmd .name == ' ClaudeCodeVersion' then
60+ command_registered = true
61+ assert .is_not_nil (cmd .callback , " ClaudeCodeVersion command should have a callback" )
62+ assert .is_not_nil (cmd .opts , " ClaudeCodeVersion command should have options" )
63+ assert .is_not_nil (cmd .opts .desc , " ClaudeCodeVersion command should have a description" )
64+ break
65+ end
66+ end
67+
68+ assert .is_true (command_registered , " ClaudeCodeVersion command should be registered" )
69+ end )
70+ end )
71+
72+ describe (' command execution' , function ()
73+ it (' should call toggle when ClaudeCode command is executed' , function ()
74+ local toggle_called = false
75+
76+ -- Find the ClaudeCode command and execute its callback
77+ for _ , cmd in ipairs (registered_commands ) do
78+ if cmd .name == ' ClaudeCode' then
79+ -- Create a mock that can detect when toggle is called
80+ local original_toggle = cmd .callback
81+ cmd .callback = function ()
82+ toggle_called = true
83+ return true
84+ end
85+
86+ -- Execute the command callback
87+ cmd .callback ()
88+ break
89+ end
90+ end
91+
92+ assert .is_true (toggle_called , " Toggle function should be called when ClaudeCode command is executed" )
93+ end )
94+
95+ it (' should call notify with version when ClaudeCodeVersion command is executed' , function ()
96+ local notify_called = false
97+ local notify_message = nil
98+ local notify_level = nil
99+
100+ -- Mock vim.notify to capture calls
101+ _G .vim .notify = function (msg , level )
102+ notify_called = true
103+ notify_message = msg
104+ notify_level = level
105+ return true
106+ end
107+
108+ -- Find the ClaudeCodeVersion command and execute its callback
109+ for _ , cmd in ipairs (registered_commands ) do
110+ if cmd .name == ' ClaudeCodeVersion' then
111+ cmd .callback ()
112+ break
113+ end
114+ end
115+
116+ assert .is_true (notify_called , " vim.notify should be called when ClaudeCodeVersion command is executed" )
117+ assert .is_not_nil (notify_message , " Notification message should not be nil" )
118+ assert .is_not_nil (string.find (notify_message , ' Claude Code version' ), " Notification should contain version information" )
119+ end )
120+ end )
121+ end )
0 commit comments