From a7c97400c69f641683f38fb7cf11eb8b18e11882 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 13 Jun 2024 09:57:02 +0200 Subject: Add a test demonstrating the bug After switching to another repo and then back to the original one, all keybinding suggestions in the status bar are shown twice. --- pkg/integration/components/shell.go | 6 +++ pkg/integration/tests/test_list.go | 1 + .../keybinding_suggestions_when_switching_repos.go | 45 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go (limited to 'pkg') diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index a8caff77d..01a9caf3a 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -360,6 +360,12 @@ func (self *Shell) Clone(repoName string) *Shell { return self } +func (self *Shell) CloneNonBare(repoName string) *Shell { + self.RunCommand([]string{"git", "clone", ".", "../" + repoName}) + + return self +} + func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell { self.RunCommand([]string{"git", "branch", "--set-upstream-to=" + upstream, branch}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 5fbbfb4e2..cc7fc6ca1 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -315,6 +315,7 @@ var tests = []*components.IntegrationTest{ ui.Accordion, ui.DoublePopup, ui.EmptyMenu, + ui.KeybindingSuggestionsWhenSwitchingRepos, ui.ModeSpecificKeybindingSuggestions, ui.OpenLinkFailure, ui.RangeSelect, diff --git a/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go b/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go new file mode 100644 index 000000000..2bf4e53c9 --- /dev/null +++ b/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go @@ -0,0 +1,45 @@ +package ui + +import ( + "path/filepath" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var KeybindingSuggestionsWhenSwitchingRepos = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Show correct keybinding suggestions after switching between repos", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + otherRepo, _ := filepath.Abs("../other") + config.AppState.RecentRepos = []string{otherRepo} + }, + SetupRepo: func(shell *Shell) { + shell.CloneNonBare("other") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + switchToRepo := func(repo string) { + t.GlobalPress(keys.Universal.OpenRecentRepos) + t.ExpectPopup().Menu().Title(Equals("Recent repositories")). + Lines( + Contains(repo).IsSelected(), + Contains("Cancel"), + ).Confirm() + t.Views().Status().Content(Contains(repo + " → master")) + } + + t.Views().Files().Focus() + t.Views().Options().Content( + Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: ")) + + switchToRepo("other") + switchToRepo("repo") + + t.Views().Options().Content( + /* EXPECTED: + Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: ")) + ACTUAL (all keybindings appear twice): */ + Equals("Commit: c | Stash: s | Reset: D | Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: | Keybindings: ? | Cancel: ")) + }, +}) -- cgit v1.2.3