mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-17 01:42:45 +02:00
better test
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/atotto/clipboard"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
||||||
@ -143,6 +144,21 @@ func (self *TestDriver) ExpectPopup() *Popup {
|
|||||||
return &Popup{t: self}
|
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
|
// for making assertions through git itself
|
||||||
func (self *TestDriver) Git() *Git {
|
func (self *TestDriver) Git() *Git {
|
||||||
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}
|
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}
|
||||||
|
@ -64,6 +64,10 @@ func (self *Views) Information() *ViewDriver {
|
|||||||
return self.byName("information")
|
return self.byName("information")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Views) AppStatus() *ViewDriver {
|
||||||
|
return self.byName("appStatus")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Views) Branches() *ViewDriver {
|
func (self *Views) Branches() *ViewDriver {
|
||||||
return self.byName("localBranches")
|
return self.byName("localBranches")
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package patch_building
|
package patch_building
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/atotto/clipboard"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
)
|
)
|
||||||
@ -39,18 +36,18 @@ var BuildPatchAndCopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Lines(
|
Lines(
|
||||||
Contains("M file1").IsSelected(),
|
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.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()
|
t.ExpectClipboard(Contains("diff --git a/file1 b/file1"))
|
||||||
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")
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user