mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Merge pull request #2373 from phanithinks/clipboard_patch_option_2357
This commit is contained in:
@ -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")
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package patch_building
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var BuildPatchAndCopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Create a patch from the commits and copy the patch to clipbaord.",
|
||||
ExtraCmdArgs: "",
|
||||
Skip: true,
|
||||
SetupConfig: func(config *config.AppConfig) {},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.NewBranch("branch-a")
|
||||
shell.CreateFileAndAdd("file1", "first line\n")
|
||||
shell.Commit("first commit")
|
||||
|
||||
shell.NewBranch("branch-b")
|
||||
shell.UpdateFileAndAdd("file1", "first line\nsecond line\n")
|
||||
shell.Commit("update")
|
||||
|
||||
shell.Checkout("branch-a")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Branches().
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("branch-a").IsSelected(),
|
||||
Contains("branch-b"),
|
||||
).
|
||||
Press(keys.Universal.NextItem).
|
||||
PressEnter().
|
||||
PressEnter()
|
||||
t.Views().
|
||||
CommitFiles().
|
||||
Lines(
|
||||
Contains("M file1").IsSelected(),
|
||||
).
|
||||
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.ExpectToast(Contains("Patch copied to clipboard"))
|
||||
|
||||
t.ExpectClipboard(Contains("diff --git a/file1 b/file1"))
|
||||
},
|
||||
})
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_path"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/patch_building"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
|
||||
)
|
||||
@ -72,6 +73,7 @@ var tests = []*components.IntegrationTest{
|
||||
filter_by_path.CliArg,
|
||||
filter_by_path.SelectFile,
|
||||
filter_by_path.TypeFile,
|
||||
patch_building.BuildPatchAndCopyToClipboard,
|
||||
}
|
||||
|
||||
func GetTests() []*components.IntegrationTest {
|
||||
|
Reference in New Issue
Block a user