1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

move popup assertions into a struct

This commit is contained in:
Jesse Duffield
2022-12-28 11:00:22 +11:00
parent 7aa843c75a
commit 9fef4447b6
33 changed files with 130 additions and 120 deletions

View File

@ -8,7 +8,7 @@ type Actions struct {
func (self *Actions) ContinueMerge() {
self.t.Views().current().Press(self.t.keys.Universal.CreateRebaseOptionsMenu)
self.t.ExpectMenu().
self.t.ExpectPopup().Menu().
Title(Equals("Rebase Options")).
Select(Contains("continue")).
Confirm()

View File

@ -0,0 +1,70 @@
package components
type Popup struct {
t *TestDriver
}
func (self *Popup) Confirmation() *ConfirmationAsserter {
self.inConfirm()
return &ConfirmationAsserter{t: self.t}
}
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"
})
}
func (self *Popup) Prompt() *PromptAsserter {
self.inPrompt()
return &PromptAsserter{t: self.t}
}
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"
})
}
func (self *Popup) Alert() *AlertAsserter {
self.inAlert()
return &AlertAsserter{t: self.t}
}
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"
})
}
func (self *Popup) Menu() *MenuAsserter {
self.inMenu()
return &MenuAsserter{t: self.t}
}
func (self *Popup) inMenu() {
self.t.assertWithRetries(func() (bool, string) {
return self.t.gui.CurrentContext().GetView().Name() == "menu", "Expected popup menu to be focused"
})
}
func (self *Popup) CommitMessagePanel() *CommitMessagePanelAsserter {
self.inCommitMessagePanel()
return &CommitMessagePanelAsserter{t: self.t}
}
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"
})
}

View File

@ -133,76 +133,16 @@ func (self *TestDriver) inListContext() {
})
}
func (self *TestDriver) ExpectConfirmation() *ConfirmationAsserter {
self.inConfirm()
return &ConfirmationAsserter{t: self}
}
func (self *TestDriver) inConfirm() {
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && !currentView.Editable, "Expected confirmation popup to be focused"
})
}
func (self *TestDriver) ExpectPrompt() *PromptAsserter {
self.inPrompt()
return &PromptAsserter{t: self}
}
func (self *TestDriver) inPrompt() {
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && currentView.Editable, "Expected prompt popup to be focused"
})
}
func (self *TestDriver) ExpectAlert() *AlertAsserter {
self.inAlert()
return &AlertAsserter{t: self}
}
func (self *TestDriver) inAlert() {
// basically the same thing as a confirmation popup with the current implementation
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && !currentView.Editable, "Expected alert popup to be focused"
})
}
func (self *TestDriver) ExpectMenu() *MenuAsserter {
self.inMenu()
return &MenuAsserter{t: self}
}
func (self *TestDriver) inMenu() {
self.assertWithRetries(func() (bool, string) {
return self.gui.CurrentContext().GetView().Name() == "menu", "Expected popup menu to be focused"
})
}
func (self *TestDriver) ExpectCommitMessagePanel() *CommitMessagePanelAsserter {
self.inCommitMessagePanel()
return &CommitMessagePanelAsserter{t: self}
}
func (self *TestDriver) inCommitMessagePanel() {
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
return currentView.Name() == "commitMessage", "Expected commit message panel to be focused"
})
}
// for making assertions on lazygit views
func (self *TestDriver) Views() *Views {
return &Views{t: self}
}
// for interacting with popups
func (self *TestDriver) ExpectPopup() *Popup {
return &Popup{t: self}
}
// for making assertions through git itself
func (self *TestDriver) Git() *Git {
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}