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:
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) {
|
||||
|
Reference in New Issue
Block a user