1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03: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()
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.CurrentView().Title(title)
self.Type(textToType)
self.Confirm()
return &PromptAsserter{assert: self.assert, input: self}
}
// 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().")
}
}