mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-10 11:10:18 +02:00
add prompt asserter
This commit is contained in:
parent
c976839a63
commit
8052ac4fd6
@ -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
|
||||
|
59
pkg/integration/components/prompt_asserter.go
Normal file
59
pkg/integration/components/prompt_asserter.go
Normal file
@ -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().")
|
||||
}
|
||||
}
|
@ -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?"))
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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"))
|
||||
},
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user