From caca62b89ef4c20cc6c4b78597f71ea25bfa2c62 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 15 Feb 2025 10:52:51 +0100 Subject: [PATCH] Cleanup: simplify and tighten test expectations related to clipboard Change our fake clipboard command to not append a linefeed; that's closer to what the production code does. This allows us to use Equals instead of Contains for checking the clipboard contents. Finally, use FileSystem().FileContent() to assert the clipboard contents, instead of selecting the clipboard file and then checking the diff view. --- .../tests/commit/copy_author_to_clipboard.go | 12 ++---------- .../tests/commit/copy_tag_to_clipboard.go | 13 ++----------- .../tests/commit/paste_commit_message.go | 2 +- .../commit/paste_commit_message_over_existing.go | 2 +- pkg/integration/tests/file/copy_menu.go | 6 +++--- pkg/integration/tests/misc/copy_to_clipboard.go | 11 ++--------- pkg/integration/tests/tag/copy_to_clipboard.go | 12 ++---------- 7 files changed, 13 insertions(+), 45 deletions(-) diff --git a/pkg/integration/tests/commit/copy_author_to_clipboard.go b/pkg/integration/tests/commit/copy_author_to_clipboard.go index 9e182265f..22a731109 100644 --- a/pkg/integration/tests/commit/copy_author_to_clipboard.go +++ b/pkg/integration/tests/commit/copy_author_to_clipboard.go @@ -12,8 +12,7 @@ var CopyAuthorToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ 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" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard" }, SetupRepo: func(shell *Shell) { @@ -36,13 +35,6 @@ var CopyAuthorToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectToast(Equals("Commit author copied to clipboard")) - t.Views().Files(). - Focus(). - Press(keys.Files.RefreshFiles). - Lines( - Contains("clipboard").IsSelected(), - ) - - t.Views().Main().Content(Contains("/John Doe /")) + t.FileSystem().FileContent("clipboard", Equals("John Doe ")) }, }) diff --git a/pkg/integration/tests/commit/copy_tag_to_clipboard.go b/pkg/integration/tests/commit/copy_tag_to_clipboard.go index a88148754..6bcd03483 100644 --- a/pkg/integration/tests/commit/copy_tag_to_clipboard.go +++ b/pkg/integration/tests/commit/copy_tag_to_clipboard.go @@ -12,8 +12,7 @@ var CopyTagToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ 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" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard" }, SetupRepo: func(shell *Shell) { @@ -38,14 +37,6 @@ var CopyTagToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ 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_")) + t.FileSystem().FileContent("clipboard", Equals("tag2\ntag1")) }, }) diff --git a/pkg/integration/tests/commit/paste_commit_message.go b/pkg/integration/tests/commit/paste_commit_message.go index 72edf72af..ab9939e5b 100644 --- a/pkg/integration/tests/commit/paste_commit_message.go +++ b/pkg/integration/tests/commit/paste_commit_message.go @@ -10,7 +10,7 @@ var PasteCommitMessage = NewIntegrationTest(NewIntegrationTestArgs{ ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) { - config.GetUserConfig().OS.CopyToClipboardCmd = "echo {{text}} > ../clipboard" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > ../clipboard" config.GetUserConfig().OS.ReadFromClipboardCmd = "cat ../clipboard" }, SetupRepo: func(shell *Shell) { diff --git a/pkg/integration/tests/commit/paste_commit_message_over_existing.go b/pkg/integration/tests/commit/paste_commit_message_over_existing.go index 049d5acbd..9f0ab259c 100644 --- a/pkg/integration/tests/commit/paste_commit_message_over_existing.go +++ b/pkg/integration/tests/commit/paste_commit_message_over_existing.go @@ -10,7 +10,7 @@ var PasteCommitMessageOverExisting = NewIntegrationTest(NewIntegrationTestArgs{ ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) { - config.GetUserConfig().OS.CopyToClipboardCmd = "echo {{text}} > ../clipboard" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > ../clipboard" config.GetUserConfig().OS.ReadFromClipboardCmd = "cat ../clipboard" }, SetupRepo: func(shell *Shell) { diff --git a/pkg/integration/tests/file/copy_menu.go b/pkg/integration/tests/file/copy_menu.go index 1adb9989c..9b96f8486 100644 --- a/pkg/integration/tests/file/copy_menu.go +++ b/pkg/integration/tests/file/copy_menu.go @@ -17,7 +17,7 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{ ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) { - config.GetUserConfig().OS.CopyToClipboardCmd = "echo {{text}} > clipboard" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard" }, SetupRepo: func(shell *Shell) {}, Run: func(t *TestDriver, keys config.KeybindingConfig) { @@ -100,7 +100,7 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectToast(Equals("File name copied to clipboard")) - expectClipboard(t, Contains("unstaged_file")) + expectClipboard(t, Equals("1-unstaged_file")) }) // Copy file path @@ -114,7 +114,7 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectToast(Equals("File path copied to clipboard")) - expectClipboard(t, Contains("dir/1-unstaged_file")) + expectClipboard(t, Equals("dir/1-unstaged_file")) }) // Selected path diff on a single (unstaged) file diff --git a/pkg/integration/tests/misc/copy_to_clipboard.go b/pkg/integration/tests/misc/copy_to_clipboard.go index 96b628c00..5b4eb731d 100644 --- a/pkg/integration/tests/misc/copy_to_clipboard.go +++ b/pkg/integration/tests/misc/copy_to_clipboard.go @@ -12,7 +12,7 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) { - config.GetUserConfig().OS.CopyToClipboardCmd = "echo {{text}} > clipboard" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard" }, SetupRepo: func(shell *Shell) { @@ -34,13 +34,6 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ t.GlobalPress(keys.Files.RefreshFiles) - // Expect to see the clipboard file with contents - t.Views().Files(). - IsFocused(). - Lines( - Contains("clipboard").IsSelected(), - ) - - t.Views().Main().Content(Contains("branch-a")) + t.FileSystem().FileContent("clipboard", Equals("branch-a")) }, }) diff --git a/pkg/integration/tests/tag/copy_to_clipboard.go b/pkg/integration/tests/tag/copy_to_clipboard.go index 124c94f94..9f6b38359 100644 --- a/pkg/integration/tests/tag/copy_to_clipboard.go +++ b/pkg/integration/tests/tag/copy_to_clipboard.go @@ -10,8 +10,7 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ 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" + config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard" }, SetupRepo: func(shell *Shell) { shell.EmptyCommit("one") @@ -27,13 +26,6 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectToast(Equals("'super.l000ongtag' copied to clipboard")) - t.Views().Files(). - Focus(). - Press(keys.Files.RefreshFiles). - Lines( - Contains("clipboard").IsSelected(), - ) - - t.Views().Main().Content(Contains("super.l000ongtag")) + t.FileSystem().FileContent("clipboard", Equals("super.l000ongtag")) }, })