@@ -1,6 +1,7 @@
package editor
import (
+ "context"
"testing"
"testing/fstest"
@@ -305,6 +306,36 @@ func TestEditor_OnCompletionPathToNonImageEmitsAttachFileMessage(t *testing.T) {
assert.Nil(t, cmd)
}
+// type mockSrv struct {}
+
+func TestEditor_StepForwardOverHistoryDoesNotTouchExistingInputValue(t *testing.T) {
+ mEditor := editorCmp{}
+ fakeHistory := []string{
+ "First message user sent",
+ "Second message user sent",
+ "Third message user sent",
+ "Current value in the input field",
+ }
+
+ history := func(ctx context.Context) ([]string, error) {
+ return fakeHistory, nil
+ }
+ forwardDir := func() direction {
+ return next
+ }
+ previousDir := func() direction {
+ return previous
+ }
+
+ // NOTE(tauraamui): if forward is the first direction the user goes in, the current message should be left alone/the same
+ assert.Equal(t, "Current value in the input field", mEditor.stepOverHistory(history, forwardDir))
+ assert.Equal(t, "Current value in the input field", mEditor.stepOverHistory(history, forwardDir))
+ assert.Equal(t, "Third message user sent", mEditor.stepOverHistory(history, previousDir))
+ assert.Equal(t, "Second message user sent", mEditor.stepOverHistory(history, previousDir))
+ assert.Equal(t, "First message user sent", mEditor.stepOverHistory(history, previousDir))
+ assert.Equal(t, "First message user sent", mEditor.stepOverHistory(history, previousDir))
+}
+
// TestHelperFunctions demonstrates how to use the batch message helpers
func TestHelperFunctions(t *testing.T) {
testEditor := newEditor(&app.App{}, mockDirLister([]string{"file1.txt", "file2.txt"}))