From dad705defc10ab7e3adac9dd9d5d341decdaa502 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 29 Dec 2024 18:05:13 +0100 Subject: [PATCH] fixup! Allow to switch branches in Commit View Add integration test --- pkg/integration/tests/commit/checkout.go | 70 ++++++++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 71 insertions(+) create mode 100644 pkg/integration/tests/commit/checkout.go diff --git a/pkg/integration/tests/commit/checkout.go b/pkg/integration/tests/commit/checkout.go new file mode 100644 index 00000000000..a08d79423ee --- /dev/null +++ b/pkg/integration/tests/commit/checkout.go @@ -0,0 +1,70 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Checkout = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Checkout a commit as a detached head, or checkout an existing branch at a commit", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.EmptyCommit("two") + shell.NewBranch("branch1") + shell.NewBranch("branch2") + shell.EmptyCommit("three") + shell.EmptyCommit("four") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("four").IsSelected(), + Contains("three"), + Contains("two"), + Contains("one"), + ). + PressPrimaryAction() + + t.ExpectPopup().Menu(). + Title(Contains("Checkout branch or commit")). + Lines( + Contains("Checkout commit as detached head").IsSelected(), + Contains("Checkout branch"), + Contains("Cancel"), + ). + Select(Contains("Checkout branch")). + Tooltip(Contains("Disabled: No branches found at selected commit.")). + Select(Contains("Checkout commit as detached head")). + Confirm() + t.Views().Branches().Lines( + Contains("* (HEAD detached at"), + Contains("branch2"), + Contains("branch1"), + Contains("master"), + ) + + t.Views().Commits(). + NavigateToLine(Contains("two")). + PressPrimaryAction() + + t.ExpectPopup().Menu(). + Title(Contains("Checkout branch or commit")). + Lines( + Contains("Checkout commit as detached head").IsSelected(), + Contains("Checkout branch").Contains("branch1"), + Contains("Checkout branch").Contains("master"), + Contains("Cancel"), + ). + Select(Contains("Checkout branch").Contains("branch1")). + Confirm() + t.Views().Branches().Lines( + Contains("branch1"), + Contains("branch2"), + Contains("master"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 782bdcb1bd6..2e33a4f4e5b 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -84,6 +84,7 @@ var tests = []*components.IntegrationTest{ commit.AddCoAuthorWhileCommitting, commit.Amend, commit.AutoWrapMessage, + commit.Checkout, commit.Commit, commit.CommitMultiline, commit.CommitSwitchToEditor,