1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

migrate menuFromCommand integration test

This commit is contained in:
Jesse Duffield
2022-08-14 21:18:12 +10:00
parent b2ae651686
commit fed2aaf37f
50 changed files with 96 additions and 86 deletions

View File

@ -52,7 +52,7 @@ func Contains(target string) *matcher {
func Equals(target string) *matcher {
return &matcher{testFn: func(value string) (bool, string) {
return target == value, fmt.Sprintf("Expected '%T' to equal '%T'", value, target)
return target == value, fmt.Sprintf("Expected '%s' to equal '%s'", value, target)
}}
}
@ -123,14 +123,14 @@ func (self *Assert) MatchSelectedLine(matcher *matcher) {
func (self *Assert) InPrompt() {
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && currentView.Editable, fmt.Sprintf("Expected prompt popup to be focused")
return currentView.Name() == "confirmation" && currentView.Editable, "Expected prompt popup to be focused"
})
}
func (self *Assert) InConfirm() {
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
return currentView.Name() == "confirmation" && !currentView.Editable, fmt.Sprintf("Expected confirmation popup to be focused")
return currentView.Name() == "confirmation" && !currentView.Editable, "Expected confirmation popup to be focused"
})
}
@ -138,13 +138,13 @@ func (self *Assert) 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, fmt.Sprintf("Expected alert popup to be focused")
return currentView.Name() == "confirmation" && !currentView.Editable, "Expected alert popup to be focused"
})
}
func (self *Assert) InMenu() {
self.assertWithRetries(func() (bool, string) {
return self.gui.CurrentContext().GetView().Name() == "menu", fmt.Sprintf("Expected popup menu to be focused")
return self.gui.CurrentContext().GetView().Name() == "menu", "Expected popup menu to be focused"
})
}

View File

@ -0,0 +1,74 @@
package custom_commands
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
// NOTE: we're getting a weird offset in the popup prompt for some reason. Not sure what's behind that.
var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Using menuFromCommand prompt type",
ExtraCmdArgs: "",
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
EmptyCommit("foo").
EmptyCommit("bar").
EmptyCommit("baz").
NewBranch("feature/foo")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.CustomCommands = []config.CustomCommand{
{
Key: "a",
Context: "localBranches",
Command: `echo "{{index .PromptResponses 0}} {{index .PromptResponses 1}} {{ .SelectedLocalBranch.Name }}" > output.txt`,
Prompts: []config.CustomCommandPrompt{
{
Type: "menuFromCommand",
Title: "Choose commit message",
Command: `git log --oneline --pretty=%B`,
Filter: `(?P<commit_message>.*)`,
ValueFormat: `{{ .commit_message }}`,
LabelFormat: `{{ .commit_message | yellow }}`,
},
{
Type: "input",
Title: "Description",
InitialValue: `{{ if .SelectedLocalBranch.Name }}Branch: #{{ .SelectedLocalBranch.Name }}{{end}}`,
},
},
},
}
},
Run: func(
shell *Shell,
input *Input,
assert *Assert,
keys config.KeybindingConfig,
) {
assert.WorkingTreeFileCount(0)
input.SwitchToBranchesWindow()
input.PressKeys("a")
assert.InMenu()
assert.MatchCurrentViewTitle(Equals("Choose commit message"))
assert.MatchSelectedLine(Equals("baz"))
input.NextItem()
assert.MatchSelectedLine(Equals("bar"))
input.Confirm()
assert.InPrompt()
assert.MatchCurrentViewTitle(Equals("Description"))
input.Type(" my branch")
input.Confirm()
input.SwitchToFilesWindow()
assert.WorkingTreeFileCount(1)
assert.MatchSelectedLine(Contains("output.txt"))
assert.MatchMainViewContent(Contains("bar Branch: #feature/foo my branch feature/foo"))
},
})

View File

@ -26,6 +26,7 @@ var tests = []*components.IntegrationTest{
interactive_rebase.One,
custom_commands.Basic,
custom_commands.MultiplePrompts,
custom_commands.MenuFromCommand,
}
func GetTests() []*components.IntegrationTest {