diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index 60d652d5e2afd4d30a5a0ee17946564fd44a29bb..5eb49d4bdaa5c6c1c3c27641e355fbc8e7824532 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/internal/tui/components/chat/editor/editor_test.go @@ -23,5 +23,71 @@ func TestEditorTypingForwardSlashOpensCompletions(t *testing.T) { cmds() assert.True(t, testEditor.isCompletionsOpen) - assert.Equal(t, testEditor.textarea.Value(), "/") + assert.Equal(t, "/", testEditor.textarea.Value()) +} + +func TestEditorAutocompletionWithEmptyInput(t *testing.T) { + testEditor := newEditor(&app.App{}) + require.NotNil(t, testEditor) + + // First, give the editor focus + testEditor.Focus() + + // Simulate pressing the '/' key when the editor is empty + // This should trigger the completions to open + keyPressMsg := tea.KeyPressMsg{ + Text: "/", + } + + m, cmds := testEditor.Update(keyPressMsg) + testEditor = m.(*editorCmp) + cmds() + + // Verify completions menu is open + assert.True(t, testEditor.isCompletionsOpen) + assert.Equal(t, "/", testEditor.textarea.Value()) + + // Verify the query is empty (since we just opened it) + assert.Equal(t, "", testEditor.currentQuery) +} + +func TestEditorAutocompletionFiltering(t *testing.T) { + testEditor := newEditor(&app.App{}) + require.NotNil(t, testEditor) + + // First, open the completions menu by simulating a '/' key press + testEditor.Focus() + keyPressMsg := tea.KeyPressMsg{ + Text: "/", + } + + m, cmds := testEditor.Update(keyPressMsg) + testEditor = m.(*editorCmp) + cmds() + + // Verify completions menu is open + assert.True(t, testEditor.isCompletionsOpen) + assert.Equal(t, "/", testEditor.textarea.Value()) + + // Now simulate typing a query to filter the completions + // Set the text to "/tes" and then simulate typing "t" to make "/test" + testEditor.textarea.SetValue("/tes") + + // Simulate typing a key that would trigger filtering + keyPressMsg = tea.KeyPressMsg{ + Text: "t", + } + + m, cmds = testEditor.Update(keyPressMsg) + testEditor = m.(*editorCmp) + cmds() + + // Verify the editor still has completions open + assert.True(t, testEditor.isCompletionsOpen) + + // The currentQuery should be updated based on what we typed + // In this case, it would be "test" (the word after the initial '/') + // Note: The actual filtering is handled by the completions component, + // so we're just verifying the editor's state is correct + assert.Equal(t, "test", testEditor.currentQuery) }