test(editor): ensure entering content post slash is being queried

tauraamui created

Change summary

internal/tui/components/chat/editor/editor_test.go | 68 +++++++++++++++
1 file changed, 67 insertions(+), 1 deletion(-)

Detailed changes

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)
 }