@@ -84,4 +84,102 @@ func TestEditorHandlesAutoSubmit(t *testing.T) {
8484 // It should also clear the trigger and completion word from textarea
8585 assert .Empty (t , e .textarea .Value (), "should clear the trigger and completion word" )
8686 })
87+
88+ t .Run ("@ completion inserts value even if AutoSubmit is true" , func (t * testing.T ) {
89+ t .Parallel ()
90+
91+ e := newTestEditor ("@he" , "he" )
92+ e .currentCompletion = & mockCompletion {trigger : "@" }
93+
94+ msg := completion.SelectedMsg {
95+ Value : "@hello" ,
96+ AutoSubmit : true ,
97+ }
98+
99+ _ , cmd := e .Update (msg )
100+
101+ // Command should be nil because atCompletion is true, preventing AutoSubmit behavior
102+ assert .Nil (t , cmd )
103+
104+ // Value should have trigger replaced with selected value and a space appended
105+ assert .Equal (t , "@hello " , e .textarea .Value ())
106+ })
107+
108+ t .Run ("@ completion adds file attachment" , func (t * testing.T ) {
109+ t .Parallel ()
110+
111+ e := newTestEditor ("@main.go" , "main.go" )
112+ e .currentCompletion = & mockCompletion {trigger : "@" }
113+
114+ // Use a real file that exists
115+ msg := completion.SelectedMsg {
116+ Value : "@editor.go" ,
117+ AutoSubmit : false ,
118+ }
119+
120+ _ , cmd := e .Update (msg )
121+ assert .Nil (t , cmd )
122+
123+ // Value should have trigger replaced with selected value and a space appended
124+ assert .Equal (t , "@editor.go " , e .textarea .Value ())
125+
126+ // File should be tracked as attachment
127+ require .Len (t , e .attachments , 1 )
128+ assert .Equal (t , "@editor.go" , e .attachments [0 ].placeholder )
129+ assert .False (t , e .attachments [0 ].isTemp )
130+ })
131+
132+ t .Run ("@ completion with Execute runs execute command even if AutoSubmit is false" , func (t * testing.T ) {
133+ t .Parallel ()
134+
135+ e := newTestEditor ("@he" , "he" )
136+ e .currentCompletion = & mockCompletion {trigger : "@" }
137+
138+ type testMsg struct {}
139+ msg := completion.SelectedMsg {
140+ Value : "@hello" ,
141+ AutoSubmit : false ,
142+ Execute : func () tea.Cmd {
143+ return func () tea.Msg { return testMsg {} }
144+ },
145+ }
146+
147+ _ , cmd := e .Update (msg )
148+ require .NotNil (t , cmd )
149+
150+ // Execute should return the provided command
151+ msgs := collectMsgs (cmd )
152+ require .Len (t , msgs , 1 )
153+ _ , ok := msgs [0 ].(testMsg )
154+ assert .True (t , ok , "should return the command from Execute" )
155+
156+ // It should also clear the trigger and completion word from textarea
157+ assert .Empty (t , e .textarea .Value (), "should clear the trigger and completion word" )
158+ })
159+
160+ t .Run ("@paste- completion sends message if AutoSubmit is true" , func (t * testing.T ) {
161+ t .Parallel ()
162+
163+ e := newTestEditor ("@paste" , "paste" )
164+ e .currentCompletion = & mockCompletion {trigger : "@" }
165+
166+ msg := completion.SelectedMsg {
167+ Value : "@paste-1" ,
168+ AutoSubmit : true ,
169+ }
170+
171+ _ , cmd := e .Update (msg )
172+ require .NotNil (t , cmd )
173+
174+ // Find SendMsg
175+ found := false
176+ for _ , m := range collectMsgs (cmd ) {
177+ if sm , ok := m .(messages.SendMsg ); ok {
178+ assert .Equal (t , "@paste-1" , sm .Content )
179+ found = true
180+ break
181+ }
182+ }
183+ assert .True (t , found , "should return SendMsg" )
184+ })
87185}
0 commit comments