From f7f24dbfc198679dbcd2781db644354bf5b40856 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 26 Jan 2023 13:25:56 +1100 Subject: better test --- pkg/integration/components/test_driver.go | 16 ++++++++++++++++ pkg/integration/components/views.go | 4 ++++ .../tests/patch_building/copy_patch_to_clipboard.go | 21 +++++++++------------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pkg/integration/components/test_driver.go b/pkg/integration/components/test_driver.go index 5f2e15435..1128de3f5 100644 --- a/pkg/integration/components/test_driver.go +++ b/pkg/integration/components/test_driver.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "github.com/atotto/clipboard" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" @@ -143,6 +144,21 @@ func (self *TestDriver) ExpectPopup() *Popup { return &Popup{t: self} } +func (self *TestDriver) ExpectToast(matcher *matcher) { + self.Views().AppStatus().Content(matcher) +} + +func (self *TestDriver) ExpectClipboard(matcher *matcher) { + self.assertWithRetries(func() (bool, string) { + text, err := clipboard.ReadAll() + if err != nil { + return false, "Error occured when reading from clipboard: " + err.Error() + } + ok, _ := matcher.test(text) + return ok, fmt.Sprintf("Expected clipboard to match %s, but got %s", matcher.name(), text) + }) +} + // for making assertions through git itself func (self *TestDriver) Git() *Git { return &Git{assertionHelper: self.assertionHelper, shell: self.shell} diff --git a/pkg/integration/components/views.go b/pkg/integration/components/views.go index 906c17f4f..5641f1cd4 100644 --- a/pkg/integration/components/views.go +++ b/pkg/integration/components/views.go @@ -64,6 +64,10 @@ func (self *Views) Information() *ViewDriver { return self.byName("information") } +func (self *Views) AppStatus() *ViewDriver { + return self.byName("appStatus") +} + func (self *Views) Branches() *ViewDriver { return self.byName("localBranches") } diff --git a/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go b/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go index 1e2ff0122..0a0193994 100644 --- a/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go +++ b/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go @@ -1,9 +1,6 @@ package patch_building import ( - "strings" - - "github.com/atotto/clipboard" "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) @@ -39,18 +36,18 @@ var BuildPatchAndCopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("M file1").IsSelected(), ). - PressPrimaryAction().Press(keys.Universal.CreatePatchOptionsMenu) + PressPrimaryAction() + + t.Views().Information().Content(Contains("building patch")) + + t.Views(). + CommitFiles(). + Press(keys.Universal.CreatePatchOptionsMenu) t.ExpectPopup().Menu().Title(Equals("Patch Options")).Select(Contains("copy patch to clipboard")).Confirm() - t.Wait(1000) + t.ExpectToast(Contains("Patch copied to clipboard")) - 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") - } + t.ExpectClipboard(Contains("diff --git a/file1 b/file1")) }, }) -- cgit v1.2.3