diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-02-22 21:57:32 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-02-22 21:57:32 +1100 |
commit | eabe7f462a1f950d05b66306c19a00855e3fa175 (patch) | |
tree | 2d500a74e016ee3a3cb5ab5e998914f7ba15f571 /pkg/integration | |
parent | 22c10479d528d3d9982f142139f82a8c764a550d (diff) |
migrate more tests
Diffstat (limited to 'pkg/integration')
-rw-r--r-- | pkg/integration/components/prompt_driver.go | 3 | ||||
-rw-r--r-- | pkg/integration/components/search_driver.go | 39 | ||||
-rw-r--r-- | pkg/integration/components/shell.go | 2 | ||||
-rw-r--r-- | pkg/integration/components/test_driver.go | 13 | ||||
-rw-r--r-- | pkg/integration/components/views.go | 4 | ||||
-rw-r--r-- | pkg/integration/tests/branch/reset_upstream.go | 36 | ||||
-rw-r--r-- | pkg/integration/tests/branch/set_upstream.go | 40 | ||||
-rw-r--r-- | pkg/integration/tests/commit/reset_author.go | 39 | ||||
-rw-r--r-- | pkg/integration/tests/commit/search.go | 107 | ||||
-rw-r--r-- | pkg/integration/tests/commit/set_author.go | 51 | ||||
-rw-r--r-- | pkg/integration/tests/staging/search.go | 42 | ||||
-rw-r--r-- | pkg/integration/tests/tests_gen.go | 7 |
12 files changed, 380 insertions, 3 deletions
diff --git a/pkg/integration/components/prompt_driver.go b/pkg/integration/components/prompt_driver.go index 45a6db513..59e3587ef 100644 --- a/pkg/integration/components/prompt_driver.go +++ b/pkg/integration/components/prompt_driver.go @@ -32,8 +32,7 @@ func (self *PromptDriver) Type(value string) *PromptDriver { } func (self *PromptDriver) Clear() *PromptDriver { - // TODO: soft-code this - self.t.press("<c-u>") + self.t.press(ClearKey) return self } diff --git a/pkg/integration/components/search_driver.go b/pkg/integration/components/search_driver.go new file mode 100644 index 000000000..4ab4a4103 --- /dev/null +++ b/pkg/integration/components/search_driver.go @@ -0,0 +1,39 @@ +package components + +// TODO: soft-code this +const ClearKey = "<c-u>" + +type SearchDriver struct { + t *TestDriver +} + +func (self *SearchDriver) getViewDriver() *ViewDriver { + return self.t.Views().Search() +} + +// asserts on the text initially present in the prompt +func (self *SearchDriver) InitialText(expected *matcher) *SearchDriver { + self.getViewDriver().Content(expected) + + return self +} + +func (self *SearchDriver) Type(value string) *SearchDriver { + self.t.typeContent(value) + + return self +} + +func (self *SearchDriver) Clear() *SearchDriver { + self.t.press(ClearKey) + + return self +} + +func (self *SearchDriver) Confirm() { + self.getViewDriver().PressEnter() +} + +func (self *SearchDriver) Cancel() { + self.getViewDriver().PressEscape() +} diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 2087cd389..8d47083ad 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -179,7 +179,7 @@ func (self *Shell) StashWithMessage(message string) *Shell { } func (self *Shell) SetConfig(key string, value string) *Shell { - self.RunCommand(fmt.Sprintf(`git config --local "%s" %s`, key, value)) + self.RunCommand(fmt.Sprintf(`git config --local "%s" "%s"`, key, value)) return self } diff --git a/pkg/integration/components/test_driver.go b/pkg/integration/components/test_driver.go index 1128de3f5..e52cc8915 100644 --- a/pkg/integration/components/test_driver.go +++ b/pkg/integration/components/test_driver.go @@ -159,6 +159,19 @@ func (self *TestDriver) ExpectClipboard(matcher *matcher) { }) } +func (self *TestDriver) ExpectSearch() *SearchDriver { + self.inSearch() + + return &SearchDriver{t: self} +} + +func (self *TestDriver) inSearch() { + self.assertWithRetries(func() (bool, string) { + currentView := self.gui.CurrentContext().GetView() + return currentView.Name() == "search", "Expected search prompt to be focused" + }) +} + // for making assertions through git itself func (self *TestDriver) Git() *Git { return &Git{assertionHelper: self.assertionHelper, shell: self.shell} diff --git a/pkg/integration/components/views.go b/pkg/integration/components/views.go index 4c8002469..ea5257602 100644 --- a/pkg/integration/components/views.go +++ b/pkg/integration/components/views.go @@ -127,3 +127,7 @@ func (self *Views) Suggestions() *ViewDriver { func (self *Views) MergeConflicts() *ViewDriver { return self.byName("mergeConflicts") } + +func (self *Views) Search() *ViewDriver { + return self.byName("search") +} diff --git a/pkg/integration/tests/branch/reset_upstream.go b/pkg/integration/tests/branch/reset_upstream.go new file mode 100644 index 000000000..126d2abf9 --- /dev/null +++ b/pkg/integration/tests/branch/reset_upstream.go @@ -0,0 +1,36 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ResetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Reset the upstream of a branch", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.CloneIntoRemote("origin") + shell.SetBranchUpstream("master", "origin/master") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Press(keys.Universal.NextScreenMode). // we need to enlargen the window to see the upstream + Lines( + Contains("master").Contains("origin master").IsSelected(), + ). + Press(keys.Branches.SetUpstream). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Set/unset upstream")). + Select(Contains("unset upstream of selected branch")). + Confirm() + }). + Lines( + Contains("master").DoesNotContain("origin master").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/branch/set_upstream.go b/pkg/integration/tests/branch/set_upstream.go new file mode 100644 index 000000000..3388a6086 --- /dev/null +++ b/pkg/integration/tests/branch/set_upstream.go @@ -0,0 +1,40 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SetUpstream = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Set the upstream of a branch", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.CloneIntoRemote("origin") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Press(keys.Universal.NextScreenMode). // we need to enlargen the window to see the upstream + Lines( + Contains("master").DoesNotContain("origin master").IsSelected(), + ). + Press(keys.Branches.SetUpstream). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Set/unset upstream")). + Select(Contains(" set upstream of selected branch")). // using leading space to disambiguate from the 'reset' option + Confirm() + + t.ExpectPopup().Prompt(). + Title(Equals("Enter upstream as '<remote> <branchname>'")). + SuggestionLines(Equals("origin master")). + ConfirmFirstSuggestion() + }). + Lines( + Contains("master").Contains("origin master").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/commit/reset_author.go b/pkg/integration/tests/commit/reset_author.go new file mode 100644 index 000000000..f54b5b5aa --- /dev/null +++ b/pkg/integration/tests/commit/reset_author.go @@ -0,0 +1,39 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ResetAuthor = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Reset author on a commit", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.SetConfig("user.email", "Bill@example.com") + shell.SetConfig("user.name", "Bill Smith") + + shell.EmptyCommit("one") + + shell.SetConfig("user.email", "John@example.com") + shell.SetConfig("user.name", "John Smith") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("BS").Contains("one").IsSelected(), + ). + Press(keys.Commits.ResetCommitAuthor). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Amend commit attribute")). + Select(Contains("reset author")). + Confirm() + }). + Lines( + Contains("JS").Contains("one").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/commit/search.go b/pkg/integration/tests/commit/search.go new file mode 100644 index 000000000..7159b11d1 --- /dev/null +++ b/pkg/integration/tests/commit/search.go @@ -0,0 +1,107 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Search = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Search for a commit", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.EmptyCommit("two") + 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"), + ). + Press(keys.Universal.StartSearch). + Tap(func() { + t.ExpectSearch(). + Type("two"). + Confirm() + + t.Views().Search().Content(Contains("matches for 'two' (1 of 1)")) + }). + Lines( + Contains("four"), + Contains("three"), + Contains("two").IsSelected(), + Contains("one"), + ). + Press(keys.Universal.StartSearch). + Tap(func() { + t.ExpectSearch(). + Type("o"). + Confirm() + + t.Views().Search().Content(Contains("matches for 'o' (2 of 3)")) + }). + Lines( + Contains("four"), + Contains("three"), + Contains("two").IsSelected(), + Contains("one"), + ). + Press("n"). + Tap(func() { + t.Views().Search().Content(Contains("matches for 'o' (3 of 3)")) + }). + Lines( + Contains("four"), + Contains("three"), + Contains("two"), + Contains("one").IsSelected(), + ). + Press("n"). + Tap(func() { + t.Views().Search().Content(Contains("matches for 'o' (1 of 3)")) + }). + Lines( + Contains("four").IsSelected(), + Contains("three"), + Contains("two"), + Contains("one"), + ). + Press("n"). + Tap(func() { + t.Views().Search().Content(Contains("matches for 'o' (2 of 3)")) + }). + Lines( + Contains("four"), + Contains("three"), + Contains("two").IsSelected(), + Contains("one"), + ). + Press("N"). + Tap(func() { + t.Views().Search().Content(Contains("matches for 'o' (1 of 3)")) + }). + Lines( + Contains("four").IsSelected(), + Contains("three"), + Contains("two"), + Contains("one"), + ). + Press("N"). + Tap(func() { + t.Views().Search().Content(Contains("matches for 'o' (3 of 3)")) + }). + Lines( + Contains("four"), + Contains("three"), + Contains("two"), + Contains("one").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/commit/set_author.go b/pkg/integration/tests/commit/set_author.go new file mode 100644 index 000000000..047ac167c --- /dev/null +++ b/pkg/integration/tests/commit/set_author.go @@ -0,0 +1,51 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SetAuthor = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Set author on a commit", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.SetConfig("user.email", "Bill@example.com") + shell.SetConfig("user.name", "Bill Smith") + + shell.EmptyCommit("one") + + shell.SetConfig("user.email", "John@example.com") + shell.SetConfig("user.name", "John Smith") + + shell.EmptyCommit("two") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("JS").Contains("two").IsSelected(), + Contains("BS").Contains("one"), + ). + Press(keys.Commits.ResetCommitAuthor). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Amend commit attribute")). + Select(Contains(" set author")). // adding space at start to distinguish from 'reset author' + Confirm() + + t.ExpectPopup().Prompt(). + Title(Contains("Set author")). + SuggestionLines( + Contains("John Smith"), + Contains("Bill Smith"), + ). + ConfirmSuggestion(Contains("John Smith")) + }). + Lines( + Contains("JS").Contains("two").IsSelected(), + Contains("BS").Contains("one"), + ) + }, +}) diff --git a/pkg/integration/tests/staging/search.go b/pkg/integration/tests/staging/search.go new file mode 100644 index 000000000..b7a42a276 --- /dev/null +++ b/pkg/integration/tests/staging/search.go @@ -0,0 +1,42 @@ +package staging + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Search = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Use the search feature in the staging panel", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFile("file1", "one\ntwo\nthree\nfour\nfive") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Contains("file1").IsSelected(), + ). + PressEnter() + + t.Views().Staging(). + IsFocused(). + Press(keys.Universal.StartSearch). + Tap(func() { + t.ExpectSearch(). + Type("four"). + Confirm() + + t.Views().Search().Content(Contains("matches for 'four' (1 of 1)")) + }). + SelectedLine(Contains("+four")). // stage the line + PressPrimaryAction(). + Content(DoesNotContain("+four")). + Tap(func() { + t.Views().StagingSecondary(). + Content(Contains("+four")) + }) + }, +}) diff --git a/pkg/integration/tests/tests_gen.go b/pkg/integration/tests/tests_gen.go index a7cade4d4..635451b54 100644 --- a/pkg/integration/tests/tests_gen.go +++ b/pkg/integration/tests/tests_gen.go @@ -18,6 +18,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/tests/misc" "github.com/jesseduffield/lazygit/pkg/integration/tests/patch_building" "github.com/jesseduffield/lazygit/pkg/integration/tests/reflog" + "github.com/jesseduffield/lazygit/pkg/integration/tests/staging" "github.com/jesseduffield/lazygit/pkg/integration/tests/stash" "github.com/jesseduffield/lazygit/pkg/integration/tests/submodule" "github.com/jesseduffield/lazygit/pkg/integration/tests/sync" @@ -38,6 +39,8 @@ var tests = []*components.IntegrationTest{ branch.RebaseAndDrop, branch.RebaseDoesNotAutosquash, branch.Reset, + branch.ResetUpstream, + branch.SetUpstream, branch.Suggestions, cherry_pick.CherryPick, cherry_pick.CherryPickConflicts, @@ -46,8 +49,11 @@ var tests = []*components.IntegrationTest{ commit.CreateTag, commit.DiscardOldFileChange, commit.NewBranch, + commit.ResetAuthor, commit.Revert, commit.RevertMerge, + commit.Search, + commit.SetAuthor, commit.StageRangeOfLines, commit.Staged, commit.StagedWithoutHooks, @@ -92,6 +98,7 @@ var tests = []*components.IntegrationTest{ reflog.CherryPick, reflog.Patch, reflog.Reset, + staging.Search, stash.Apply, stash.ApplyPatch, stash.CreateBranch, |