1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00
lazygit/pkg/integration/components/confirmation_driver.go

54 lines
1.3 KiB
Go
Raw Normal View History

package components
2022-12-28 11:27:48 +11:00
type ConfirmationDriver struct {
2022-12-27 21:35:36 +11:00
t *TestDriver
hasCheckedTitle bool
hasCheckedContent bool
}
2022-12-28 11:27:48 +11:00
func (self *ConfirmationDriver) getViewDriver() *ViewDriver {
2022-12-27 21:35:36 +11: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 11:27:48 +11: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 11:27:48 +11:00
self.getViewDriver().Content(expected)
self.hasCheckedContent = true
return self
}
2022-12-28 11:27:48 +11:00
func (self *ConfirmationDriver) Confirm() {
self.checkNecessaryChecksCompleted()
2022-12-28 11:27:48 +11:00
self.getViewDriver().PressEnter()
}
2022-12-28 11:27:48 +11:00
func (self *ConfirmationDriver) Cancel() {
self.checkNecessaryChecksCompleted()
2022-12-28 11:27:48 +11:00
self.getViewDriver().PressEscape()
}
2023-08-02 00:06:48 +10:00
func (self *ConfirmationDriver) Wait(milliseconds int) *ConfirmationDriver {
self.getViewDriver().Wait(milliseconds)
return self
}
2022-12-28 11:27:48 +11:00
func (self *ConfirmationDriver) checkNecessaryChecksCompleted() {
if !self.hasCheckedContent || !self.hasCheckedTitle {
2022-12-27 21:35:36 +11:00
self.t.Fail("You must both check the content and title of a confirmation popup by calling Title()/Content() before calling Confirm()/Cancel().")
}
}