mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
better test
This commit is contained in:
parent
c6929c36ae
commit
f7f24dbfc1
@ -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}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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"))
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user