1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-21 12:16:54 +02:00
lazygit/pkg/integration/tests/custom_commands/show_output_in_panel.go
Stefan Haller 22a38c9f50 Add property outputTitle to CustomCommand
It can optionally be used to set the title of the panel that shows the output of
a command (when showOutput is true). If left unset, the command string is used
as the title.
2024-05-20 21:02:49 +02:00

58 lines
1.5 KiB
Go

package custom_commands
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ShowOutputInPanel = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Run a command and show the output in a panel",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("my change")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.CustomCommands = []config.CustomCommand{
{
Key: "X",
Context: "commits",
Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
ShowOutput: true,
},
{
Key: "Y",
Context: "commits",
Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
ShowOutput: true,
OutputTitle: "Subject of commit {{ .SelectedLocalCommit.Hash }}",
},
}
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("my change").IsSelected(),
).
Press("X")
t.ExpectPopup().Alert().
// Uses cmd string as title if no outputTitle is provided
Title(Equals("printf '%s' 'my change'")).
Content(Equals("my change")).
Confirm()
t.Views().Commits().
Press("Y")
hash := t.Git().GetCommitHash("HEAD")
t.ExpectPopup().Alert().
// Uses provided outputTitle with template fields resolved
Title(Equals(fmt.Sprintf("Subject of commit %s", hash))).
Content(Equals("my change"))
},
})