1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/integration/components/confirmation_driver.go

54 lines
1.3 KiB
Go
Raw Normal View History

package components
2022-12-28 02:27:48 +02:00
type ConfirmationDriver struct {
2022-12-27 12:35:36 +02:00
t *TestDriver
hasCheckedTitle bool
hasCheckedContent bool
}
2022-12-28 02:27:48 +02:00
func (self *ConfirmationDriver) getViewDriver() *ViewDriver {
2022-12-27 12:35:36 +02:00
return self.t.Views().Confirmation()
}
// asserts that the confirmation view has the expected title
func (self *ConfirmationDriver) Title(expected *TextMatcher) *ConfirmationDriver {
2022-12-28 02:27:48 +02:00
self.getViewDriver().Title(expected)
self.hasCheckedTitle = true
return self
}
// asserts that the confirmation view has the expected content
func (self *ConfirmationDriver) Content(expected *TextMatcher) *ConfirmationDriver {
2022-12-28 02:27:48 +02:00
self.getViewDriver().Content(expected)
self.hasCheckedContent = true
return self
}
2022-12-28 02:27:48 +02:00
func (self *ConfirmationDriver) Confirm() {
self.checkNecessaryChecksCompleted()
2022-12-28 02:27:48 +02:00
self.getViewDriver().PressEnter()
}
2022-12-28 02:27:48 +02:00
func (self *ConfirmationDriver) Cancel() {
self.checkNecessaryChecksCompleted()
2022-12-28 02:27:48 +02:00
self.getViewDriver().PressEscape()
}
2023-08-01 16:06:48 +02:00
func (self *ConfirmationDriver) Wait(milliseconds int) *ConfirmationDriver {
self.getViewDriver().Wait(milliseconds)
return self
}
2022-12-28 02:27:48 +02:00
func (self *ConfirmationDriver) checkNecessaryChecksCompleted() {
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().")
}
}