diff options
35 files changed, 182 insertions, 172 deletions
diff --git a/pkg/integration/components/alert_asserter.go b/pkg/integration/components/alert_asserter.go index c2b85848a..9dc2d32ab 100644 --- a/pkg/integration/components/alert_asserter.go +++ b/pkg/integration/components/alert_asserter.go @@ -8,7 +8,7 @@ type AlertAsserter struct { } func (self *AlertAsserter) getViewAsserter() *ViewAsserter { - return self.assert.View("confirmation") + return self.assert.Views().ByName("confirmation") } // asserts that the alert view has the expected title diff --git a/pkg/integration/components/assert.go b/pkg/integration/components/assert.go index ac6b99f0e..b4be669c5 100644 --- a/pkg/integration/components/assert.go +++ b/pkg/integration/components/assert.go @@ -182,34 +182,44 @@ func (self *Assert) FileSystemPathNotPresent(path string) { }) } -func (self *Assert) CurrentView() *ViewAsserter { - return &ViewAsserter{ - context: "current view", - getView: func() *gocui.View { return self.gui.CurrentContext().GetView() }, - assert: self, +func (self *Assert) Views() *ViewAsserterGetter { + return &ViewAsserterGetter{ + assert: self, } } -func (self *Assert) View(viewName string) *ViewAsserter { +type ViewAsserterGetter struct { + assert *Assert +} + +func (self *ViewAsserterGetter) Current() *ViewAsserter { return &ViewAsserter{ - context: fmt.Sprintf("%s view", viewName), - getView: func() *gocui.View { return self.gui.View(viewName) }, - assert: self, + context: "current view", + getView: func() *gocui.View { return self.assert.gui.CurrentContext().GetView() }, + assert: self.assert, } } -func (self *Assert) MainView() *ViewAsserter { +func (self *ViewAsserterGetter) Main() *ViewAsserter { return &ViewAsserter{ context: "main view", - getView: func() *gocui.View { return self.gui.MainView() }, - assert: self, + getView: func() *gocui.View { return self.assert.gui.MainView() }, + assert: self.assert, } } -func (self *Assert) SecondaryView() *ViewAsserter { +func (self *ViewAsserterGetter) Secondary() *ViewAsserter { return &ViewAsserter{ context: "secondary view", - getView: func() *gocui.View { return self.gui.SecondaryView() }, - assert: self, + getView: func() *gocui.View { return self.assert.gui.SecondaryView() }, + assert: self.assert, + } +} + +func (self *ViewAsserterGetter) ByName(viewName string) *ViewAsserter { + return &ViewAsserter{ + context: fmt.Sprintf("%s view", viewName), + getView: func() *gocui.View { return self.assert.gui.View(viewName) }, + assert: self.assert, } } diff --git a/pkg/integration/components/commit_message_panel_asserter.go b/pkg/integration/components/commit_message_panel_asserter.go index f7923282e..6ffb6b80c 100644 --- a/pkg/integration/components/commit_message_panel_asserter.go +++ b/pkg/integration/components/commit_message_panel_asserter.go @@ -6,7 +6,7 @@ type CommitMessagePanelAsserter struct { } func (self *CommitMessagePanelAsserter) getViewAsserter() *ViewAsserter { - return self.assert.View("commitMessage") + return self.assert.Views().ByName("commitMessage") } // asserts on the text initially present in the prompt diff --git a/pkg/integration/components/confirmation_asserter.go b/pkg/integration/components/confirmation_asserter.go index c0ff9246a..371e46028 100644 --- a/pkg/integration/components/confirmation_asserter.go +++ b/pkg/integration/components/confirmation_asserter.go @@ -8,7 +8,7 @@ type ConfirmationAsserter struct { } func (self *ConfirmationAsserter) getViewAsserter() *ViewAsserter { - return self.assert.View("confirmation") + return self.assert.Views().ByName("confirmation") } // asserts that the confirmation view has the expected title diff --git a/pkg/integration/components/input.go b/pkg/integration/components/input.go index c5d808588..014a74d5d 100644 --- a/pkg/integration/components/input.go +++ b/pkg/integration/components/input.go @@ -48,7 +48,7 @@ func (self *Input) SwitchToStatusWindow() { // switch to status window and assert that the status view is on top func (self *Input) SwitchToStatusView() { self.SwitchToStatusWindow() - self.assert.CurrentView().Name("status") + self.assert.Views().Current().Name("status") } func (self *Input) SwitchToFilesWindow() { @@ -59,7 +59,7 @@ func (self *Input) SwitchToFilesWindow() { // switch to files window and assert that the files view is on top func (self *Input) SwitchToFilesView() { self.SwitchToFilesWindow() - self.assert.CurrentView().Name("files") + self.assert.Views().Current().Name("files") } func (self *Input) SwitchToBranchesWindow() { @@ -70,7 +70,7 @@ func (self *Input) SwitchToBranchesWindow() { // switch to branches window and assert that the branches view is on top func (self *Input) SwitchToBranchesView() { self.SwitchToBranchesWindow() - self.assert.CurrentView().Name("localBranches") + self.assert.Views().Current().Name("localBranches") } func (self *Input) SwitchToCommitsWindow() { @@ -81,7 +81,7 @@ func (self *Input) SwitchToCommitsWindow() { // switch to commits window and assert that the commits view is on top func (self *Input) SwitchToCommitsView() { self.SwitchToCommitsWindow() - self.assert.CurrentView().Name("commits") + self.assert.Views().Current().Name("commits") } func (self *Input) SwitchToStashWindow() { @@ -92,7 +92,7 @@ func (self *Input) SwitchToStashWindow() { // switch to stash window and assert that the stash view is on top func (self *Input) SwitchToStashView() { self.SwitchToStashWindow() - self.assert.CurrentView().Name("stash") + self.assert.Views().Current().Name("stash") } func (self *Input) Type(content string) { @@ -133,7 +133,7 @@ func (self *Input) PreviousItem() { func (self *Input) ContinueMerge() { self.Press(self.keys.Universal.CreateRebaseOptionsMenu) - self.assert.CurrentView().SelectedLine(Contains("continue")) + self.assert.Views().Current().SelectedLine(Contains("continue")) self.Confirm() } @@ -197,20 +197,20 @@ func (self *Input) NavigateToListItem(matcher *matcher) { selectedLineIdx := view.SelectedLineIdx() if selectedLineIdx == matchIndex { - self.assert.CurrentView().SelectedLine(matcher) + self.assert.Views().Current().SelectedLine(matcher) return } if selectedLineIdx < matchIndex { for i := selectedLineIdx; i < matchIndex; i++ { self.NextItem() } - self.assert.CurrentView().SelectedLine(matcher) + self.assert.Views().Current().SelectedLine(matcher) return } else { for i := selectedLineIdx; i > matchIndex; i-- { self.PreviousItem() } - self.assert.CurrentView().SelectedLine(matcher) + self.assert.Views().Current().SelectedLine(matcher) return } } diff --git a/pkg/integration/components/menu_asserter.go b/pkg/integration/components/menu_asserter.go index 7c5e2e5f9..ab2256320 100644 --- a/pkg/integration/components/menu_asserter.go +++ b/pkg/integration/components/menu_asserter.go @@ -7,7 +7,7 @@ type MenuAsserter struct { } func (self *MenuAsserter) getViewAsserter() *ViewAsserter { - return self.assert.View("menu") + return self.assert.Views().ByName("menu") } // asserts that the popup has the expected title diff --git a/pkg/integration/components/prompt_asserter.go b/pkg/integration/components/prompt_asserter.go index 01d1ed8f7..079cc4d3f 100644 --- a/pkg/integration/components/prompt_asserter.go +++ b/pkg/integration/components/prompt_asserter.go @@ -7,7 +7,7 @@ type PromptAsserter struct { } func (self *PromptAsserter) getViewAsserter() *ViewAsserter { - return self.assert.View("confirmation") + return self.assert.Views().ByName("confirmation") } // asserts that the popup has the expected title @@ -55,27 +55,27 @@ func (self *PromptAsserter) checkNecessaryChecksCompleted() { } func (self *PromptAsserter) SuggestionLines(matchers ...*matcher) *PromptAsserter { - self.assert.View("suggestions").Lines(matchers...) + self.assert.Views().ByName("suggestions").Lines(matchers...) return self } func (self *PromptAsserter) SuggestionTopLines(matchers ...*matcher) *PromptAsserter { - self.assert.View("suggestions").TopLines(matchers...) + self.assert.Views().ByName("suggestions").TopLines(matchers...) return self } func (self *PromptAsserter) SelectFirstSuggestion() *PromptAsserter { self.input.Press(self.input.keys.Universal.TogglePanel) - self.assert.CurrentView().Name("suggestions") + self.assert.Views().Current().Name("suggestions") return self } func (self *PromptAsserter) SelectSuggestion(matcher *matcher) *PromptAsserter { self.input.Press(self.input.keys.Universal.TogglePanel) - self.assert.CurrentView().Name("suggestions") + self.assert.Views().Current().Name("suggestions") self.input.NavigateToListItem(matcher) diff --git a/pkg/integration/tests/bisect/basic.go b/pkg/integration/tests/bisect/basic.go index 86e58b681..7e2a21a61 100644 --- a/pkg/integration/tests/bisect/basic.go +++ b/pkg/integration/tests/bisect/basic.go @@ -34,28 +34,28 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ input.SwitchToCommitsView() - assert.CurrentView().SelectedLine(Contains("commit 10")) + assert.Views().Current().SelectedLine(Contains("commit 10")) input.NavigateToListItem(Contains("commit 09")) markCommitAsBad() - assert.View("information").Content(Contains("bisecting")) + assert.Views().ByName("information").Content(Contains("bisecting")) - assert.CurrentView().Name("commits").SelectedLine(Contains("<-- bad")) + assert.Views().Current().Name("commits").SelectedLine(Contains("<-- bad")) input.NavigateToListItem(Contains("commit 02")) markCommitAsGood() // lazygit will land us in the commit between our good and bad commits. - assert.CurrentView(). + assert.Views().Current(). Name("commits"). SelectedLine(Contains("commit 05").Contains("<-- current")) markCommitAsBad() - assert.CurrentView(). + assert.Views().Current(). Name("commits"). SelectedLine(Contains("commit 04").Contains("<-- current")) @@ -64,7 +64,7 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ // commit 5 is the culprit because we marked 4 as good and 5 as bad. input.Alert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 05.*Do you want to reset")).Confirm() - assert.CurrentView().Name("commits").Content(Contains("commit 04")) - assert.View("information").Content(DoesNotContain("bisecting")) + assert.Views().Current().Name("commits").Content(Contains("commit 04")) + assert.Views().ByName("information").Content(DoesNotContain("bisecting")) }, }) diff --git a/pkg/integration/tests/bisect/from_other_branch.go b/pkg/integration/tests/bisect/from_other_branch.go index 40308246e..255b39542 100644 --- a/pkg/integration/tests/bisect/from_other_branch.go +++ b/pkg/integration/tests/bisect/from_other_branch.go @@ -24,13 +24,13 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{ assert *Assert, keys config.KeybindingConfig, ) { - assert.View("information").Content(Contains("bisecting")) + assert.Views().ByName("information").Content(Contains("bisecting")) assert.AtLeastOneCommit() input.SwitchToCommitsView() - assert.CurrentView().TopLines( + assert.Views().Current().TopLines( MatchesRegexp(`<-- bad.*commit 08`), MatchesRegexp(`<-- current.*commit 07`), MatchesRegexp(`\?.*commit 06`), @@ -44,10 +44,10 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{ input.Alert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 08.*Do you want to reset")).Confirm() - assert.View("information").Content(DoesNotContain("bisecting")) + assert.Views().ByName("information").Content(DoesNotContain("bisecting")) // back in master branch which just had the one commit - assert.CurrentView().Name("commits").Lines( + assert.Views().Current().Name("commits").Lines( Contains("only commit on master"), ) }, diff --git a/pkg/integration/tests/branch/checkout_by_name.go b/pkg/integration/tests/branch/checkout_by_name.go index e855b7103..ccf75a831 100644 --- a/pkg/integration/tests/branch/checkout_by_name.go +++ b/pkg/integration/tests/branch/checkout_by_name.go @@ -20,7 +20,7 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( Contains("master"), Contains("@"), ) @@ -32,7 +32,7 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ input.Alert().Title(Equals("Branch not found")).Content(Equals("Branch not found. Create a new branch named new-branch?")).Confirm() - assert.CurrentView().Name("localBranches"). + assert.Views().Current().Name("localBranches"). Lines( MatchesRegexp(`\*.*new-branch`), Contains("master"), diff --git a/pkg/integration/tests/branch/delete.go b/pkg/integration/tests/branch/delete.go index c28668bb5..08b4e8f62 100644 --- a/pkg/integration/tests/branch/delete.go +++ b/pkg/integration/tests/branch/delete.go @@ -19,7 +19,7 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( MatchesRegexp(`\*.*branch-two`), MatchesRegexp(`branch-one`), MatchesRegexp(`master`), @@ -36,7 +36,7 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("Are you sure you want to delete the branch 'branch-one'?")). Confirm() - assert.CurrentView().Name("localBranches"). + assert.Views().Current().Name("localBranches"). Lines( MatchesRegexp(`\*.*branch-two`), MatchesRegexp(`master`).IsSelected(), diff --git a/pkg/integration/tests/branch/rebase.go b/pkg/integration/tests/branch/rebase.go index e4f03810e..ab3302068 100644 --- a/pkg/integration/tests/branch/rebase.go +++ b/pkg/integration/tests/branch/rebase.go @@ -17,13 +17,13 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesView() - assert.View("localBranches").Lines( + assert.Views().ByName("localBranches").Lines( Contains("first-change-branch"), Contains("second-change-branch"), Contains("original-branch"), ) - assert.View("commits").TopLines( + assert.Views().ByName("commits").TopLines( Contains("first change"), Contains("original"), ) @@ -40,25 +40,25 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("Conflicts!")). Confirm() - assert.CurrentView().Name("files").SelectedLine(Contains("file")) + assert.Views().Current().Name("files").SelectedLine(Contains("file")) // not using Confirm() convenience method because I suspect we might change this // keybinding to something more bespoke input.Press(keys.Universal.Confirm) - assert.CurrentView().Name("mergeConflicts") + assert.Views().Current().Name("mergeConflicts") input.PrimaryAction() - assert.View("information").Content(Contains("rebasing")) + assert.Views().ByName("information").Content(Contains("rebasing")) input.Confirmation(). Title(Equals("continue")). Content(Contains("all merge conflicts resolved. Continue?")). Confirm() - assert.View("information").Content(DoesNotContain("rebasing")) + assert.Views().ByName("information").Content(DoesNotContain("rebasing")) - assert.View("commits").TopLines( + assert.Views().ByName("commits").TopLines( Contains("second-change-branch unrelated change"), Contains("second change"), Contains("original"), diff --git a/pkg/integration/tests/branch/rebase_and_drop.go b/pkg/integration/tests/branch/rebase_and_drop.go index b1cc408ba..1c77dbefc 100644 --- a/pkg/integration/tests/branch/rebase_and_drop.go +++ b/pkg/integration/tests/branch/rebase_and_drop.go @@ -20,13 +20,13 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( Contains("first-change-branch"), Contains("second-change-branch"), Contains("original-branch"), ) - assert.View("commits").TopLines( + assert.Views().ByName("commits").TopLines( Contains("to keep").IsSelected(), Contains("to remove"), Contains("first change"), @@ -41,19 +41,19 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")). Confirm() - assert.View("information").Content(Contains("rebasing")) + assert.Views().ByName("information").Content(Contains("rebasing")) input.Confirmation(). Title(Equals("Auto-merge failed")). Content(Contains("Conflicts!")). Confirm() - assert.CurrentView(). + assert.Views().Current(). Name("files"). SelectedLine(MatchesRegexp("UU.*file")) input.SwitchToCommitsView() - assert.CurrentView(). + assert.Views().Current(). TopLines( MatchesRegexp(`pick.*to keep`).IsSelected(), MatchesRegexp(`pick.*to remove`), @@ -65,7 +65,7 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Universal.Remove) - assert.CurrentView(). + assert.Views().Current(). TopLines( MatchesRegexp(`pick.*to keep`), MatchesRegexp(`drop.*to remove`).IsSelected(), @@ -80,7 +80,7 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ // keybinding to something more bespoke input.Press(keys.Universal.Confirm) - assert.CurrentView().Name("mergeConflicts") + assert.Views().Current().Name("mergeConflicts") input.PrimaryAction() input.Confirmation(). @@ -88,9 +88,9 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("all merge conflicts resolved. Continue?")). Confirm() - assert.View("information").Content(DoesNotContain("rebasing")) + assert.Views().ByName("information").Content(DoesNotContain("rebasing")) - assert.View("commits").TopLines( + assert.Views().ByName("commits").TopLines( Contains("to keep"), Contains("second-change-branch unrelated change").IsSelected(), Contains("second change"), diff --git a/pkg/integration/tests/branch/reset.go b/pkg/integration/tests/branch/reset.go index 821373934..fec6aea7a 100644 --- a/pkg/integration/tests/branch/reset.go +++ b/pkg/integration/tests/branch/reset.go @@ -21,14 +21,14 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{ shell.EmptyCommit("current-branch commit") }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { - assert.View("commits").Lines( + assert.Views().ByName("commits").Lines( Contains("current-branch commit"), Contains("root commit"), ) input.SwitchToBranchesView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( Contains("current-branch"), Contains("other-branch"), ) @@ -39,11 +39,11 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu().Title(Contains("reset to other-branch")).Select(Contains("hard reset")).Confirm() // ensure that we've returned from the menu before continuing - assert.CurrentView().Name("localBranches") + assert.Views().Current().Name("localBranches") // assert that we now have the expected commits in the commit panel input.SwitchToCommitsView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( Contains("other-branch commit"), Contains("root commit"), ) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick.go b/pkg/integration/tests/cherry_pick/cherry_pick.go index 631685577..f832bfe83 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick.go @@ -26,7 +26,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( Contains("first-branch"), Contains("second-branch"), Contains("master"), @@ -36,7 +36,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ input.Enter() - assert.CurrentView().Name("subCommits").Lines( + assert.Views().Current().Name("subCommits").Lines( Contains("four"), Contains("three"), Contains("base"), @@ -44,14 +44,14 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ // copy commits 'four' and 'three' input.Press(keys.Commits.CherryPickCopy) - assert.View("information").Content(Contains("1 commit copied")) + assert.Views().ByName("information").Content(Contains("1 commit copied")) input.NextItem() input.Press(keys.Commits.CherryPickCopy) - assert.View("information").Content(Contains("2 commits copied")) + assert.Views().ByName("information").Content(Contains("2 commits copied")) input.SwitchToCommitsView() - assert.CurrentView().Lines( + assert.Views().Current().Lines( Contains("two"), Contains("one"), Contains("base"), @@ -63,7 +63,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")). Confirm() - assert.CurrentView().Name("commits").Lines( + assert.Views().Current().Name("commits").Lines( Contains("four"), Contains("three"), Contains("two"), @@ -71,8 +71,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ Contains("base"), ) - assert.View("information").Content(Contains("2 commits copied")) + assert.Views().ByName("information").Content(Contains("2 commits copied")) input.Press(keys.Universal.Return) - assert.View("information").Content(DoesNotContain("commits copied")) + assert.Views().ByName("information").Content(DoesNotContain("commits copied")) }, }) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go index 8efb94e5d..b0be4b48e 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go @@ -16,7 +16,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBr |