diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index 05d0b0c2efab8ad01eebdd460a1b0a5b402c601d..33aa432d261b19ab52d82414d922a45a3eeb4cc0 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/internal/tui/components/chat/editor/editor_test.go @@ -164,8 +164,28 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { testEditor = m.(*editorCmp) msg := cmds() - assert.NotNil(t, msg) - m, cmds = testEditor.Update(msg) + var openCompletionsMsg *completions.OpenCompletionsMsg + if batchMsg, ok := msg.(tea.BatchMsg); ok { + // Use our enhanced helper to check for OpenCompletionsMsg with specific completions + var found bool + openCompletionsMsg, found = assertBatchContainsOpenCompletionsMsg(t, batchMsg, []string{"file1.txt", "file2.txt"}) + assert.True(t, found, "Expected to find OpenCompletionsMsg with specific completions in batched messages") + } else { + t.Fatal("Expected BatchMsg from cmds()") + } + + assert.NotNil(t, openCompletionsMsg) + m, cmds = testEditor.Update(openCompletionsMsg) + + if batchMsg, ok := msg.(tea.BatchMsg); ok { + assertBatchContainsExactMessage(t, batchMsg, completions.CompletionsOpenedMsg{}) + } else { + t.Fatal("Expected BatchMsg from 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" @@ -179,6 +199,9 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { m, cmds = testEditor.Update(keyPressMsg) testEditor = m.(*editorCmp) + // 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, @@ -200,28 +223,8 @@ func TestEditorAutocompletion_SelectionOfNormalPathAddsToTextAreaClosesCompletio testEditor = m.(*editorCmp) msg := cmds() - var openCompletionsMsg *completions.OpenCompletionsMsg - if batchMsg, ok := msg.(tea.BatchMsg); ok { - // Use our enhanced helper to check for OpenCompletionsMsg with specific completions - var found bool - openCompletionsMsg, found = assertBatchContainsOpenCompletionsMsg(t, batchMsg, []string{"file1.txt", "file2.txt"}) - assert.True(t, found, "Expected to find OpenCompletionsMsg with specific completions in batched messages") - } else { - t.Fatal("Expected BatchMsg from cmds()") - } - - assert.NotNil(t, openCompletionsMsg) - m, cmds = testEditor.Update(openCompletionsMsg) - - if batchMsg, ok := msg.(tea.BatchMsg); ok { - assertBatchContainsExactMessage(t, batchMsg, completions.CompletionsOpenedMsg{}) - } else { - t.Fatal("Expected BatchMsg from cmds()") - } - - // Verify completions menu is open - assert.True(t, testEditor.isCompletionsOpen) - assert.Equal(t, "/", testEditor.textarea.Value()) + assert.NotNil(t, msg) + m, cmds = testEditor.Update(msg) // Now simulate typing a query to filter the completions // Set the text to "/tes" and then simulate typing "t" to make "/test" @@ -235,9 +238,6 @@ func TestEditorAutocompletion_SelectionOfNormalPathAddsToTextAreaClosesCompletio m, cmds = testEditor.Update(keyPressMsg) testEditor = m.(*editorCmp) - // 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,