mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
refactor prompt handling in integration tests
This commit is contained in:
parent
17140e1d8d
commit
c976839a63
52
pkg/integration/components/confirmation_asserter.go
Normal file
52
pkg/integration/components/confirmation_asserter.go
Normal file
@ -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().")
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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(
|
||||
|
@ -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"))
|
||||
|
||||
|
@ -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"))
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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"))
|
||||
|
@ -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"))
|
||||
|
@ -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"},
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user