From 632695f71c573888d65464fbc8aa8abe681e0398 Mon Sep 17 00:00:00 2001 From: Bruno Jesus Date: Tue, 28 Jan 2025 00:34:57 +0000 Subject: [PATCH] Integration tests for copy tags to clipboard Adds integration test in order to confirm if tags are being properly sent to the clipboard --- .../tests/commit/copy_tag_to_clipboard.go | 51 +++++++++++++++++++ .../tests/tag/copy_to_clipboard.go | 39 ++++++++++++++ pkg/integration/tests/test_list.go | 2 + 3 files changed, 92 insertions(+) create mode 100644 pkg/integration/tests/commit/copy_tag_to_clipboard.go create mode 100644 pkg/integration/tests/tag/copy_to_clipboard.go diff --git a/pkg/integration/tests/commit/copy_tag_to_clipboard.go b/pkg/integration/tests/commit/copy_tag_to_clipboard.go new file mode 100644 index 000000000..a88148754 --- /dev/null +++ b/pkg/integration/tests/commit/copy_tag_to_clipboard.go @@ -0,0 +1,51 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +// We're emulating the clipboard by writing to a file called clipboard + +var CopyTagToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Copy a commit tag to the clipboard", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + // Include delimiters around the text so that we can assert on the entire content + config.GetUserConfig().OS.CopyToClipboardCmd = "echo _{{text}}_ > clipboard" + }, + + SetupRepo: func(shell *Shell) { + shell.SetAuthor("John Doe", "john@doe.com") + shell.EmptyCommit("commit") + shell.CreateLightweightTag("tag1", "HEAD") + shell.CreateLightweightTag("tag2", "HEAD") + }, + + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit").IsSelected(), + ). + Press(keys.Commits.CopyCommitAttributeToClipboard) + + t.ExpectPopup().Menu(). + Title(Equals("Copy to clipboard")). + Select(Contains("Commit tags")). + Confirm() + + t.ExpectToast(Equals("Commit tags copied to clipboard")) + + t.Views().Files(). + Focus(). + Press(keys.Files.RefreshFiles). + Lines( + Contains("clipboard").IsSelected(), + ) + + t.Views().Main().Content(Contains("+_tag2")) + t.Views().Main().Content(Contains("+tag1_")) + }, +}) diff --git a/pkg/integration/tests/tag/copy_to_clipboard.go b/pkg/integration/tests/tag/copy_to_clipboard.go new file mode 100644 index 000000000..f0176df9a --- /dev/null +++ b/pkg/integration/tests/tag/copy_to_clipboard.go @@ -0,0 +1,39 @@ +package tag + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Copy the tag to the clipboard", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + // Include delimiters around the text so that we can assert on the entire content + config.GetUserConfig().OS.CopyToClipboardCmd = "echo _{{text}}_ > clipboard" + }, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.CreateLightweightTag("tag1", "HEAD") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Tags(). + Focus(). + Lines( + Contains("tag").IsSelected(), + ). + Press(keys.Universal.CopyToClipboard) + + t.ExpectToast(Equals("'tag1' copied to clipboard")) + + t.Views().Files(). + Focus(). + Press(keys.Files.RefreshFiles). + Lines( + Contains("clipboard").IsSelected(), + ) + + t.Views().Main().Content(Contains("_tag1_")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 0736677a8..8b520e9e4 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -93,6 +93,7 @@ var tests = []*components.IntegrationTest{ commit.CommitWithNonMatchingBranchName, commit.CommitWithPrefix, commit.CopyAuthorToClipboard, + commit.CopyTagToClipboard, commit.CreateAmendCommit, commit.CreateFixupCommitInBranchStack, commit.CreateTag, @@ -351,6 +352,7 @@ var tests = []*components.IntegrationTest{ sync.RenameBranchAndPull, tag.Checkout, tag.CheckoutWhenBranchWithSameNameExists, + tag.CopyToClipboard, tag.CreateWhileCommitting, tag.CrudAnnotated, tag.CrudLightweight,