|
| 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 MenuPromptWithKeys = NewIntegrationTest(NewIntegrationTestArgs{ |
| 9 | + Description: "Using a custom command with menu options that have keybindings", |
| 10 | + ExtraCmdArgs: []string{}, |
| 11 | + Skip: false, |
| 12 | + SetupRepo: func(shell *Shell) { |
| 13 | + shell.EmptyCommit("initial commit") |
| 14 | + }, |
| 15 | + SetupConfig: func(cfg *config.AppConfig) { |
| 16 | + cfg.GetUserConfig().CustomCommands = []config.CustomCommand{ |
| 17 | + { |
| 18 | + Key: "a", |
| 19 | + Context: "files", |
| 20 | + Command: `echo {{.Form.Choice | quote}} > result.txt`, |
| 21 | + Prompts: []config.CustomCommandPrompt{ |
| 22 | + { |
| 23 | + Key: "Choice", |
| 24 | + Type: "menu", |
| 25 | + Title: "Choose an option", |
| 26 | + Options: []config.CustomCommandMenuOption{ |
| 27 | + { |
| 28 | + Name: "first", |
| 29 | + Description: "First option", |
| 30 | + Value: "FIRST", |
| 31 | + Key: "1", |
| 32 | + }, |
| 33 | + { |
| 34 | + Name: "second", |
| 35 | + Description: "Second option", |
| 36 | + Value: "SECOND", |
| 37 | + Key: "H", |
| 38 | + }, |
| 39 | + { |
| 40 | + Name: "third", |
| 41 | + Description: "Third option", |
| 42 | + Value: "THIRD", |
| 43 | + Key: "3", |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + } |
| 50 | + }, |
| 51 | + Run: func(t *TestDriver, keys config.KeybindingConfig) { |
| 52 | + t.Views().Files(). |
| 53 | + IsFocused(). |
| 54 | + Press("a") |
| 55 | + |
| 56 | + // Verify the menu appears |
| 57 | + t.ExpectPopup().Menu(). |
| 58 | + Title(Equals("Choose an option")) |
| 59 | + |
| 60 | + // Press 'H' to directly select the second option via its keybinding |
| 61 | + // 'H' is normally a navigation key (ScrollLeft), so this tests that menu item |
| 62 | + // keybindings have proper precedence over non-essential navigation keys |
| 63 | + t.Views().Menu().Press("H") |
| 64 | + |
| 65 | + // After pressing 'H', the menu should close and the command should execute |
| 66 | + t.FileSystem().FileContent("result.txt", Equals("SECOND\n")) |
| 67 | + }, |
| 68 | +}) |
0 commit comments