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

84 lines
2.3 KiB
Go
Raw Normal View History

2022-12-28 02:00:22 +02:00
package components
type Popup struct {
t *TestDriver
}
2022-12-28 02:27:48 +02:00
func (self *Popup) Confirmation() *ConfirmationDriver {
2022-12-28 02:00:22 +02:00
self.inConfirm()
2022-12-28 02:27:48 +02:00
return &ConfirmationDriver{t: self.t}
2022-12-28 02:00:22 +02:00
}
func (self *Popup) inConfirm() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && !currentView.Editable, "Expected confirmation popup to be focused"
})
}
2022-12-28 02:27:48 +02:00
func (self *Popup) Prompt() *PromptDriver {
2022-12-28 02:00:22 +02:00
self.inPrompt()
2022-12-28 02:27:48 +02:00
return &PromptDriver{t: self.t}
2022-12-28 02:00:22 +02:00
}
func (self *Popup) inPrompt() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && currentView.Editable, "Expected prompt popup to be focused"
})
}
2022-12-28 02:27:48 +02:00
func (self *Popup) Alert() *AlertDriver {
2022-12-28 02:00:22 +02:00
self.inAlert()
2022-12-28 02:27:48 +02:00
return &AlertDriver{t: self.t}
2022-12-28 02:00:22 +02:00
}
func (self *Popup) inAlert() {
// basically the same thing as a confirmation popup with the current implementation
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && !currentView.Editable, "Expected alert popup to be focused"
})
}
2022-12-28 02:27:48 +02:00
func (self *Popup) Menu() *MenuDriver {
2022-12-28 02:00:22 +02:00
self.inMenu()
2022-12-28 02:27:48 +02:00
return &MenuDriver{t: self.t}
2022-12-28 02:00:22 +02:00
}
func (self *Popup) inMenu() {
self.t.assertWithRetries(func() (bool, string) {
return self.t.gui.CurrentContext().GetView().Name() == "menu", "Expected popup menu to be focused"
})
}
2022-12-28 02:27:48 +02:00
func (self *Popup) CommitMessagePanel() *CommitMessagePanelDriver {
2022-12-28 02:00:22 +02:00
self.inCommitMessagePanel()
2022-12-28 02:27:48 +02:00
return &CommitMessagePanelDriver{t: self.t}
2022-12-28 02:00:22 +02:00
}
func (self *Popup) CommitDescriptionPanel() *CommitMessagePanelDriver {
self.inCommitDescriptionPanel()
return &CommitMessagePanelDriver{t: self.t}
}
2022-12-28 02:00:22 +02:00
func (self *Popup) inCommitMessagePanel() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "commitMessage", "Expected commit message panel to be focused"
})
}
func (self *Popup) inCommitDescriptionPanel() {
self.t.assertWithRetries(func() (bool, string) {
currentView := self.t.gui.CurrentContext().GetView()
return currentView.Name() == "commitDescription", "Expected commit description panel to be focused"
})
}