summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-01-26 13:25:56 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-01-26 13:25:56 +1100
commitf7f24dbfc198679dbcd2781db644354bf5b40856 (patch)
tree21aaeb6e06ea7e9f9d2d9d20b97b37fca9dffbca
parentc6929c36aeb17c54ffc54e38b80e9f1b27cef309 (diff)
better test
-rw-r--r--pkg/integration/components/test_driver.go16
-rw-r--r--pkg/integration/components/views.go4
-rw-r--r--pkg/integration/tests/patch_building/copy_patch_to_clipboard.go21
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"))
},
})