Add a test for paging up and down in a list

We are about to make list panels scroll their selection into view
automatically. Page up and down are one of the few places that manage
the scroll position themselves, keeping the selection at the edge of the
viewport rather than in its middle, and nothing covers that today.

Asserting on it needs an exact scroll position assertion; only
OriginYAtLeast existed so far.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-08-14 08:04:13 +02:00
co-authored by Claude Opus 5
parent 4e4cd93993
commit a881fb7ee0
3 changed files with 59 additions and 0 deletions
+11
View File
@@ -355,6 +355,17 @@ func (self *ViewDriver) SelectedLineIdxAtLeast(expected int) *ViewDriver {
return self
}
// asserts on the scroll position of the view, i.e. the index of the line that
// is shown at the top of the view.
func (self *ViewDriver) OriginY(expected int) *ViewDriver {
self.t.assertWithRetries(func() (bool, string) {
actual := self.getView().OriginY()
return expected == actual, fmt.Sprintf("%s: Expected origin Y to be %d, got %d", self.context, expected, actual)
})
return self
}
func (self *ViewDriver) OriginYAtLeast(expected int) *ViewDriver {
self.t.assertEventually(func() (bool, string) {
var actual int
+1
View File
@@ -505,6 +505,7 @@ var tests = []*components.IntegrationTest{
ui.KeybindingSuggestionsWhenSwitchingRepos,
ui.ModeSpecificKeybindingSuggestions,
ui.OpenLinkFailure,
ui.PageUpAndDown,
ui.PromoteTabToSidePanel,
ui.RangeSelect,
ui.RangeSelectWithAutoscroll,
@@ -0,0 +1,47 @@
package ui
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
const (
// The height of the commits panel in this test's window, in lines.
commitsPanelHeight = 5
// Paging keeps one line of overlap between the old and the new page.
pageDelta = commitsPanelHeight - 1
)
var PageUpAndDown = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Paging down and up keeps the selection at the edge of the viewport",
ExtraCmdArgs: []string{},
Skip: false,
Width: 120,
Height: 30,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateNCommits(40)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
SelectedLineIdx(0).
OriginY(0).
Press(keys.Universal.NextPage).
// The selection moves to the bottom of the viewport; nothing scrolls yet
SelectedLineIdx(commitsPanelHeight - 1).
OriginY(0).
Press(keys.Universal.NextPage).
// Now the view scrolls by a page, and the selection stays at the bottom
SelectedLineIdx(commitsPanelHeight - 1 + pageDelta).
OriginY(pageDelta).
Press(keys.Universal.PrevPage).
// The selection moves to the top of the viewport; nothing scrolls
SelectedLineIdx(pageDelta).
OriginY(pageDelta).
Press(keys.Universal.PrevPage).
// And back a page, with the selection staying at the top
SelectedLineIdx(0).
OriginY(0)
},
})