diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-27 11:21:44 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-27 21:26:18 +1100 |
commit | 8052ac4fd6f4ea96fbfb7a3ff16799ba981be82a (patch) | |
tree | 7ad44f3389865072f67bcd3aeb111da3b5ad3822 /pkg/integration | |
parent | c976839a632c61917bcc81dbaea8ec32cf5249e8 (diff) |
add prompt asserter
Diffstat (limited to 'pkg/integration')
18 files changed, 86 insertions, 28 deletions
diff --git a/pkg/integration/components/input.go b/pkg/integration/components/input.go index ed23b6a0d..2d086eba5 100644 --- a/pkg/integration/components/input.go +++ b/pkg/integration/components/input.go @@ -215,17 +215,16 @@ func (self *Input) NavigateToListItem(matcher *matcher) { } } -func (self *Input) InConfirm() *ConfirmationAsserter { +func (self *Input) Confirmation() *ConfirmationAsserter { self.assert.InConfirm() return &ConfirmationAsserter{assert: self.assert, input: self} } -func (self *Input) Prompt(title *matcher, textToType string) { +func (self *Input) Prompt() *PromptAsserter { self.assert.InPrompt() - self.assert.CurrentView().Title(title) - self.Type(textToType) - self.Confirm() + + return &PromptAsserter{assert: self.assert, input: self} } // type some text into a prompt, then switch to the suggestions panel and expect the first diff --git a/pkg/integration/components/prompt_asserter.go b/pkg/integration/components/prompt_asserter.go new file mode 100644 index 000000000..839934aaa --- /dev/null +++ b/pkg/integration/components/prompt_asserter.go @@ -0,0 +1,59 @@ +package components + +type PromptAsserter struct { + assert *Assert + input *Input + hasCheckedTitle bool +} + +func (self *PromptAsserter) getViewAsserter() *ViewAsserter { + return self.assert.View("confirmation") +} + +// asserts that the popup has the expected title +func (self *PromptAsserter) Title(expected *matcher) *PromptAsserter { + self.getViewAsserter().Title(expected) + + self.hasCheckedTitle = true + + return self +} + +// asserts on the text initially present in the prompt +func (self *PromptAsserter) InitialText(expected *matcher) *PromptAsserter { + self.getViewAsserter().Content(expected) + + return self +} + +func (self *PromptAsserter) Confirm() *PromptAsserter { + self.checkNecessaryChecksCompleted() + + self.input.Confirm() + + return self +} + +func (self *PromptAsserter) Cancel() *PromptAsserter { + self.checkNecessaryChecksCompleted() + + self.input.Press(self.input.keys.Universal.Return) + + return self +} + +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) checkNecessaryChecksCompleted() { + if !self.hasCheckedTitle { + self.assert.Fail("You must check the title of a prompt popup by calling Title() before calling Confirm()/Cancel().") + } +} diff --git a/pkg/integration/tests/branch/checkout_by_name.go b/pkg/integration/tests/branch/checkout_by_name.go index d3742e8f9..17fd214af 100644 --- a/pkg/integration/tests/branch/checkout_by_name.go +++ b/pkg/integration/tests/branch/checkout_by_name.go @@ -28,7 +28,7 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Branches.CheckoutBranchByName) - input.Prompt(Equals("Branch name:"), "new-branch") + 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?")) diff --git a/pkg/integration/tests/branch/delete.go b/pkg/integration/tests/branch/delete.go index 0452898db..815d40d45 100644 --- a/pkg/integration/tests/branch/delete.go +++ b/pkg/integration/tests/branch/delete.go @@ -31,7 +31,7 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Universal.Remove) - input.InConfirm(). + input.Confirmation(). Title(Equals("Delete Branch")). Content(Contains("Are you sure you want to delete the branch 'branch-one'?")). Confirm() diff --git a/pkg/integration/tests/branch/rebase.go b/pkg/integration/tests/branch/rebase.go index dc5c87b03..e4f03810e 100644 --- a/pkg/integration/tests/branch/rebase.go +++ b/pkg/integration/tests/branch/rebase.go @@ -31,11 +31,11 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Branches.RebaseBranch) - input.InConfirm(). + input.Confirmation(). Title(Equals("Rebasing")). Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")). Confirm() - input.InConfirm(). + input.Confirmation(). Title(Equals("Auto-merge failed")). Content(Contains("Conflicts!")). Confirm() @@ -51,7 +51,7 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ assert.View("information").Content(Contains("rebasing")) - input.InConfirm(). + input.Confirmation(). Title(Equals("continue")). Content(Contains("all merge conflicts resolved. Continue?")). Confirm() diff --git a/pkg/integration/tests/branch/rebase_and_drop.go b/pkg/integration/tests/branch/rebase_and_drop.go index 8ecb18e23..b1cc408ba 100644 --- a/pkg/integration/tests/branch/rebase_and_drop.go +++ b/pkg/integration/tests/branch/rebase_and_drop.go @@ -36,14 +36,14 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Branches.RebaseBranch) - input.InConfirm(). + input.Confirmation(). 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.InConfirm(). + input.Confirmation(). Title(Equals("Auto-merge failed")). Content(Contains("Conflicts!")). Confirm() @@ -83,7 +83,7 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ assert.CurrentView().Name("mergeConflicts") input.PrimaryAction() - input.InConfirm(). + input.Confirmation(). Title(Equals("continue")). Content(Contains("all merge conflicts resolved. Continue?")). Confirm() diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go index 1359c1d66..31c64664f 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go @@ -47,7 +47,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.InConfirm(). + input.Confirmation(). Title(Equals("Auto-merge failed")). Content(Contains("Conflicts!")). Confirm() @@ -64,7 +64,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.PrimaryAction() - input.InConfirm(). + input.Confirmation(). Title(Equals("continue")). Content(Contains("all merge conflicts resolved. Continue?")). Confirm() diff --git a/pkg/integration/tests/commit/new_branch.go b/pkg/integration/tests/commit/new_branch.go index 1702b0973..c14e48310 100644 --- a/pkg/integration/tests/commit/new_branch.go +++ b/pkg/integration/tests/commit/new_branch.go @@ -30,7 +30,7 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Universal.New) branchName := "my-branch-name" - input.Prompt(Contains("New Branch Name"), branchName) + input.Prompt().Title(Equals("New Branch Name")).Type(branchName).Confirm() assert.CurrentBranchName(branchName) diff --git a/pkg/integration/tests/commit/revert.go b/pkg/integration/tests/commit/revert.go index 63f6b1b96..9527d5640 100644 --- a/pkg/integration/tests/commit/revert.go +++ b/pkg/integration/tests/commit/revert.go @@ -25,7 +25,7 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{ ) input.Press(keys.Commits.RevertCommit) - input.InConfirm(). + input.Confirmation(). Title(Equals("Revert commit")). Content(MatchesRegexp(`Are you sure you want to revert \w+?`)). Confirm() diff --git a/pkg/integration/tests/custom_commands/form_prompts.go b/pkg/integration/tests/custom_commands/form_prompts.go index 9c02f4eef..dbb2b3c8c 100644 --- a/pkg/integration/tests/custom_commands/form_prompts.go +++ b/pkg/integration/tests/custom_commands/form_prompts.go @@ -65,11 +65,11 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{ input.Press("a") - input.Prompt(Equals("Enter a file name"), "my file") + input.Prompt().Title(Equals("Enter a file name")).Type("my file").Confirm() input.Menu(Equals("Choose file content"), Contains("bar")) - input.InConfirm(). + input.Confirmation(). Title(Equals("Are you sure?")). Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). Confirm() diff --git a/pkg/integration/tests/custom_commands/menu_from_command.go b/pkg/integration/tests/custom_commands/menu_from_command.go index c4fe063e2..f130af989 100644 --- a/pkg/integration/tests/custom_commands/menu_from_command.go +++ b/pkg/integration/tests/custom_commands/menu_from_command.go @@ -55,7 +55,7 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu(Equals("Choose commit message"), Contains("bar")) - input.Prompt(Equals("Description"), " my branch") + input.Prompt().Title(Equals("Description")).Type(" my branch").Confirm() input.SwitchToFilesView() diff --git a/pkg/integration/tests/custom_commands/multiple_prompts.go b/pkg/integration/tests/custom_commands/multiple_prompts.go index 060ce04a9..eb20876cf 100644 --- a/pkg/integration/tests/custom_commands/multiple_prompts.go +++ b/pkg/integration/tests/custom_commands/multiple_prompts.go @@ -63,11 +63,11 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{ input.Press("a") - input.Prompt(Equals("Enter a file name"), "myfile") + input.Prompt().Title(Equals("Enter a file name")).Type("myfile").Confirm() input.Menu(Equals("Choose file content"), Contains("bar")) - input.InConfirm(). + input.Confirmation(). Title(Equals("Are you sure?")). Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). Confirm() diff --git a/pkg/integration/tests/file/discard_changes.go b/pkg/integration/tests/file/discard_changes.go index c9a8aa497..9d88f49e5 100644 --- a/pkg/integration/tests/file/discard_changes.go +++ b/pkg/integration/tests/file/discard_changes.go @@ -98,7 +98,7 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{ {status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"}, }) - input.InConfirm(). + input.Confirmation(). Title(Equals("continue")). Content(Contains("all merge conflicts resolved. Continue?")). Cancel() diff --git a/pkg/integration/tests/interactive_rebase/amend_merge.go b/pkg/integration/tests/interactive_rebase/amend_merge.go index 93a577eb9..f1ea39d04 100644 --- a/pkg/integration/tests/interactive_rebase/amend_merge.go +++ b/pkg/integration/tests/interactive_rebase/amend_merge.go @@ -36,7 +36,7 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{ assert.HeadCommitMessage(Contains(mergeCommitMessage)) input.Press(keys.Commits.AmendToCommit) - input.InConfirm(). + input.Confirmation(). Title(Equals("Amend Commit")). Content(Contains("Are you sure you want to amend this commit with your staged files?")). Confirm() diff --git a/pkg/integration/tests/misc/confirm_on_quit.go b/pkg/integration/tests/misc/confirm_on_quit.go index cf0e3235d..5f377eeab 100644 --- a/pkg/integration/tests/misc/confirm_on_quit.go +++ b/pkg/integration/tests/misc/confirm_on_quit.go @@ -17,7 +17,7 @@ var ConfirmOnQuit = NewIntegrationTest(NewIntegrationTestArgs{ assert.CommitCount(0) input.Press(keys.Universal.Quit) - input.InConfirm(). + input.Confirmation(). Title(Equals("")). Content(Contains("Are you sure you want to quit?")). Confirm() diff --git a/pkg/integration/tests/stash/rename.go b/pkg/integration/tests/stash/rename.go index 7088de423..99036b7f6 100644 --- a/pkg/integration/tests/stash/rename.go +++ b/pkg/integration/tests/stash/rename.go @@ -28,7 +28,7 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{ input.NextItem() input.Press(keys.Stash.RenameStash) - input.Prompt(Equals("Rename stash: stash@{1}"), " baz") + input.Prompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm() assert.CurrentView().SelectedLine(Equals("On master: foo baz")) }, diff --git a/pkg/integration/tests/stash/stash.go b/pkg/integration/tests/stash/stash.go index 23ff7e99d..996006489 100644 --- a/pkg/integration/tests/stash/stash.go +++ b/pkg/integration/tests/stash/stash.go @@ -23,7 +23,7 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu(Equals("Stash options"), MatchesRegexp("stash all changes$")) - input.Prompt(Equals("Stash changes"), "my stashed file") + input.Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm() assert.StashCount(1) assert.WorkingTreeFileCount(0) diff --git a/pkg/integration/tests/stash/stash_including_untracked_files.go b/pkg/integration/tests/stash/stash_including_untracked_files.go index d193600df..b63796bbc 100644 --- a/pkg/integration/tests/stash/stash_including_untracked_files.go +++ b/pkg/integration/tests/stash/stash_including_untracked_files.go @@ -24,7 +24,7 @@ var StashIncludingUntrackedFiles = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu(Equals("Stash options"), Contains("stash all changes including untracked files")) - input.Prompt(Equals("Stash changes"), "my stashed file") + input.Prompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm() assert.StashCount(1) assert.WorkingTreeFileCount(0) |