2022-12-27 11:21:44 +11:00
|
|
|
package components
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
type PromptDriver struct {
|
2022-12-27 21:35:36 +11:00
|
|
|
t *TestDriver
|
2022-12-27 11:21:44 +11:00
|
|
|
hasCheckedTitle bool
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) getViewDriver() *ViewDriver {
|
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
|
2023-06-03 15:12:31 +10:00
|
|
|
func (self *PromptDriver) Title(expected *TextMatcher) *PromptDriver {
|
2022-12-28 11:27:48 +11:00
|
|
|
self.getViewDriver().Title(expected)
|
2022-12-27 11:21:44 +11:00
|
|
|
|
|
|
|
self.hasCheckedTitle = true
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
// asserts on the text initially present in the prompt
|
2023-06-03 15:12:31 +10:00
|
|
|
func (self *PromptDriver) InitialText(expected *TextMatcher) *PromptDriver {
|
2022-12-28 11:27:48 +11:00
|
|
|
self.getViewDriver().Content(expected)
|
2022-12-27 11:21:44 +11:00
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) Type(value string) *PromptDriver {
|
2022-12-27 21:35:36 +11:00
|
|
|
self.t.typeContent(value)
|
2022-12-27 11:34:41 +11:00
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) Clear() *PromptDriver {
|
2023-02-22 21:57:32 +11:00
|
|
|
self.t.press(ClearKey)
|
2023-02-12 09:53:57 +11:00
|
|
|
|
|
|
|
return self
|
2022-12-27 11:34:41 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) Confirm() {
|
2022-12-27 11:21:44 +11:00
|
|
|
self.checkNecessaryChecksCompleted()
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
self.getViewDriver().PressEnter()
|
2022-12-27 11:21:44 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) Cancel() {
|
2022-12-27 11:21:44 +11:00
|
|
|
self.checkNecessaryChecksCompleted()
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
self.getViewDriver().PressEscape()
|
2022-12-27 11:34:41 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) checkNecessaryChecksCompleted() {
|
2022-12-27 11:34:41 +11:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:12:31 +10:00
|
|
|
func (self *PromptDriver) SuggestionLines(matchers ...*TextMatcher) *PromptDriver {
|
2022-12-27 21:35:36 +11:00
|
|
|
self.t.Views().Suggestions().Lines(matchers...)
|
2022-12-27 11:21:44 +11:00
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:12:31 +10:00
|
|
|
func (self *PromptDriver) SuggestionTopLines(matchers ...*TextMatcher) *PromptDriver {
|
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-28 11:27:48 +11:00
|
|
|
func (self *PromptDriver) ConfirmFirstSuggestion() {
|
2022-12-27 21:35:36 +11:00
|
|
|
self.t.press(self.t.keys.Universal.TogglePanel)
|
|
|
|
self.t.Views().Suggestions().
|
2022-12-27 16:27:36 +11:00
|
|
|
IsFocused().
|
2022-12-28 10:41:42 +11:00
|
|
|
SelectedLineIdx(0).
|
|
|
|
PressEnter()
|
2022-12-27 11:21:44 +11:00
|
|
|
}
|
|
|
|
|
2023-06-03 15:12:31 +10:00
|
|
|
func (self *PromptDriver) ConfirmSuggestion(matcher *TextMatcher) {
|
2022-12-27 21:35:36 +11:00
|
|
|
self.t.press(self.t.keys.Universal.TogglePanel)
|
|
|
|
self.t.Views().Suggestions().
|
2022-12-27 16:27:36 +11:00
|
|
|
IsFocused().
|
2023-02-26 11:49:15 +11:00
|
|
|
NavigateToLine(matcher).
|
2022-12-28 10:41:42 +11:00
|
|
|
PressEnter()
|
2022-12-27 11:21:44 +11:00
|
|
|
}
|