From 4e880e56c40ceef5b5d809fb9c6db6b18622024e Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 31 Aug 2024 14:27:40 -0700 Subject: [PATCH] Add integration tests for checkout/new branch with autostash --- .../tests/branch/checkout_autostash.go | 54 +++++++++++++++++ .../tests/branch/new_branch_autostash.go | 60 +++++++++++++++++++ pkg/integration/tests/test_list.go | 2 + 3 files changed, 116 insertions(+) create mode 100644 pkg/integration/tests/branch/checkout_autostash.go create mode 100644 pkg/integration/tests/branch/new_branch_autostash.go diff --git a/pkg/integration/tests/branch/checkout_autostash.go b/pkg/integration/tests/branch/checkout_autostash.go new file mode 100644 index 000000000..1256b3332 --- /dev/null +++ b/pkg/integration/tests/branch/checkout_autostash.go @@ -0,0 +1,54 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var CheckoutAutostash = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Check out a branch that requires performing autostash", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file", "a\n\nb") + shell.Commit("add file") + shell.UpdateFileAndAdd("file", "a\n\nc") + shell.Commit("edit last line") + + shell.Checkout("HEAD^") + shell.UpdateFile("file", "b\n\nb") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + Lines( + Contains("file"), + ) + + t.Views().Branches(). + Focus(). + Lines( + MatchesRegexp(`\*.*HEAD`).IsSelected(), + Contains("master"), + ). + NavigateToLine(Contains("master")). + PressPrimaryAction() + + t.ExpectPopup().Confirmation(). + Title(Contains("Autostash?")). + Content(Contains("You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)")). + Confirm() + + t.Views().Branches(). + Lines( + Contains("master").IsSelected(), + ) + + t.Git().CurrentBranchName("master") + + t.Views().Files(). + Lines( + Contains("file"), + ) + }, +}) diff --git a/pkg/integration/tests/branch/new_branch_autostash.go b/pkg/integration/tests/branch/new_branch_autostash.go new file mode 100644 index 000000000..c20088a04 --- /dev/null +++ b/pkg/integration/tests/branch/new_branch_autostash.go @@ -0,0 +1,60 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var NewBranchAutostash = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Create a new branch that requires performing autostash", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file", "a\n\nb") + shell.Commit("add file") + shell.UpdateFileAndAdd("file", "a\n\nc") + shell.Commit("edit last line") + + shell.Checkout("HEAD^") + shell.UpdateFile("file", "b\n\nb") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + Lines( + Contains("file"), + ) + + t.Views().Branches(). + Focus(). + Lines( + MatchesRegexp(`\*.*HEAD`).IsSelected(), + Contains("master"), + ). + NavigateToLine(Contains("master")). + Press(keys.Universal.New) + + t.ExpectPopup().Prompt(). + Title(Contains("New branch name (branch is off of 'master')")). + Type("new-branch"). + Confirm() + + t.ExpectPopup().Confirmation(). + Title(Contains("Autostash?")). + Content(Contains("You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)")). + Confirm() + + t.Views().Branches(). + Lines( + Contains("new-branch").IsSelected(), + Contains("master"), + ) + + t.Git().CurrentBranchName("new-branch") + + t.Views().Files(). + Lines( + Contains("file"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 268420648..dfc016a3a 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -38,11 +38,13 @@ var tests = []*components.IntegrationTest{ bisect.ChooseTerms, bisect.FromOtherBranch, bisect.Skip, + branch.CheckoutAutostash, branch.CheckoutByName, branch.CreateTag, branch.Delete, branch.DeleteRemoteBranchWithCredentialPrompt, branch.DetachedHead, + branch.NewBranchAutostash, branch.NewBranchFromRemoteTrackingDifferentName, branch.NewBranchFromRemoteTrackingSameName, branch.OpenPullRequestNoUpstream,