1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00
lazygit/pkg/integration/components/prompt_asserter.go

85 lines
1.9 KiB
Go
Raw Normal View History

2022-12-27 11:21:44 +11:00
package components
type PromptAsserter struct {
2022-12-27 21:35:36 +11:00
t *TestDriver
2022-12-27 11:21:44 +11:00
hasCheckedTitle bool
}
2022-12-27 15:56:02 +11:00
func (self *PromptAsserter) getViewAsserter() *View {
2022-12-27 21:35:36 +11:00
return self.t.Views().Confirmation()
2022-12-27 11:21:44 +11:00
}
// 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
}
2022-12-27 11:34:41 +11:00
func (self *PromptAsserter) Type(value string) *PromptAsserter {
2022-12-27 21:35:36 +11:00
self.t.typeContent(value)
2022-12-27 11:34:41 +11:00
return self
}
func (self *PromptAsserter) Clear() *PromptAsserter {
panic("Clear method not yet implemented!")
}
func (self *PromptAsserter) Confirm() {
2022-12-27 11:21:44 +11:00
self.checkNecessaryChecksCompleted()
self.getViewAsserter().PressEnter()
2022-12-27 11:21:44 +11:00
}
2022-12-27 11:34:41 +11:00
func (self *PromptAsserter) Cancel() {
2022-12-27 11:21:44 +11:00
self.checkNecessaryChecksCompleted()
self.getViewAsserter().PressEscape()
2022-12-27 11:34:41 +11:00
}
func (self *PromptAsserter) checkNecessaryChecksCompleted() {
if !self.hasCheckedTitle {
2022-12-27 21:35:36 +11:00
self.t.Fail("You must check the title of a prompt popup by calling Title() before calling Confirm()/Cancel().")
2022-12-27 11:34:41 +11:00
}
}
func (self *PromptAsserter) SuggestionLines(matchers ...*matcher) *PromptAsserter {
2022-12-27 21:35:36 +11:00
self.t.Views().Suggestions().Lines(matchers...)
2022-12-27 11:21:44 +11:00
return self
}
2022-12-27 11:34:41 +11:00
func (self *PromptAsserter) SuggestionTopLines(matchers ...*matcher) *PromptAsserter {
2022-12-27 21:35:36 +11:00
self.t.Views().Suggestions().TopLines(matchers...)
2022-12-27 11:21:44 +11:00
return self
}
2022-12-27 11:34:41 +11:00
func (self *PromptAsserter) SelectFirstSuggestion() *PromptAsserter {
2022-12-27 21:35:36 +11:00
self.t.press(self.t.keys.Universal.TogglePanel)
self.t.Views().Suggestions().
IsFocused().
SelectedLineIdx(0)
2022-12-27 11:34:41 +11:00
return self
2022-12-27 11:21:44 +11:00
}
2022-12-27 11:34:41 +11:00
func (self *PromptAsserter) SelectSuggestion(matcher *matcher) *PromptAsserter {
2022-12-27 21:35:36 +11:00
self.t.press(self.t.keys.Universal.TogglePanel)
self.t.Views().Suggestions().
IsFocused().
NavigateToListItem(matcher)
2022-12-27 11:34:41 +11:00
return self
2022-12-27 11:21:44 +11:00
}