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.
This commit is contained in:
Stefan Haller 2025-02-15 10:52:51 +01:00
parent e15e4951ab
commit caca62b89e
7 changed files with 13 additions and 45 deletions

View file

@ -12,8 +12,7 @@ var CopyAuthorToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { SetupConfig: func(config *config.AppConfig) {
// Include delimiters around the text so that we can assert on the entire content config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
config.GetUserConfig().OS.CopyToClipboardCmd = "echo /{{text}}/ > clipboard"
}, },
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {
@ -36,13 +35,6 @@ var CopyAuthorToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectToast(Equals("Commit author copied to clipboard")) t.ExpectToast(Equals("Commit author copied to clipboard"))
t.Views().Files(). t.FileSystem().FileContent("clipboard", Equals("John Doe <john@doe.com>"))
Focus().
Press(keys.Files.RefreshFiles).
Lines(
Contains("clipboard").IsSelected(),
)
t.Views().Main().Content(Contains("/John Doe <john@doe.com>/"))
}, },
}) })

View file

@ -12,8 +12,7 @@ var CopyTagToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { SetupConfig: func(config *config.AppConfig) {
// Include delimiters around the text so that we can assert on the entire content config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
config.GetUserConfig().OS.CopyToClipboardCmd = "echo _{{text}}_ > clipboard"
}, },
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {
@ -38,14 +37,6 @@ var CopyTagToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectToast(Equals("Commit tags copied to clipboard")) t.ExpectToast(Equals("Commit tags copied to clipboard"))
t.Views().Files(). t.FileSystem().FileContent("clipboard", Equals("tag2\ntag1"))
Focus().
Press(keys.Files.RefreshFiles).
Lines(
Contains("clipboard").IsSelected(),
)
t.Views().Main().Content(Contains("+_tag2"))
t.Views().Main().Content(Contains("+tag1_"))
}, },
}) })

View file

@ -10,7 +10,7 @@ var PasteCommitMessage = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { 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" config.GetUserConfig().OS.ReadFromClipboardCmd = "cat ../clipboard"
}, },
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {

View file

@ -10,7 +10,7 @@ var PasteCommitMessageOverExisting = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { 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" config.GetUserConfig().OS.ReadFromClipboardCmd = "cat ../clipboard"
}, },
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {

View file

@ -17,7 +17,7 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().OS.CopyToClipboardCmd = "echo {{text}} > clipboard" config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
}, },
SetupRepo: func(shell *Shell) {}, SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) { Run: func(t *TestDriver, keys config.KeybindingConfig) {
@ -100,7 +100,7 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectToast(Equals("File name copied to clipboard")) t.ExpectToast(Equals("File name copied to clipboard"))
expectClipboard(t, Contains("unstaged_file")) expectClipboard(t, Equals("1-unstaged_file"))
}) })
// Copy file path // Copy file path
@ -114,7 +114,7 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectToast(Equals("File path copied to clipboard")) 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 // Selected path diff on a single (unstaged) file

View file

@ -12,7 +12,7 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().OS.CopyToClipboardCmd = "echo {{text}} > clipboard" config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
}, },
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {
@ -34,13 +34,6 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
t.GlobalPress(keys.Files.RefreshFiles) t.GlobalPress(keys.Files.RefreshFiles)
// Expect to see the clipboard file with contents t.FileSystem().FileContent("clipboard", Equals("branch-a"))
t.Views().Files().
IsFocused().
Lines(
Contains("clipboard").IsSelected(),
)
t.Views().Main().Content(Contains("branch-a"))
}, },
}) })

View file

@ -10,8 +10,7 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{}, ExtraCmdArgs: []string{},
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) { SetupConfig: func(config *config.AppConfig) {
// Include delimiters around the text so that we can assert on the entire content config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
config.GetUserConfig().OS.CopyToClipboardCmd = "echo _{{text}}_ > clipboard"
}, },
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {
shell.EmptyCommit("one") shell.EmptyCommit("one")
@ -27,13 +26,6 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectToast(Equals("'super.l000ongtag' copied to clipboard")) t.ExpectToast(Equals("'super.l000ongtag' copied to clipboard"))
t.Views().Files(). t.FileSystem().FileContent("clipboard", Equals("super.l000ongtag"))
Focus().
Press(keys.Files.RefreshFiles).
Lines(
Contains("clipboard").IsSelected(),
)
t.Views().Main().Content(Contains("super.l000ongtag"))
}, },
}) })