diff options
23 files changed, 169 insertions, 63 deletions
diff --git a/pkg/integration/components/alert_asserter.go b/pkg/integration/components/alert_asserter.go new file mode 100644 index 000000000..c2b85848a --- /dev/null +++ b/pkg/integration/components/alert_asserter.go @@ -0,0 +1,48 @@ +package components + +type AlertAsserter struct { + assert *Assert + input *Input + hasCheckedTitle bool + hasCheckedContent bool +} + +func (self *AlertAsserter) getViewAsserter() *ViewAsserter { + return self.assert.View("confirmation") +} + +// asserts that the alert view has the expected title +func (self *AlertAsserter) Title(expected *matcher) *AlertAsserter { + self.getViewAsserter().Title(expected) + + self.hasCheckedTitle = true + + return self +} + +// asserts that the alert view has the expected content +func (self *AlertAsserter) Content(expected *matcher) *AlertAsserter { + self.getViewAsserter().Content(expected) + + self.hasCheckedContent = true + + return self +} + +func (self *AlertAsserter) Confirm() { + self.checkNecessaryChecksCompleted() + + self.input.Confirm() +} + +func (self *AlertAsserter) Cancel() { + self.checkNecessaryChecksCompleted() + + self.input.Press(self.input.keys.Universal.Return) +} + +func (self *AlertAsserter) checkNecessaryChecksCompleted() { + if !self.hasCheckedContent || !self.hasCheckedTitle { + self.assert.Fail("You must both check the content and title of a confirmation popup by calling Title()/Content() before calling Confirm()/Cancel().") + } +} diff --git a/pkg/integration/components/confirmation_asserter.go b/pkg/integration/components/confirmation_asserter.go index fa11e814f..c0ff9246a 100644 --- a/pkg/integration/components/confirmation_asserter.go +++ b/pkg/integration/components/confirmation_asserter.go @@ -29,20 +29,16 @@ func (self *ConfirmationAsserter) Content(expected *matcher) *ConfirmationAssert return self } -func (self *ConfirmationAsserter) Confirm() *ConfirmationAsserter { +func (self *ConfirmationAsserter) Confirm() { self.checkNecessaryChecksCompleted() self.input.Confirm() - - return self } -func (self *ConfirmationAsserter) Cancel() *ConfirmationAsserter { +func (self *ConfirmationAsserter) Cancel() { self.checkNecessaryChecksCompleted() self.input.Press(self.input.keys.Universal.Return) - - return self } func (self *ConfirmationAsserter) checkNecessaryChecksCompleted() { diff --git a/pkg/integration/components/input.go b/pkg/integration/components/input.go index 2d086eba5..91048dfb7 100644 --- a/pkg/integration/components/input.go +++ b/pkg/integration/components/input.go @@ -227,28 +227,14 @@ func (self *Input) Prompt() *PromptAsserter { return &PromptAsserter{assert: self.assert, input: self} } -// type some text into a prompt, then switch to the suggestions panel and expect the first -// item to match the given matcher, then confirm that item. -func (self *Input) Typeahead(title *matcher, textToType string, expectedFirstOption *matcher) { - self.assert.InPrompt() - self.assert.CurrentView().Title(title) - self.Type(textToType) - self.Press(self.keys.Universal.TogglePanel) - self.assert.CurrentView().Name("suggestions") - self.assert.CurrentView().SelectedLine(expectedFirstOption) - self.Confirm() +func (self *Input) Alert() *AlertAsserter { + self.assert.InAlert() + + return &AlertAsserter{assert: self.assert, input: self} } -func (self *Input) Menu(title *matcher, optionToSelect *matcher) { +func (self *Input) Menu() *MenuAsserter { self.assert.InMenu() - self.assert.CurrentView().Title(title) - self.NavigateToListItem(optionToSelect) - self.Confirm() -} -func (self *Input) Alert(title *matcher, content *matcher) { - self.assert.InListContext() - self.assert.CurrentView().Title(title) - self.assert.CurrentView().Content(content) - self.Confirm() + return &MenuAsserter{assert: self.assert, input: self} } diff --git a/pkg/integration/components/menu_asserter.go b/pkg/integration/components/menu_asserter.go new file mode 100644 index 000000000..7c5e2e5f9 --- /dev/null +++ b/pkg/integration/components/menu_asserter.go @@ -0,0 +1,44 @@ +package components + +type MenuAsserter struct { + assert *Assert + input *Input + hasCheckedTitle bool +} + +func (self *MenuAsserter) getViewAsserter() *ViewAsserter { + return self.assert.View("menu") +} + +// asserts that the popup has the expected title +func (self *MenuAsserter) Title(expected *matcher) *MenuAsserter { + self.getViewAsserter().Title(expected) + + self.hasCheckedTitle = true + + return self +} + +func (self *MenuAsserter) Confirm() { + self.checkNecessaryChecksCompleted() + + self.input.Confirm() +} + +func (self *MenuAsserter) Cancel() { + self.checkNecessaryChecksCompleted() + + self.input.Press(self.input.keys.Universal.Return) +} + +func (self *MenuAsserter) Select(option *matcher) *MenuAsserter { + self.input.NavigateToListItem(option) + + return self +} + +func (self *MenuAsserter) checkNecessaryChecksCompleted() { + if !self.hasCheckedTitle { + self.assert.Fail("You must check the title of a menu popup by calling Title() before calling Confirm()/Cancel().") + } +} diff --git a/pkg/integration/components/prompt_asserter.go b/pkg/integration/components/prompt_asserter.go index 839934aaa..01d1ed8f7 100644 --- a/pkg/integration/components/prompt_asserter.go +++ b/pkg/integration/components/prompt_asserter.go @@ -26,34 +26,58 @@ func (self *PromptAsserter) InitialText(expected *matcher) *PromptAsserter { return self } -func (self *PromptAsserter) Confirm() *PromptAsserter { +func (self *PromptAsserter) Type(value string) *PromptAsserter { + self.input.Type(value) + + return self +} + +func (self *PromptAsserter) Clear() *PromptAsserter { + panic("Clear method not yet implemented!") +} + +func (self *PromptAsserter) Confirm() { self.checkNecessaryChecksCompleted() self.input.Confirm() - - return self } -func (self *PromptAsserter) Cancel() *PromptAsserter { +func (self *PromptAsserter) Cancel() { self.checkNecessaryChecksCompleted() self.input.Press(self.input.keys.Universal.Return) +} + +func (self *PromptAsserter) checkNecessaryChecksCompleted() { + if !self.hasCheckedTitle { + self.assert.Fail("You must check the title of a prompt popup by calling Title() before calling Confirm()/Cancel().") + } +} + +func (self *PromptAsserter) SuggestionLines(matchers ...*matcher) *PromptAsserter { + self.assert.View("suggestions").Lines(matchers...) return self } -func (self *PromptAsserter) Type(value string) *PromptAsserter { - self.input.Type(value) +func (self *PromptAsserter) SuggestionTopLines(matchers ...*matcher) *PromptAsserter { + self.assert.View("suggestions").TopLines(matchers...) return self } -func (self *PromptAsserter) Clear() *PromptAsserter { - panic("Clear method not yet implemented!") +func (self *PromptAsserter) SelectFirstSuggestion() *PromptAsserter { + self.input.Press(self.input.keys.Universal.TogglePanel) + self.assert.CurrentView().Name("suggestions") + + return self } -func (self *PromptAsserter) checkNecessaryChecksCompleted() { - if !self.hasCheckedTitle { - self.assert.Fail("You must check the title of a prompt popup by calling Title() before calling Confirm()/Cancel().") - } +func (self *PromptAsserter) SelectSuggestion(matcher *matcher) *PromptAsserter { + self.input.Press(self.input.keys.Universal.TogglePanel) + self.assert.CurrentView().Name("suggestions") + + self.input.NavigateToListItem(matcher) + + return self } diff --git a/pkg/integration/tests/bisect/basic.go b/pkg/integration/tests/bisect/basic.go index 45d66fa18..86e58b681 100644 --- a/pkg/integration/tests/bisect/basic.go +++ b/pkg/integration/tests/bisect/basic.go @@ -22,12 +22,12 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ ) { markCommitAsBad := func() { input.Press(keys.Commits.ViewBisectOptions) - input.Menu(Equals("Bisect"), MatchesRegexp(`mark .* as bad`)) + input.Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as bad`)).Confirm() } markCommitAsGood := func() { input.Press(keys.Commits.ViewBisectOptions) - input.Menu(Equals("Bisect"), MatchesRegexp(`mark .* as good`)) + input.Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm() } assert.AtLeastOneCommit() @@ -62,7 +62,7 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ markCommitAsGood() // commit 5 is the culprit because we marked 4 as good and 5 as bad. - input.Alert(Equals("Bisect complete"), MatchesRegexp("(?s)commit 05.*Do you want to reset")) + 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")) diff --git a/pkg/integration/tests/bisect/from_other_branch.go b/pkg/integration/tests/bisect/from_other_branch.go index cb31af972..40308246e 100644 --- a/pkg/integration/tests/bisect/from_other_branch.go +++ b/pkg/integration/tests/bisect/from_other_branch.go @@ -40,9 +40,9 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Commits.ViewBisectOptions) - input.Menu(Equals("Bisect"), MatchesRegexp(`mark .* as good`)) + input.Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm() - input.Alert(Equals("Bisect complete"), MatchesRegexp(`(?s)commit 08.*Do you want to reset`)) + input.Alert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 08.*Do you want to reset")).Confirm() assert.View("information").Content(DoesNotContain("bisecting")) diff --git a/pkg/integration/tests/branch/checkout_by_name.go b/pkg/integration/tests/branch/checkout_by_name.go index 17fd214af..e855b7103 100644 --- a/pkg/integration/tests/branch/checkout_by_name.go +++ b/pkg/integration/tests/branch/checkout_by_name.go @@ -30,7 +30,7 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ input.Prompt().Title(Equals("Branch name:")).Type("new-branch").Confirm() - input.Alert(Equals("Branch not found"), Equals("Branch not found. Create a new branch named new-branch?")) + input.Alert().Title(Equals("Branch not found")).Content(Equals("Branch not found. Create a new branch named new-branch?")).Confirm() assert.CurrentView().Name("localBranches"). Lines( diff --git a/pkg/integration/tests/branch/delete.go b/pkg/integration/tests/branch/delete.go index 815d40d45..c28668bb5 100644 --- a/pkg/integration/tests/branch/delete.go +++ b/pkg/integration/tests/branch/delete.go @@ -26,7 +26,7 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ ) input.Press(keys.Universal.Remove) - input.Alert(Equals("Error"), Contains("You cannot delete the checked out branch!")) + input.Alert().Title(Equals("Error")).Content(Contains("You cannot delete the checked out branch!")).Confirm() input.NextItem() diff --git a/pkg/integration/tests/branch/reset.go b/pkg/integration/tests/branch/reset.go index 8be35e4ec..821373934 100644 --- a/pkg/integration/tests/branch/reset.go +++ b/pkg/integration/tests/branch/reset.go @@ -36,7 +36,7 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Commits.ViewResetOptions) - input.Menu(Contains("reset to other-branch"), Contains("hard reset")) + 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") diff --git a/pkg/integration/tests/branch/suggestions.go b/pkg/integration/tests/branch/suggestions.go index 7631ad735..f9399296d 100644 --- a/pkg/integration/tests/branch/suggestions.go +++ b/pkg/integration/tests/branch/suggestions.go @@ -27,7 +27,12 @@ var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{ // we expect the first suggestion to be the branch we want because it most // closely matches what we typed in - input.Typeahead(Equals("Branch name:"), "branch-to", Contains("branch-to-checkout")) + input.Prompt(). + Title(Equals("Branch name:")). + Type("branch-to"). + SuggestionTopLines(Contains("branch-to-checkout")). + SelectFirstSuggestion(). + Confirm() assert.CurrentBranchName("branch-to-checkout") }, diff --git a/pkg/integration/tests/cherry_pick/cherry_pick.go b/pkg/integration/tests/cherry_pick/cherry_pick.go index e79e35b19..631685577 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick.go @@ -58,7 +58,10 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ ) input.Press(keys.Commits.PasteCommits) - input.Alert(Equals("Cherry-Pick"), Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")) + input.Alert(). + Title(Equals("Cherry-Pick")). + Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")). + Confirm() assert.CurrentView().Name("commits").Lines( Contains("four"), diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go index 31c64664f..8efb94e5d 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go @@ -45,7 +45,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ ) input.Press(keys.Commits.PasteCommits) - input.Alert(Equals("Cherry-Pick"), Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")) + input.Alert().Title(Equals("Cherry-Pick")).Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).Confirm() input.Confirmation(). Title(Equals("Auto-merge failed")). diff --git a/pkg/integration/tests/custom_commands/form_prompts.go b/pkg/integration/tests/custom_commands/form_prompts.go index dbb2b3c8c..fa6495a93 100644 --- a/pkg/integration/tests/custom_commands/form_prompts.go +++ b/pkg/integration/tests/custom_commands/form_prompts.go @@ -67,7 +67,7 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{ input.Prompt().Title(Equals("Enter a file name")).Type("my file").Confirm() - input.Menu(Equals("Choose file content"), Contains("bar")) + input.Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm() input.Confirmation(). Title(Equals("Are you sure?")). diff --git a/pkg/integration/tests/custom_commands/menu_from_command.go b/pkg/integration/tests/custom_commands/menu_from_command.go index f130af989..d9b9fab05 100644 --- a/pkg/integration/tests/custom_commands/menu_from_command.go +++ b/pkg/integration/tests/custom_commands/menu_from_command.go @@ -53,7 +53,7 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{ input.Press("a") - input.Menu(Equals("Choose commit message"), Contains("bar")) + input.Menu().Title(Equals("Choose commit message")).Select(Contains("bar")).Confirm() input.Prompt().Title(Equals("Description")).Type(" my branch").Confirm() diff --git a/pkg/integration/tests/custom_commands/menu_from_commands_output.go b/pkg/integration/tests/custom_commands/menu_from_commands_output.go index 68c4db0f6..d17cb1176 100644 --- a/pkg/integration/tests/custom_commands/menu_from_commands_output.go +++ b/pkg/integration/tests/custom_commands/menu_from_commands_output.go @@ -60,7 +60,7 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{ SelectedLine(Equals("branch")) input.Confirm() - input.Menu(Equals("Branch:"), Equals("master")) + input.Menu().Title(Equals("Branch:")).Select(Equals("master")).Confirm() assert.CurrentBranchName("master") }, diff --git a/pkg/integration/tests/custom_commands/multiple_prompts.go b/pkg/integration/tests/custom_commands/multiple_prompts.go index eb20876cf..9b77a05bf 100644 --- a/pkg/integration/tests/custom_commands/multiple_prompts.go +++ b/pkg/integration/tests/custom_commands/multiple_prompts.go @@ -65,7 +65,7 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{ input.Prompt().Title(Equals("Enter a file name")).Type("myfile").Confirm() - input.Menu(Equals("Choose file content"), Contains("bar")) + input.Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm() input.Confirmation(). Title(Equals("Are you sure?")). diff --git a/pkg/integration/tests/diff/diff.go b/pkg/integration/tests/diff/diff.go index 4bba36de8..e0fc214b2 100644 --- a/pkg/integration/tests/diff/diff.go +++ b/pkg/integration/tests/diff/diff.go @@ -29,7 +29,7 @@ var Diff = NewIntegrationTest(NewIntegrationTestArgs{ Contains("branch-b"), ) input.Press(keys.Universal.DiffingMenu) - input.Menu(Equals("Diffing"), Contains(`diff branch-a`)) + input.Menu().Title(Equals("Diffing")).Select(Contains(`diff branch-a`)).Confirm() assert.CurrentView().Name("localBranches") @@ -51,7 +51,7 @@ var Diff = NewIntegrationTest(NewIntegrationTestArgs{ assert.CurrentView().Name("localBranches") input.Press(keys.Universal.DiffingMenu) - input.Menu(Equals("Diffing"), Contains("reverse diff direction")) + input.Menu().Title(Equals("Diffing")).Select(Contains("reverse diff direction")).Confirm() assert.View("information").Content(Contains("showing output for: git diff branch-a branch-b -R")) assert.MainView().Content(Contains("-second line")) }, diff --git a/pkg/integration/tests/diff/diff_and_apply_patch.go b/pkg/integration/tests/diff/diff_and_apply_patch.go index e963bb296..e6dfe5a97 100644 --- a/pkg/integration/tests/diff/diff_and_apply_patch.go +++ b/pkg/integration/tests/diff/diff_and_apply_patch.go @@ -30,7 +30,7 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Universal.DiffingMenu) - input.Menu(Equals("Diffing"), Equals("diff branch-a")) + input.Menu().Title(Equals("Diffing")).Select(Equals("diff branch-a")).Confirm() assert.CurrentView().Name("localBranches") @@ -52,13 +52,13 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{ input.PrimaryAction() input.Press(keys.Universal.DiffingMenu) - input.Menu(Equals("Diffing"), Contains("exit diff mode")) + input.Menu().Title(Equals("Diffing")).Select(Contains("exit diff mode")).Confirm() assert.View("information").Content(DoesNotContain("building patch")) input.Press(keys.Universal.CreatePatchOptionsMenu) // adding the regex '$' here to distinguish the menu item from the 'apply patch in reverse' item - input.Menu(Equals("Patch Options"), MatchesRegexp("apply patch$")) + input.Menu().Title(Equals("Patch Options")).Select(MatchesRegexp("apply patch$")).Confirm() input.SwitchToFilesView() diff --git a/pkg/integration/tests/diff/diff_commits.go b/pkg/integration/tests/diff/diff_commits.go index efa44d818..e4db05f18 100644 --- a/pkg/integration/tests/diff/diff_commits.go +++ b/pkg/integration/tests/diff/diff_commits.go @@ -28,7 +28,7 @@ var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{ ) input.Press(keys.Universal.DiffingMenu) - input.Menu(Equals("Diffing"), MatchesRegexp(`diff \w+`)) + input.Menu().Title(Equals("Diffing")).Select(MatchesRegexp(`diff \w+`)).Confirm() assert.NotInPopup() @@ -41,7 +41,7 @@ var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{ assert.MainView().Content(Contains("-second line\n-third line")) input.Press(keys.Universal.DiffingMenu) - input.Menu(Equals("Diffing"), Contains("reverse diff direction")) + input.Menu().Title(Equals("Diffing")).Select(Contains("reverse diff direction")).Confirm() assert.NotInPopup() assert.MainView().Content(Contains("+second line\n+third line")) diff --git a/pkg/integration/tests/file/discard_changes.go b/pkg/integration/tests/file/discard_changes.go index 9d88f49e5..e965385ec 100644 --- a/pkg/integration/tests/file/discard_changes.go +++ b/pkg/integration/tests/file/discard_changes.go @@ -84,7 +84,7 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{ for _, file := range files { assert.CurrentView().SelectedLine(Contains(file.status + " " + file.label)) input.Press(keys.Universal.Remove) - input.Menu(Equals(file.menuTitle), Contains("discard all changes")) + input.Menu().Title(Equals(file.menuTitle)).Select(Contains("discard all changes")).Confirm() } } diff --git a/pkg/integration/tests/stash/stash.go b/pkg/integration/tests/stash/stash.go index 996006489..8f1281bc3 100644 --- a/pkg/integration/tests/stash/stash.go +++ b/pkg/integration/tests/stash/stash.go @@ -21,7 +21,7 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Files.ViewStashOptions) - input.Menu(Equals("Stash options"), MatchesRegexp("stash all changes$")) + input.Menu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm() input.Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm() diff --git a/pkg/integration/tests/stash/stash_including_untracked_files.go b/pkg/integration/tests/stash/stash_including_untracked_files.go index b63796bbc..51cdbbc25 100644 --- a/pkg/integration/tests/stash/stash_including_untracked_files.go +++ b/pkg/integration/tests/stash/stash_including_untracked_files.go @@ -22,7 +22,7 @@ var StashIncludingUntrackedFiles = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Files.ViewStashOptions) - input.Menu(Equals("Stash options"), Contains("stash all changes including untracked files")) + input.Menu().Title(Equals("Stash options")).Select(Contains("stash all changes including untracked files")).Confirm() input.Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm() |