From 916437afc275eb4b8382f0c998e4d801626aa99e Mon Sep 17 00:00:00 2001 From: tauraamui Date: Wed, 17 Sep 2025 11:51:50 +0100 Subject: [PATCH] test(editor): ensure image and non image results in correct response --- .../tui/components/chat/editor/editor_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index ca9c26755226e8bcb6161523588a101bc5c4047d..11db160ae08426a3c70e6035ff4921f811eab07d 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/internal/tui/components/chat/editor/editor_test.go @@ -226,6 +226,54 @@ func TestEditorAutoCompletion_OnNonImageFileFullPathInsertedFromQuery(t *testing assert.Equal(t, "./root/project/random.txt", testEditor.textarea.Value()) } +func TestEditor_OnCompletionPathToImageEmitsAttachFileMessage(t *testing.T) { + entriesForAutoComplete := mockDirLister([]string{"image.png", "random.txt"}) + fsys := fstest.MapFS{ + "auto_completed_image.png": { + Data: pngMagicNumberData, + }, + "random.txt": { + Data: []byte("Some content"), + }, + } + testEditor := newEditor(&app.App{}, entriesForAutoComplete) + model, cmd := onCompletionItemSelect(fsys, FileCompletionItem{Path: "auto_completed_image.png"}, true, testEditor) + testEditor = model.(*editorCmp) + + require.NotNil(t, cmd) + msg := cmd() + assert.NotNil(t, msg) + + var attachmentMsg message.Attachment + if fpickedMsg, ok := msg.(filepicker.FilePickedMsg); ok { + attachmentMsg = fpickedMsg.Attachment + } + + assert.Equal(t, message.Attachment{ + FilePath: "auto_completed_image.png", + FileName: "auto_completed_image.png", + MimeType: "image/png", + Content: pngMagicNumberData, + }, attachmentMsg) +} + +func TestEditor_OnCompletionPathToNonImageEmitsAttachFileMessage(t *testing.T) { + entriesForAutoComplete := mockDirLister([]string{"image.png", "random.txt"}) + fsys := fstest.MapFS{ + "auto_completed_image.png": { + Data: pngMagicNumberData, + }, + "random.txt": { + Data: []byte("Some content"), + }, + } + testEditor := newEditor(&app.App{}, entriesForAutoComplete) + model, cmd := onCompletionItemSelect(fsys, FileCompletionItem{Path: "random.txt"}, true, testEditor) + testEditor = model.(*editorCmp) + + assert.Nil(t, cmd) +} + func TestEditor_OnPastePathToImageEmitsAttachFileMessage(t *testing.T) { entriesForAutoComplete := mockDirLister([]string{"image.png", "random.txt"}) fsys := fstest.MapFS{