test: validate error set based on direction and current state

tauraamui created

Change summary

internal/tui/components/chat/editor/editor_test.go | 51 +++++++++++++++
1 file changed, 49 insertions(+), 2 deletions(-)

Detailed changes

internal/tui/components/chat/editor/editor_test.go 🔗

@@ -306,8 +306,6 @@ func TestEditor_OnCompletionPathToNonImageEmitsAttachFileMessage(t *testing.T) {
 	assert.Nil(t, cmd)
 }
 
-// type mockSrv struct {}
-
 func TestEditor_StepForwardOverHistoryDoesNotTouchExistingInputValue(t *testing.T) {
 	mEditor := editorCmp{}
 	fakeHistory := []string{
@@ -331,9 +329,58 @@ func TestEditor_StepForwardOverHistoryDoesNotTouchExistingInputValue(t *testing.
 	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))
+}
+
+func TestEditor_StepBackwardOverHistoryScrollsUpTilBottom(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
+	}
+	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, "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))
+}
+
+func TestEditor_StepBackToBoundAndThenForward(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): current message should not be re-reachable whilst in scrolling mode
+	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))
+	assert.Equal(t, "Second message user sent", mEditor.stepOverHistory(history, forwardDir))
+	assert.Equal(t, "Third message user sent", mEditor.stepOverHistory(history, forwardDir))
+	assert.Equal(t, "Third message user sent", mEditor.stepOverHistory(history, forwardDir))
 }
 
 // TestHelperFunctions demonstrates how to use the batch message helpers