1
0
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:
Jesse Duffield 2022-12-27 10:50:00 +11:00
parent 17140e1d8d
commit c976839a63
12 changed files with 114 additions and 25 deletions

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

View File

@ -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) {

View File

@ -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(

View File

@ -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"))

View File

@ -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"))

View File

@ -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)

View File

@ -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(

View File

@ -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"))

View 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"))

View File

@ -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"},

View File

@ -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)

View File

@ -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()
},
})