1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03: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) {