1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-08 04:04:22 +02:00
lazygit/pkg/integration/components/alert_driver.go

48 lines
1.1 KiB
Go
Raw Normal View History

2022-12-27 02:34:41 +02:00
package components
2022-12-28 02:27:48 +02:00
type AlertDriver struct {
2022-12-27 12:35:36 +02:00
t *TestDriver
2022-12-27 02:34:41 +02:00
hasCheckedTitle bool
hasCheckedContent bool
}
2022-12-28 02:27:48 +02:00
func (self *AlertDriver) getViewDriver() *ViewDriver {
2022-12-27 12:35:36 +02:00
return self.t.Views().Confirmation()
2022-12-27 02:34:41 +02:00
}
// asserts that the alert view has the expected title
func (self *AlertDriver) Title(expected *TextMatcher) *AlertDriver {
2022-12-28 02:27:48 +02:00
self.getViewDriver().Title(expected)
2022-12-27 02:34:41 +02:00
self.hasCheckedTitle = true
return self
}
// asserts that the alert view has the expected content
func (self *AlertDriver) Content(expected *TextMatcher) *AlertDriver {
2022-12-28 02:27:48 +02:00
self.getViewDriver().Content(expected)
2022-12-27 02:34:41 +02:00
self.hasCheckedContent = true
return self
}
2022-12-28 02:27:48 +02:00
func (self *AlertDriver) Confirm() {
2022-12-27 02:34:41 +02:00
self.checkNecessaryChecksCompleted()
2022-12-28 02:27:48 +02:00
self.getViewDriver().PressEnter()
2022-12-27 02:34:41 +02:00
}
2022-12-28 02:27:48 +02:00
func (self *AlertDriver) Cancel() {
2022-12-27 02:34:41 +02:00
self.checkNecessaryChecksCompleted()
2022-12-28 02:27:48 +02:00
self.getViewDriver().PressEscape()
2022-12-27 02:34:41 +02:00
}
2022-12-28 02:27:48 +02:00
func (self *AlertDriver) checkNecessaryChecksCompleted() {
2022-12-27 02:34:41 +02:00
if !self.hasCheckedContent || !self.hasCheckedTitle {
2022-12-27 12:35:36 +02:00
self.t.Fail("You must both check the content and title of a confirmation popup by calling Title()/Content() before calling Confirm()/Cancel().")
2022-12-27 02:34:41 +02:00
}
}