jesseduffield.lazygit/pkg/integration/tests/ui/page_up_and_down.go
Stefan Haller a881fb7ee0 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>
2026-08-14 08:04:13 +02:00

48 lines
1.5 KiB
Go

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)
},
})