diff --git a/pkg/integration/components/confirmation_asserter.go b/pkg/integration/components/confirmation_asserter.go new file mode 100644 index 000000000..fa11e814f --- /dev/null +++ b/pkg/integration/components/confirmation_asserter.go @@ -0,0 +1,52 @@ +package components + +type ConfirmationAsserter struct { + assert *Assert + input *Input + hasCheckedTitle bool + hasCheckedContent bool +} + +func (self *ConfirmationAsserter) getViewAsserter() *ViewAsserter { + return self.assert.View("confirmation") +} + +// asserts that the confirmation view has the expected title +func (self *ConfirmationAsserter) Title(expected *matcher) *ConfirmationAsserter { + self.getViewAsserter().Title(expected) + + self.hasCheckedTitle = true + + return self +} + +// asserts that the confirmation view has the expected content +func (self *ConfirmationAsserter) Content(expected *matcher) *ConfirmationAsserter { + self.getViewAsserter().Content(expected) + + self.hasCheckedContent = true + + return self +} + +func (self *ConfirmationAsserter) Confirm() *ConfirmationAsserter { + self.checkNecessaryChecksCompleted() + + self.input.Confirm() + + return self +} + +func (self *ConfirmationAsserter) Cancel() *ConfirmationAsserter { + self.checkNecessaryChecksCompleted() + + self.input.Press(self.input.keys.Universal.Return) + + return self +} + +func (self *ConfirmationAsserter) 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/input.go b/pkg/integration/components/input.go index 39f1991c1..ed23b6a0d 100644 --- a/pkg/integration/components/input.go +++ b/pkg/integration/components/input.go @@ -215,18 +215,10 @@ func (self *Input) NavigateToListItem(matcher *matcher) { } } -func (self *Input) AcceptConfirmation(title *matcher, content *matcher) { +func (self *Input) InConfirm() *ConfirmationAsserter { self.assert.InConfirm() - self.assert.CurrentView().Title(title) - self.assert.CurrentView().Content(content) - self.Confirm() -} -func (self *Input) DenyConfirmation(title *matcher, content *matcher) { - self.assert.InConfirm() - self.assert.CurrentView().Title(title) - self.assert.CurrentView().Content(content) - self.Cancel() + return &ConfirmationAsserter{assert: self.assert, input: self} } func (self *Input) Prompt(title *matcher, textToType string) { diff --git a/pkg/integration/tests/branch/delete.go b/pkg/integration/tests/branch/delete.go index 01bd4edda..0452898db 100644 --- a/pkg/integration/tests/branch/delete.go +++ b/pkg/integration/tests/branch/delete.go @@ -31,7 +31,10 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Universal.Remove) - input.AcceptConfirmation(Equals("Delete Branch"), Contains("Are you sure you want to delete the branch 'branch-one'?")) + input.InConfirm(). + Title(Equals("Delete Branch")). + Content(Contains("Are you sure you want to delete the branch 'branch-one'?")). + Confirm() assert.CurrentView().Name("localBranches"). Lines( diff --git a/pkg/integration/tests/branch/rebase.go b/pkg/integration/tests/branch/rebase.go index 860331215..dc5c87b03 100644 --- a/pkg/integration/tests/branch/rebase.go +++ b/pkg/integration/tests/branch/rebase.go @@ -31,8 +31,14 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Branches.RebaseBranch) - input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")) - input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) + input.InConfirm(). + Title(Equals("Rebasing")). + Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")). + Confirm() + input.InConfirm(). + Title(Equals("Auto-merge failed")). + Content(Contains("Conflicts!")). + Confirm() assert.CurrentView().Name("files").SelectedLine(Contains("file")) @@ -45,7 +51,10 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ assert.View("information").Content(Contains("rebasing")) - input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) + input.InConfirm(). + Title(Equals("continue")). + Content(Contains("all merge conflicts resolved. Continue?")). + Confirm() assert.View("information").Content(DoesNotContain("rebasing")) diff --git a/pkg/integration/tests/branch/rebase_and_drop.go b/pkg/integration/tests/branch/rebase_and_drop.go index 2ef65c3aa..8ecb18e23 100644 --- a/pkg/integration/tests/branch/rebase_and_drop.go +++ b/pkg/integration/tests/branch/rebase_and_drop.go @@ -36,11 +36,17 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Branches.RebaseBranch) - input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")) + input.InConfirm(). + Title(Equals("Rebasing")). + 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")) - input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) + input.InConfirm(). + Title(Equals("Auto-merge failed")). + Content(Contains("Conflicts!")). + Confirm() assert.CurrentView(). Name("files"). @@ -77,7 +83,10 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ assert.CurrentView().Name("mergeConflicts") input.PrimaryAction() - input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) + input.InConfirm(). + Title(Equals("continue")). + Content(Contains("all merge conflicts resolved. Continue?")). + Confirm() assert.View("information").Content(DoesNotContain("rebasing")) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go index 4ed310e1d..1359c1d66 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go @@ -47,7 +47,10 @@ 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.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) + input.InConfirm(). + Title(Equals("Auto-merge failed")). + Content(Contains("Conflicts!")). + Confirm() assert.CurrentView().Name("files") assert.CurrentView().SelectedLine(Contains("file")) @@ -61,7 +64,10 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.PrimaryAction() - input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) + input.InConfirm(). + Title(Equals("continue")). + Content(Contains("all merge conflicts resolved. Continue?")). + Confirm() assert.CurrentView().Name("files") assert.WorkingTreeFileCount(0) diff --git a/pkg/integration/tests/commit/revert.go b/pkg/integration/tests/commit/revert.go index a9bd6373a..63f6b1b96 100644 --- a/pkg/integration/tests/commit/revert.go +++ b/pkg/integration/tests/commit/revert.go @@ -25,7 +25,10 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{ ) input.Press(keys.Commits.RevertCommit) - input.AcceptConfirmation(Equals("Revert commit"), MatchesRegexp(`Are you sure you want to revert \w+?`)) + input.InConfirm(). + Title(Equals("Revert commit")). + Content(MatchesRegexp(`Are you sure you want to revert \w+?`)). + Confirm() assert.CurrentView().Name("commits"). Lines( diff --git a/pkg/integration/tests/custom_commands/form_prompts.go b/pkg/integration/tests/custom_commands/form_prompts.go index 8651efd39..9c02f4eef 100644 --- a/pkg/integration/tests/custom_commands/form_prompts.go +++ b/pkg/integration/tests/custom_commands/form_prompts.go @@ -69,7 +69,10 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu(Equals("Choose file content"), Contains("bar")) - input.AcceptConfirmation(Equals("Are you sure?"), Equals("Are you REALLY sure you want to make this file? Up to you buddy.")) + input.InConfirm(). + Title(Equals("Are you sure?")). + Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). + Confirm() assert.WorkingTreeFileCount(1) assert.CurrentView().SelectedLine(Contains("my file")) diff --git a/pkg/integration/tests/custom_commands/multiple_prompts.go b/pkg/integration/tests/custom_commands/multiple_prompts.go index f3aa04728..060ce04a9 100644 --- a/pkg/integration/tests/custom_commands/multiple_prompts.go +++ b/pkg/integration/tests/custom_commands/multiple_prompts.go @@ -67,7 +67,10 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu(Equals("Choose file content"), Contains("bar")) - input.AcceptConfirmation(Equals("Are you sure?"), Equals("Are you REALLY sure you want to make this file? Up to you buddy.")) + input.InConfirm(). + Title(Equals("Are you sure?")). + Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). + Confirm() assert.WorkingTreeFileCount(1) assert.CurrentView().SelectedLine(Contains("myfile")) diff --git a/pkg/integration/tests/file/discard_changes.go b/pkg/integration/tests/file/discard_changes.go index e44bb45d7..c9a8aa497 100644 --- a/pkg/integration/tests/file/discard_changes.go +++ b/pkg/integration/tests/file/discard_changes.go @@ -98,7 +98,10 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{ {status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"}, }) - input.DenyConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) + input.InConfirm(). + Title(Equals("continue")). + Content(Contains("all merge conflicts resolved. Continue?")). + Cancel() discardOneByOne([]statusFile{ {status: "MD", label: "change-delete.txt", menuTitle: "change-delete.txt"}, diff --git a/pkg/integration/tests/interactive_rebase/amend_merge.go b/pkg/integration/tests/interactive_rebase/amend_merge.go index 449d5f614..93a577eb9 100644 --- a/pkg/integration/tests/interactive_rebase/amend_merge.go +++ b/pkg/integration/tests/interactive_rebase/amend_merge.go @@ -36,7 +36,10 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{ assert.HeadCommitMessage(Contains(mergeCommitMessage)) input.Press(keys.Commits.AmendToCommit) - input.AcceptConfirmation(Equals("Amend Commit"), Contains("Are you sure you want to amend this commit with your staged files?")) + input.InConfirm(). + Title(Equals("Amend Commit")). + Content(Contains("Are you sure you want to amend this commit with your staged files?")). + Confirm() // assuring we haven't added a brand new commit assert.CommitCount(3) diff --git a/pkg/integration/tests/misc/confirm_on_quit.go b/pkg/integration/tests/misc/confirm_on_quit.go index 183f7dd0b..cf0e3235d 100644 --- a/pkg/integration/tests/misc/confirm_on_quit.go +++ b/pkg/integration/tests/misc/confirm_on_quit.go @@ -17,6 +17,9 @@ var ConfirmOnQuit = NewIntegrationTest(NewIntegrationTestArgs{ assert.CommitCount(0) input.Press(keys.Universal.Quit) - input.AcceptConfirmation(Equals(""), Contains("Are you sure you want to quit?")) + input.InConfirm(). + Title(Equals("")). + Content(Contains("Are you sure you want to quit?")). + Confirm() }, })