From 206b2c6f0be8d61fae225dbaa9c2af097ebeae20 Mon Sep 17 00:00:00 2001 From: Yam Liu <1056803+yam-liu@users.noreply.github.com> Date: Thu, 1 Aug 2024 03:51:36 +0000 Subject: [PATCH] Add a unit test case for global context --- .../tests/custom_commands/global_context.go | 61 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 62 insertions(+) create mode 100644 pkg/integration/tests/custom_commands/global_context.go diff --git a/pkg/integration/tests/custom_commands/global_context.go b/pkg/integration/tests/custom_commands/global_context.go new file mode 100644 index 000000000..8f8518559 --- /dev/null +++ b/pkg/integration/tests/custom_commands/global_context.go @@ -0,0 +1,61 @@ +package custom_commands + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var GlobalContext = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Ensure global context works", + 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: "global", + Command: "touch myfile", + ShowOutput: false, + }, + } + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + // commits + t.Views().Commits(). + Focus(). + Press("X") + + t.Views().Files(). + Focus(). + Lines(Contains("myfile")) + + t.Shell().DeleteFile("myfile") + t.GlobalPress(keys.Files.RefreshFiles) + + // branches + t.Views().Branches(). + Focus(). + Press("X") + + t.Views().Files(). + Focus(). + Lines(Contains("myfile")) + + t.Shell().DeleteFile("myfile") + t.GlobalPress(keys.Files.RefreshFiles) + + // files + t.Views().Files(). + Focus(). + Press("X") + + t.Views().Files(). + Focus(). + Lines(Contains("myfile")) + + t.Shell().DeleteFile("myfile") + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 477fdee44..50d68e85c 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -122,6 +122,7 @@ var tests = []*components.IntegrationTest{ custom_commands.DeleteFromHistory, custom_commands.EditHistory, custom_commands.FormPrompts, + custom_commands.GlobalContext, custom_commands.History, custom_commands.MenuFromCommand, custom_commands.MenuFromCommandsOutput,