1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-17 00:18:05 +02:00

add prompt asserter

This commit is contained in:
Jesse Duffield
2022-12-27 11:21:44 +11:00
parent c976839a63
commit 8052ac4fd6
18 changed files with 86 additions and 28 deletions

View File

@ -215,17 +215,16 @@ func (self *Input) NavigateToListItem(matcher *matcher) {
} }
} }
func (self *Input) InConfirm() *ConfirmationAsserter { func (self *Input) Confirmation() *ConfirmationAsserter {
self.assert.InConfirm() self.assert.InConfirm()
return &ConfirmationAsserter{assert: self.assert, input: self} 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.InPrompt()
self.assert.CurrentView().Title(title)
self.Type(textToType) return &PromptAsserter{assert: self.assert, input: self}
self.Confirm()
} }
// type some text into a prompt, then switch to the suggestions panel and expect the first // type some text into a prompt, then switch to the suggestions panel and expect the first

View 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().")
}
}

View File

@ -28,7 +28,7 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Branches.CheckoutBranchByName) 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?")) input.Alert(Equals("Branch not found"), Equals("Branch not found. Create a new branch named new-branch?"))

View File

@ -31,7 +31,7 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{
input.NextItem() input.NextItem()
input.Press(keys.Universal.Remove) input.Press(keys.Universal.Remove)
input.InConfirm(). input.Confirmation().
Title(Equals("Delete Branch")). Title(Equals("Delete Branch")).
Content(Contains("Are you sure you want to delete the branch 'branch-one'?")). Content(Contains("Are you sure you want to delete the branch 'branch-one'?")).
Confirm() Confirm()

View File

@ -31,11 +31,11 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
input.NextItem() input.NextItem()
input.Press(keys.Branches.RebaseBranch) input.Press(keys.Branches.RebaseBranch)
input.InConfirm(). input.Confirmation().
Title(Equals("Rebasing")). Title(Equals("Rebasing")).
Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")). Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")).
Confirm() Confirm()
input.InConfirm(). input.Confirmation().
Title(Equals("Auto-merge failed")). Title(Equals("Auto-merge failed")).
Content(Contains("Conflicts!")). Content(Contains("Conflicts!")).
Confirm() Confirm()
@ -51,7 +51,7 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
assert.View("information").Content(Contains("rebasing")) assert.View("information").Content(Contains("rebasing"))
input.InConfirm(). input.Confirmation().
Title(Equals("continue")). Title(Equals("continue")).
Content(Contains("all merge conflicts resolved. Continue?")). Content(Contains("all merge conflicts resolved. Continue?")).
Confirm() Confirm()

View File

@ -36,14 +36,14 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
input.NextItem() input.NextItem()
input.Press(keys.Branches.RebaseBranch) input.Press(keys.Branches.RebaseBranch)
input.InConfirm(). input.Confirmation().
Title(Equals("Rebasing")). Title(Equals("Rebasing")).
Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")). Content(Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")).
Confirm() Confirm()
assert.View("information").Content(Contains("rebasing")) assert.View("information").Content(Contains("rebasing"))
input.InConfirm(). input.Confirmation().
Title(Equals("Auto-merge failed")). Title(Equals("Auto-merge failed")).
Content(Contains("Conflicts!")). Content(Contains("Conflicts!")).
Confirm() Confirm()
@ -83,7 +83,7 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentView().Name("mergeConflicts") assert.CurrentView().Name("mergeConflicts")
input.PrimaryAction() input.PrimaryAction()
input.InConfirm(). input.Confirmation().
Title(Equals("continue")). Title(Equals("continue")).
Content(Contains("all merge conflicts resolved. Continue?")). Content(Contains("all merge conflicts resolved. Continue?")).
Confirm() Confirm()

View File

@ -47,7 +47,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Commits.PasteCommits) 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(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")). Title(Equals("Auto-merge failed")).
Content(Contains("Conflicts!")). Content(Contains("Conflicts!")).
Confirm() Confirm()
@ -64,7 +64,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
input.NextItem() input.NextItem()
input.PrimaryAction() input.PrimaryAction()
input.InConfirm(). input.Confirmation().
Title(Equals("continue")). Title(Equals("continue")).
Content(Contains("all merge conflicts resolved. Continue?")). Content(Contains("all merge conflicts resolved. Continue?")).
Confirm() Confirm()

View File

@ -30,7 +30,7 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Universal.New) input.Press(keys.Universal.New)
branchName := "my-branch-name" branchName := "my-branch-name"
input.Prompt(Contains("New Branch Name"), branchName) input.Prompt().Title(Equals("New Branch Name")).Type(branchName).Confirm()
assert.CurrentBranchName(branchName) assert.CurrentBranchName(branchName)

View File

@ -25,7 +25,7 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
) )
input.Press(keys.Commits.RevertCommit) input.Press(keys.Commits.RevertCommit)
input.InConfirm(). input.Confirmation().
Title(Equals("Revert commit")). Title(Equals("Revert commit")).
Content(MatchesRegexp(`Are you sure you want to revert \w+?`)). Content(MatchesRegexp(`Are you sure you want to revert \w+?`)).
Confirm() Confirm()

View File

@ -65,11 +65,11 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
input.Press("a") 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.Menu(Equals("Choose file content"), Contains("bar"))
input.InConfirm(). input.Confirmation().
Title(Equals("Are you sure?")). Title(Equals("Are you sure?")).
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
Confirm() Confirm()

View File

@ -55,7 +55,7 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
input.Menu(Equals("Choose commit message"), Contains("bar")) 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() input.SwitchToFilesView()

View File

@ -63,11 +63,11 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{
input.Press("a") 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.Menu(Equals("Choose file content"), Contains("bar"))
input.InConfirm(). input.Confirmation().
Title(Equals("Are you sure?")). Title(Equals("Are you sure?")).
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
Confirm() Confirm()

View File

@ -98,7 +98,7 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
{status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"}, {status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"},
}) })
input.InConfirm(). input.Confirmation().
Title(Equals("continue")). Title(Equals("continue")).
Content(Contains("all merge conflicts resolved. Continue?")). Content(Contains("all merge conflicts resolved. Continue?")).
Cancel() Cancel()

View File

@ -36,7 +36,7 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
assert.HeadCommitMessage(Contains(mergeCommitMessage)) assert.HeadCommitMessage(Contains(mergeCommitMessage))
input.Press(keys.Commits.AmendToCommit) input.Press(keys.Commits.AmendToCommit)
input.InConfirm(). input.Confirmation().
Title(Equals("Amend Commit")). Title(Equals("Amend Commit")).
Content(Contains("Are you sure you want to amend this commit with your staged files?")). Content(Contains("Are you sure you want to amend this commit with your staged files?")).
Confirm() Confirm()

View File

@ -17,7 +17,7 @@ var ConfirmOnQuit = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(0) assert.CommitCount(0)
input.Press(keys.Universal.Quit) input.Press(keys.Universal.Quit)
input.InConfirm(). input.Confirmation().
Title(Equals("")). Title(Equals("")).
Content(Contains("Are you sure you want to quit?")). Content(Contains("Are you sure you want to quit?")).
Confirm() Confirm()

View File

@ -28,7 +28,7 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
input.NextItem() input.NextItem()
input.Press(keys.Stash.RenameStash) 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")) assert.CurrentView().SelectedLine(Equals("On master: foo baz"))
}, },

View File

@ -23,7 +23,7 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{
input.Menu(Equals("Stash options"), MatchesRegexp("stash all changes$")) 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.StashCount(1)
assert.WorkingTreeFileCount(0) assert.WorkingTreeFileCount(0)

View File

@ -24,7 +24,7 @@ var StashIncludingUntrackedFiles = NewIntegrationTest(NewIntegrationTestArgs{
input.Menu(Equals("Stash options"), Contains("stash all changes including untracked files")) 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.StashCount(1)
assert.WorkingTreeFileCount(0) assert.WorkingTreeFileCount(0)