1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-11 01:20:48 +02:00
Files
.devcontainer
.github
.vscode
cmd
demo
docs
pkg
app
cheatsheet
commands
common
config
constants
env
fakes
gui
i18n
integration
clients
components
tests
bisect
branch
cherry_pick
commit
config
conflicts
custom_commands
basic_cmd_at_runtime.go
basic_cmd_from_config.go
check_for_conflicts.go
complex_cmd_at_runtime.go
form_prompts.go
history.go
menu_from_command.go
menu_from_commands_output.go
multiple_prompts.go
omit_from_history.go
suggestions_command.go
suggestions_preset.go
demo
diff
file
filter_and_search
filter_by_author
filter_by_path
interactive_rebase
misc
patch_building
reflog
shared
staging
stash
submodule
sync
tag
ui
undo
worktree
test_list.go
test_list_generator.go
tests.go
types
README.md
jsonschema
logs
snake
tasks
theme
updates
utils
schema
scripts
test
vendor
.editorconfig
.gitignore
.golangci.yml
.goreleaser.yml
CODE-OF-CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
main.go
lazygit/pkg/integration/tests/custom_commands/history.go
Stefan Haller 6c6201ab04 Fix order problems when saving custom commands history
This fixes two problems:
- each time the custom commands panel was opened, the history of commands would
  be shown in reversed order compared to last time. (The reason is that
  lo.Reverse modifies the slice in place rather than just returning a new,
  reversed slice.)
- when executing a previous command again (either by typing it in again, or by
  picking it from the history), it should move to the beginning of the history,
  but didn't.

We fix this by storing the history in reversed order (as the user sees it in
the panel), this makes the logic simpler. We just have to prepend rather
than append newly added commands now.

While this is theoretically a breaking change, it's not worth bothering because
the order was wrong for existing users in 50% of the cases anyway.
2024-02-16 13:31:37 +01:00

61 lines
1.5 KiB
Go

package custom_commands
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var History = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Test that the custom commands history is saved correctly",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {},
SetupConfig: func(cfg *config.AppConfig) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.GlobalPress(keys.Universal.ExecuteCustomCommand)
t.ExpectPopup().Prompt().
Title(Equals("Custom command:")).
Type("echo 1").
Confirm()
t.GlobalPress(keys.Universal.ExecuteCustomCommand)
t.ExpectPopup().Prompt().
Title(Equals("Custom command:")).
SuggestionLines(Contains("1")).
Type("echo 2").
Confirm()
t.GlobalPress(keys.Universal.ExecuteCustomCommand)
t.ExpectPopup().Prompt().
Title(Equals("Custom command:")).
SuggestionLines(
// "echo 2" was typed last, so it should come first
Contains("2"),
Contains("1"),
).
Type("echo 3").
Confirm()
t.GlobalPress(keys.Universal.ExecuteCustomCommand)
t.ExpectPopup().Prompt().
Title(Equals("Custom command:")).
SuggestionLines(
Contains("3"),
Contains("2"),
Contains("1"),
).
Type("echo 1").
Confirm()
// Executing a command again should move it to the front:
t.GlobalPress(keys.Universal.ExecuteCustomCommand)
t.ExpectPopup().Prompt().
Title(Equals("Custom command:")).
SuggestionLines(
Contains("1"),
Contains("3"),
Contains("2"),
)
},
})