diff --git a/pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go b/pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go new file mode 100644 index 000000000..1219543f8 --- /dev/null +++ b/pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go @@ -0,0 +1,64 @@ +package file + +import ( + "fmt" + "strings" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var PaneShownAgainStartsAtTheTop = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "A pane that was emptied while it wasn't shown starts at the top when it comes back, rather than where it was left", + ExtraCmdArgs: []string{}, + Skip: false, + Width: 120, + Height: 30, + SetupConfig: func(cfg *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + lines := make([]string, 40) + for i := range lines { + lines[i] = fmt.Sprintf("line%02d", i+1) + } + shell.CreateFileAndAdd("file1", strings.Join(lines, "\n")+"\n") + shell.CreateFileAndAdd("file2", "one\n") + shell.Commit("one") + + // More staged changes in file1 than fit in the pane they are shown in, so that + // there is a position in it to lose, plus an unstaged change to give the file a + // second pane. + for i := range lines { + lines[i] = strings.ToUpper(lines[i]) + } + shell.UpdateFileAndAdd("file1", strings.Join(lines, "\n")+"\n") + shell.UpdateFile("file1", strings.Join(lines, "\n")+"unstaged\n") + + shell.UpdateFile("file2", "two\n") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + NavigateToLine(Contains("file1")) + + t.Views().Secondary(). + IsVisible(). + Title(Equals("Staged changes")). + ScrollWheelDown(). + ScrollWheelDown(). + OriginYAtLeast(1) + + // A file with nothing staged leaves that pane with nothing to show, so it goes + // away and is emptied. + t.Views().Files().NavigateToLine(Contains("file2")) + t.Views().Secondary().IsInvisible() + + t.Views().Files().NavigateToLine(Contains("file1")) + t.Views().Secondary(). + IsVisible(). + Content(Contains("+LINE40")). + /* EXPECTED: + OriginY(0) + ACTUAL: */ + OriginYAtLeast(1) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index ed89e9a03..946bb7884 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -253,6 +253,7 @@ var tests = []*components.IntegrationTest{ file.ExcludeWithoutInfoDir, file.Gitignore, file.GitignoreSpecialCharacters, + file.PaneShownAgainStartsAtTheTop, file.RememberCommitMessageAfterFail, file.RenameSimilarityThresholdChange, file.RenamedFiles,