From c6bcc91cbddfbe80297872868136dbceaa83a1fc Mon Sep 17 00:00:00 2001 From: tauraamui Date: Mon, 15 Sep 2025 16:33:50 +0100 Subject: [PATCH] test(editor): wip fiddle with invoking returned cmds for state updates --- .../tui/components/chat/editor/editor_test.go | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index 33aa432d261b19ab52d82414d922a45a3eeb4cc0..3777b484de647e0174ddef813f4860a44b261933 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/internal/tui/components/chat/editor/editor_test.go @@ -176,6 +176,9 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { assert.NotNil(t, openCompletionsMsg) m, cmds = testEditor.Update(openCompletionsMsg) + if + msg = cmds() + testEditor = m.(*editorCmp) if batchMsg, ok := msg.(tea.BatchMsg); ok { assertBatchContainsExactMessage(t, batchMsg, completions.CompletionsOpenedMsg{}) @@ -197,6 +200,7 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { } m, cmds = testEditor.Update(keyPressMsg) + msg = cmds() testEditor = m.(*editorCmp) // Verify the editor still has completions open @@ -207,10 +211,30 @@ func TestEditorAutocompletion_StartFilteringOpens(t *testing.T) { // 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) + + keyPressMsg = tea.KeyPressMsg{ + Code: tea.KeyEnter, + } + + m, cmds = testEditor.Update(keyPressMsg) + msg = cmds() + testEditor = m.(*editorCmp) + + if batchMsg, ok := msg.(tea.BatchMsg); ok { + assertBatchContainsExactMessage(t, batchMsg, completions.CompletionsOpenedMsg{}) + } else { + t.Fatal("Expected BatchMsg from cmds()") + } + + m, cmds = testEditor.Update(msg) + msg = cmds() + testEditor = m.(*editorCmp) + // Verify the editor still has completions open + assert.True(t, testEditor.isCompletionsOpen) } func TestEditorAutocompletion_SelectionOfNormalPathAddsToTextAreaClosesCompletion(t *testing.T) { - testEditor := newEditor(&app.App{}, mockDirLister([]string{"file1.txt", "file2.txt"})) + testEditor := newEditor(&app.App{}, mockDirLister([]string{"example_test.go", "file1.txt", "file2.txt"})) require.NotNil(t, testEditor) // open the completions menu by simulating a '/' key press