Skip to content

Commit 97ccb45

Browse files
committed
Add a test that demonstrates problems with custom menu keybindings
The test shows two problems: a <down> keybinding is not removed from a menu item (the 'y' binding is removed though, which is correct), and keybindings such as 'j' and 'H' don't work. We will fix both of these separately in the following commits.
1 parent 3201695 commit 97ccb45

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package custom_commands
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var CustomCommandsSubmenuWithSpecialKeybindings = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Using custom commands from a custom commands menu with keybindings that conflict with builtin ones",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupRepo: func(shell *Shell) {},
13+
SetupConfig: func(cfg *config.AppConfig) {
14+
cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
15+
{
16+
Key: "x",
17+
Description: "My Custom Commands",
18+
CommandMenu: []config.CustomCommand{
19+
{
20+
Key: "j",
21+
Context: "global",
22+
Command: "echo j",
23+
Output: "popup",
24+
},
25+
{
26+
Key: "H",
27+
Context: "global",
28+
Command: "echo H",
29+
Output: "popup",
30+
},
31+
{
32+
Key: "y",
33+
Context: "global",
34+
Command: "echo y",
35+
Output: "popup",
36+
},
37+
{
38+
Key: "<down>",
39+
Context: "global",
40+
Command: "echo down",
41+
Output: "popup",
42+
},
43+
},
44+
},
45+
}
46+
cfg.GetUserConfig().Keybinding.Universal.ConfirmMenu = "y"
47+
},
48+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
49+
t.Views().Files().
50+
Focus().
51+
IsEmpty().
52+
Press("x").
53+
Tap(func() {
54+
t.ExpectPopup().Menu().
55+
Title(Equals("My Custom Commands")).
56+
Lines(
57+
/* EXPECTED:
58+
Contains("j echo j"),
59+
Contains("H echo H"),
60+
Contains(" echo y"),
61+
Contains(" echo down"),
62+
ACTUAL: */
63+
Contains("j echo j"),
64+
Contains("H echo H"),
65+
Contains(" echo y"),
66+
Contains("<down> echo down"),
67+
)
68+
t.GlobalPress("j")
69+
/* EXPECTED:
70+
t.ExpectPopup().Alert().Title(Equals("echo j")).Content(Equals("j")).Confirm()
71+
ACTUAL: */
72+
// The menu stays open; 'j' didn't trigger the command; instead, it selected the
73+
// next item, which we can confirm by pressing enter:
74+
t.GlobalPress(keys.Universal.ConfirmMenu)
75+
t.ExpectPopup().Alert().Title(Equals("echo H")).Content(Equals("H")).Confirm()
76+
}).
77+
Press("x").
78+
Tap(func() {
79+
t.ExpectPopup().Menu().
80+
Title(Equals("My Custom Commands"))
81+
t.GlobalPress("H")
82+
/* EXPECTED:
83+
t.ExpectPopup().Alert().Title(Equals("echo H")).Content(Equals("H")).Confirm()
84+
ACTUAL: */
85+
// The menu stays open:
86+
t.ExpectPopup().Menu().
87+
Title(Equals("My Custom Commands"))
88+
})
89+
},
90+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ var tests = []*components.IntegrationTest{
170170
custom_commands.BasicCommand,
171171
custom_commands.CheckForConflicts,
172172
custom_commands.CustomCommandsSubmenu,
173+
custom_commands.CustomCommandsSubmenuWithSpecialKeybindings,
173174
custom_commands.FormPrompts,
174175
custom_commands.GlobalContext,
175176
custom_commands.MenuFromCommand,

0 commit comments

Comments
 (0)