From d479a41cad6cf5b0f1970242a1ce8cbad07269fc Mon Sep 17 00:00:00 2001 From: Phanindra kumar Paladi Date: Wed, 18 Jan 2023 21:05:40 +0530 Subject: [PATCH] Added Integration testing the copy to clipboard in patchbuilding --- .../patch_building/copy_patch_to_clipboard.go | 55 +++++++++++++++++++ pkg/integration/tests/tests.go | 2 + 2 files changed, 57 insertions(+) create mode 100644 pkg/integration/tests/patch_building/copy_patch_to_clipboard.go diff --git a/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go b/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go new file mode 100644 index 000000000..2ffdaa0d7 --- /dev/null +++ b/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go @@ -0,0 +1,55 @@ +package patch_building + +import ( + "strings" + + "github.com/atotto/clipboard" + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var BuildPatchAndCopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Create a patch from the commits and copy the patch to clipbaord.", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("branch-a") + shell.CreateFileAndAdd("file1", "first line\n") + shell.Commit("first commit") + + shell.NewBranch("branch-b") + shell.UpdateFileAndAdd("file1", "first line\nsecond line\n") + shell.Commit("update") + + shell.Checkout("branch-a") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines( + Contains("branch-a").IsSelected(), + Contains("branch-b"), + ). + Press(keys.Universal.NextItem). + PressEnter(). + PressEnter() + t.Views(). + CommitFiles(). + Lines( + Contains("M file1").IsSelected(), + ). + PressPrimaryAction().Press(keys.Universal.CreatePatchOptionsMenu) + + t.ExpectPopup().Menu().Title(Equals("Patch Options")).Select(Contains("Copy patch to clipboard")).Confirm() + + text, err := clipboard.ReadAll() + if err != nil { + t.Fail(err.Error()) + } + + if !strings.HasPrefix(text, "diff --git a/file1 b/file1") { + t.Fail("Text from clipboard did not match with git diff") + } + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index f7463d0da..634bd6e48 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -21,6 +21,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_path" "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" "github.com/jesseduffield/lazygit/pkg/integration/tests/misc" + "github.com/jesseduffield/lazygit/pkg/integration/tests/patch_building" "github.com/jesseduffield/lazygit/pkg/integration/tests/stash" "github.com/jesseduffield/lazygit/pkg/integration/tests/sync" ) @@ -71,6 +72,7 @@ var tests = []*components.IntegrationTest{ filter_by_path.CliArg, filter_by_path.SelectFile, filter_by_path.TypeFile, + patch_building.BuildPatchAndCopyToClipboard, } func GetTests() []*components.IntegrationTest {