@@ -65,6 +65,15 @@ local function setup_test_environment()
6565 _G.original_logger_notify(msg, level, opts)
6666 end
6767 end
68+
69+ -- Stub vim.ui.input so we can simulate user input in tests
70+ vim.ui = vim.ui or {}
71+ _G.__test_next_input = nil
72+ vim.ui.input = function(opts, on_confirm)
73+ if on_confirm then
74+ on_confirm(_G.__test_next_input)
75+ end
76+ end
6877 ]] )
6978end
7079
@@ -256,6 +265,67 @@ T["EcaAddSelection"]["shows deprecation notice when called"] = function()
256265 eq (notifications [1 ].level , child .lua_get (" vim.log.levels.WARN" ))
257266end
258267
268+ T [" EcaChatAddUrl" ] = MiniTest .new_set ()
269+
270+ T [" EcaChatAddUrl" ][" command is registered" ] = function ()
271+ local commands = child .lua_get (" vim.api.nvim_get_commands({})" )
272+ eq (type (commands .EcaChatAddUrl ), " table" )
273+ eq (commands .EcaChatAddUrl .name , " EcaChatAddUrl" )
274+ end
275+
276+ T [" EcaChatAddUrl" ][" adds web context and truncates name based on config" ] = function ()
277+ -- Use a small max length to make truncation easy to assert on
278+ child .lua ([[ require('eca.config').override({
279+ windows = {
280+ input = {
281+ web_context_max_len = 10,
282+ },
283+ },
284+ })]] )
285+
286+ local long_url = " https://example.com/some/really/long/path"
287+
288+ -- Provide the URL for the stubbed vim.ui.input
289+ child .lua (string.format (" _G.__test_next_input = %q" , long_url ))
290+
291+ eq (contexts_count (), 0 )
292+
293+ child .cmd (" EcaChatAddUrl" )
294+ flush (200 )
295+
296+ local contexts = get_contexts ()
297+ eq (# contexts , 1 )
298+ eq (contexts [1 ].type , " web" )
299+ eq (contexts [1 ].data .path , long_url )
300+
301+ -- Ensure the context name shown in the input buffer is truncated
302+ child .lua ([[
303+ local eca = require('eca')
304+ local sidebar = eca.current.sidebar
305+ if not sidebar or not sidebar.containers or not sidebar.containers.input then
306+ _G.__test_displayed_context = nil
307+ return
308+ end
309+ local input = sidebar.containers.input
310+ local ns = vim.api.nvim_create_namespace('extmarks_contexts')
311+ local marks = vim.api.nvim_buf_get_extmarks(input.bufnr, ns, 0, -1, { details = true })
312+ if not marks or #marks == 0 then
313+ _G.__test_displayed_context = nil
314+ return
315+ end
316+ local details = marks[1][4]
317+ if not details or not details.virt_text or #details.virt_text == 0 then
318+ _G.__test_displayed_context = nil
319+ return
320+ end
321+ _G.__test_displayed_context = details.virt_text[1][1]
322+ ]] )
323+
324+ local displayed = child .lua_get (" _G.__test_displayed_context" )
325+ local expected = long_url :sub (1 , 7 ) .. " ... "
326+ eq (displayed , expected )
327+ end
328+
259329T [" EcaChatListContexts" ] = MiniTest .new_set ()
260330
261331T [" EcaChatListContexts" ][" command is registered" ] = function ()
0 commit comments