-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_select_commands.lua
More file actions
175 lines (140 loc) · 4.89 KB
/
test_select_commands.lua
File metadata and controls
175 lines (140 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
local MiniTest = require("mini.test")
local eq = MiniTest.expect.equality
local child = MiniTest.new_child_neovim()
local function setup_test_environment()
-- Setup commands
require('eca.commands').setup()
-- Initialize everything
_G.Server = require('eca.server').new()
_G.State = require('eca.state').new()
_G.Mediator = require('eca.mediator').new(_G.Server, _G.State)
_G.Sidebar = require('eca.sidebar').new(1, _G.Mediator)
_G.Eca = require('eca')
_G.Eca.current = { sidebar = _G.Sidebar }
-- Mock vim.ui.select for testing
_G.selected_choice = nil
_G.shown_items = nil
_G.shown_prompt = nil
_G.original_select = vim.ui.select
_G.mock_select = function(choice)
_G.selected_choice = choice
vim.ui.select = function(items, opts, on_choice)
_G.shown_items = items
_G.shown_prompt = opts.prompt
on_choice(choice)
end
end
_G.restore_select = function()
vim.ui.select = _G.original_select
end
end
local T = MiniTest.new_set({
hooks = {
pre_case = function()
child.restart({ "-u", "scripts/minimal_init.lua" })
child.lua_func(setup_test_environment)
end,
post_case = function()
child.lua([[_G.restore_select()]])
end,
post_once = child.stop,
},
})
-- Test EcaChatSelectModel command
T["EcaChatSelectModel"] = MiniTest.new_set()
T["EcaChatSelectModel"]["command is registered"] = function()
local commands = child.lua_get("vim.api.nvim_get_commands({})")
eq(type(commands.EcaChatSelectModel), "table")
eq(commands.EcaChatSelectModel.name, "EcaChatSelectModel")
end
T["EcaChatSelectModel"]["updates state when model selected"] = function()
-- Setup initial state with models
child.lua([[
_G.State.config.models.list = { "model1", "model2", "model3" }
_G.State.config.models.selected = "model1"
-- Mock vim.ui.select to auto-select model2
_G.mock_select("model2")
]])
-- Execute command
child.cmd("EcaChatSelectModel")
-- Check that state was updated
eq(child.lua_get("_G.State.config.models.selected"), "model2")
end
T["EcaChatSelectModel"]["handles nil selection"] = function()
-- Setup initial state
child.lua([[
_G.State.config.models.list = { "model1", "model2" }
_G.State.config.models.selected = "model1"
-- Mock vim.ui.select to return nil (user cancelled)
_G.mock_select(nil)
]])
-- Execute command
child.cmd("EcaChatSelectModel")
-- Check that state was NOT updated (still model1)
eq(child.lua_get("_G.State.config.models.selected"), "model1")
end
T["EcaChatSelectModel"]["displays all available models"] = function()
-- Setup models list
child.lua([[
_G.State.config.models.list = { "gpt-4", "gpt-3.5-turbo", "claude-3" }
-- Mock vim.ui.select to capture the items shown
_G.mock_select(nil)
]])
-- Execute command
child.cmd("EcaChatSelectModel")
-- Verify all models were shown
local shown_items = child.lua_get("_G.shown_items")
eq(shown_items[1], "gpt-4")
eq(shown_items[2], "gpt-3.5-turbo")
eq(shown_items[3], "claude-3")
end
-- Test EcaChatSelectBehavior command
T["EcaChatSelectBehavior"] = MiniTest.new_set()
T["EcaChatSelectBehavior"]["command is registered"] = function()
local commands = child.lua_get("vim.api.nvim_get_commands({})")
eq(type(commands.EcaChatSelectBehavior), "table")
eq(commands.EcaChatSelectBehavior.name, "EcaChatSelectBehavior")
end
T["EcaChatSelectBehavior"]["updates state when behavior selected"] = function()
-- Setup initial state with behaviors
child.lua([[
_G.State.config.behaviors.list = { "helpful", "creative", "concise" }
_G.State.config.behaviors.selected = "helpful"
-- Mock vim.ui.select to auto-select creative
_G.mock_select("creative")
]])
-- Execute command
child.cmd("EcaChatSelectBehavior")
-- Check that state was updated
eq(child.lua_get("_G.State.config.behaviors.selected"), "creative")
end
T["EcaChatSelectBehavior"]["handles nil selection"] = function()
-- Setup initial state
child.lua([[
_G.State.config.behaviors.list = { "helpful", "creative" }
_G.State.config.behaviors.selected = "helpful"
-- Mock vim.ui.select to return nil (user cancelled)
_G.mock_select(nil)
]])
-- Execute command
child.cmd("EcaChatSelectBehavior")
-- Check that state was NOT updated (still helpful)
eq(child.lua_get("_G.State.config.behaviors.selected"), "helpful")
end
T["EcaChatSelectBehavior"]["displays all available behaviors"] = function()
-- Setup behaviors list
child.lua([[
_G.State.config.behaviors.list = { "helpful", "creative", "concise", "technical" }
-- Mock vim.ui.select to capture the items shown
_G.mock_select(nil)
]])
-- Execute command
child.cmd("EcaChatSelectBehavior")
-- Verify all behaviors were shown
local shown_items = child.lua_get("_G.shown_items")
eq(shown_items[1], "helpful")
eq(shown_items[2], "creative")
eq(shown_items[3], "concise")
eq(shown_items[4], "technical")
end
return T