From 801e152646e498456bfccd846e440245ed6d7e64 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Mon, 15 Sep 2025 23:19:14 +0100 Subject: [PATCH] test(editor): add util/wrapped usage test --- .../tui/components/chat/editor/editor_test.go | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index 3777b484de647e0174ddef813f4860a44b261933..a03840a905bb53c238a0c5380ce5904a56702bb8 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/internal/tui/components/chat/editor/editor_test.go @@ -150,6 +150,47 @@ func TestEditorAutocompletionWithEmptyInput(t *testing.T) { assert.Equal(t, "", testEditor.currentQuery) } +func TestEditorAutoCompletion_WIP(t *testing.T) { + testEditor := newEditor(&app.App{}, mockDirLister([]string{"file1.txt", "file2.txt"})) + require.NotNil(t, testEditor) + + // open the completions menu by simulating a '/' key press + testEditor.Focus() + keyPressMsg := tea.KeyPressMsg{ + Text: "/", + } + + m, msg := simulateUpdate(testEditor, keyPressMsg) + testEditor = m.(*editorCmp) + + 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) +} + +type noopEvent struct{} + +type updater interface { + Update(msg tea.Msg) (tea.Model, tea.Cmd) +} + +func simulateUpdate(up updater, msg tea.Msg) (updater, tea.Msg) { + up, cmd := up.Update(msg) + if cmd != nil { + return up, cmd() + } + return up, noopEvent{} +} + +/* func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { testEditor := newEditor(&app.App{}, mockDirLister([]string{"file1.txt", "file2.txt"})) require.NotNil(t, testEditor) @@ -176,7 +217,7 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { assert.NotNil(t, openCompletionsMsg) m, cmds = testEditor.Update(openCompletionsMsg) - if + msg = cmds() testEditor = m.(*editorCmp) @@ -232,6 +273,7 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { // Verify the editor still has completions open assert.True(t, testEditor.isCompletionsOpen) } +*/ func TestEditorAutocompletion_SelectionOfNormalPathAddsToTextAreaClosesCompletion(t *testing.T) { testEditor := newEditor(&app.App{}, mockDirLister([]string{"example_test.go", "file1.txt", "file2.txt"}))