diff --git a/internal/tui/components/chat/editor/editor_test.go b/internal/tui/components/chat/editor/editor_test.go index b5f2298f0377f4f2932a528dc68aeb1172cc561c..db03a732fb17ea3e1092d1f97f1d62e633fa47e1 100644 --- a/internal/tui/components/chat/editor/editor_test.go +++ b/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