Skip to content

Commit

Permalink
fixup! Allow to switch branches in Commit View
Browse files Browse the repository at this point in the history
Add integration test
  • Loading branch information
stefanhaller committed Dec 29, 2024
1 parent c40294e commit dad705d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
70 changes: 70 additions & 0 deletions pkg/integration/tests/commit/checkout.go
Original file line number Diff line number Diff line change
@@ -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"),
)
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var tests = []*components.IntegrationTest{
commit.AddCoAuthorWhileCommitting,
commit.Amend,
commit.AutoWrapMessage,
commit.Checkout,
commit.Commit,
commit.CommitMultiline,
commit.CommitSwitchToEditor,
Expand Down

0 comments on commit dad705d

Please sign in to comment.