From 4bcb448d3fa991b852080ad6648dcd4b54bedf56 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Thu, 4 Dec 2025 12:55:30 +0000 Subject: [PATCH] test: ensure scrolling up and down remain correct post changes --- .../components/chat/editor/history_test.go | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/internal/tui/components/chat/editor/history_test.go b/internal/tui/components/chat/editor/history_test.go index ae97a85c8a9687af9f624c74337ffcb2edcef343..91a73c4233ce97ae977e64e7840f06e72a5e082f 100644 --- a/internal/tui/components/chat/editor/history_test.go +++ b/internal/tui/components/chat/editor/history_test.go @@ -15,8 +15,8 @@ func TestIntialiseHistoryWithExistingValue(t *testing.T) { h := InitialiseHistory("This is existing content in the input field", fakeHistory) - assert.Equal(t, h.ExistingValue(), "This is existing content in the input field") - assert.Equal(t, h.Value(), "This is existing content in the input field") + assert.Equal(t, "This is existing content in the input field", h.ExistingValue()) + assert.Equal(t, "This is existing content in the input field", h.Value()) } func TestIntialiseHistoryScrollUp(t *testing.T) { @@ -27,13 +27,59 @@ func TestIntialiseHistoryScrollUp(t *testing.T) { } h := InitialiseHistory("This is existing content in the input field", fakeHistory) - assert.Equal(t, h.ExistingValue(), "This is existing content in the input field") - assert.Equal(t, h.Value(), "This is existing content in the input field") + assert.Equal(t, "This is existing content in the input field", h.ExistingValue()) + assert.Equal(t, "This is existing content in the input field", h.Value()) h.ScrollUp() - assert.Equal(t, h.Value(), "3. This is the third message") + assert.Equal(t, "3. This is the third message", h.Value()) h.ScrollUp() - assert.Equal(t, h.Value(), "2. This is the second message") + assert.Equal(t, "2. This is the second message", h.Value()) h.ScrollUp() - assert.Equal(t, h.Value(), "1. This is the first message") + assert.Equal(t, "1. This is the first message", h.Value()) +} + +func TestIntialiseHistoryScrollDown(t *testing.T) { + fakeHistory := []string{ + "1. This is the first message", + "2. This is the second message", + "3. This is the third message", + } + + h := InitialiseHistory("This is existing content in the input field", fakeHistory) + assert.Equal(t, "This is existing content in the input field", h.ExistingValue()) + assert.Equal(t, "This is existing content in the input field", h.Value()) + + h.ScrollDown() + assert.Equal(t, "This is existing content in the input field", h.Value()) + h.ScrollDown() + assert.Equal(t, "This is existing content in the input field", h.Value()) + h.ScrollDown() + assert.Equal(t, "This is existing content in the input field", h.Value()) +} + +func TestIntialiseHistoryScrollUpThenDown(t *testing.T) { + fakeHistory := []string{ + "1. This is the first message", + "2. This is the second message", + "3. This is the third message", + } + + h := InitialiseHistory("This is existing content in the input field", fakeHistory) + assert.Equal(t, "This is existing content in the input field", h.ExistingValue()) + assert.Equal(t, "This is existing content in the input field", h.Value()) + + h.ScrollUp() + assert.Equal(t, "3. This is the third message", h.Value()) + h.ScrollDown() + assert.Equal(t, "This is existing content in the input field", h.Value()) + h.ScrollUp() + assert.Equal(t, "3. This is the third message", h.Value()) + h.ScrollUp() + assert.Equal(t, "2. This is the second message", h.Value()) + h.ScrollDown() + assert.Equal(t, "3. This is the third message", h.Value()) + h.ScrollDown() + assert.Equal(t, "This is existing content in the input field", h.Value()) + h.ScrollDown() + assert.Equal(t, "This is existing content in the input field", h.Value()) }