Skip to content

Commit 4e880e5

Browse files
brandondongstefanhaller
authored andcommitted
Add integration tests for checkout/new branch with autostash
1 parent e8e39f5 commit 4e880e5

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package branch
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var CheckoutAutostash = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Check out a branch that requires performing autostash",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.CreateFileAndAdd("file", "a\n\nb")
15+
shell.Commit("add file")
16+
shell.UpdateFileAndAdd("file", "a\n\nc")
17+
shell.Commit("edit last line")
18+
19+
shell.Checkout("HEAD^")
20+
shell.UpdateFile("file", "b\n\nb")
21+
},
22+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
23+
t.Views().Files().
24+
Lines(
25+
Contains("file"),
26+
)
27+
28+
t.Views().Branches().
29+
Focus().
30+
Lines(
31+
MatchesRegexp(`\*.*HEAD`).IsSelected(),
32+
Contains("master"),
33+
).
34+
NavigateToLine(Contains("master")).
35+
PressPrimaryAction()
36+
37+
t.ExpectPopup().Confirmation().
38+
Title(Contains("Autostash?")).
39+
Content(Contains("You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)")).
40+
Confirm()
41+
42+
t.Views().Branches().
43+
Lines(
44+
Contains("master").IsSelected(),
45+
)
46+
47+
t.Git().CurrentBranchName("master")
48+
49+
t.Views().Files().
50+
Lines(
51+
Contains("file"),
52+
)
53+
},
54+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package branch
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var NewBranchAutostash = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Create a new branch that requires performing autostash",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.CreateFileAndAdd("file", "a\n\nb")
15+
shell.Commit("add file")
16+
shell.UpdateFileAndAdd("file", "a\n\nc")
17+
shell.Commit("edit last line")
18+
19+
shell.Checkout("HEAD^")
20+
shell.UpdateFile("file", "b\n\nb")
21+
},
22+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
23+
t.Views().Files().
24+
Lines(
25+
Contains("file"),
26+
)
27+
28+
t.Views().Branches().
29+
Focus().
30+
Lines(
31+
MatchesRegexp(`\*.*HEAD`).IsSelected(),
32+
Contains("master"),
33+
).
34+
NavigateToLine(Contains("master")).
35+
Press(keys.Universal.New)
36+
37+
t.ExpectPopup().Prompt().
38+
Title(Contains("New branch name (branch is off of 'master')")).
39+
Type("new-branch").
40+
Confirm()
41+
42+
t.ExpectPopup().Confirmation().
43+
Title(Contains("Autostash?")).
44+
Content(Contains("You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)")).
45+
Confirm()
46+
47+
t.Views().Branches().
48+
Lines(
49+
Contains("new-branch").IsSelected(),
50+
Contains("master"),
51+
)
52+
53+
t.Git().CurrentBranchName("new-branch")
54+
55+
t.Views().Files().
56+
Lines(
57+
Contains("file"),
58+
)
59+
},
60+
})

pkg/integration/tests/test_list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ var tests = []*components.IntegrationTest{
3838
bisect.ChooseTerms,
3939
bisect.FromOtherBranch,
4040
bisect.Skip,
41+
branch.CheckoutAutostash,
4142
branch.CheckoutByName,
4243
branch.CreateTag,
4344
branch.Delete,
4445
branch.DeleteRemoteBranchWithCredentialPrompt,
4546
branch.DetachedHead,
47+
branch.NewBranchAutostash,
4648
branch.NewBranchFromRemoteTrackingDifferentName,
4749
branch.NewBranchFromRemoteTrackingSameName,
4850
branch.OpenPullRequestNoUpstream,

0 commit comments

Comments
 (0)