1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/integration/tests/diff/diff_and_apply_patch.go

79 lines
2.3 KiB
Go
Raw Normal View History

2022-12-21 13:52:23 +02:00
package diff
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Create a patch from the diff between two branches and apply the patch.",
ExtraCmdArgs: "",
Skip: false,
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")
},
2022-12-27 12:47:37 +02:00
Run: func(t *TestDriver, keys config.KeybindingConfig) {
2022-12-27 12:35:36 +02:00
t.Views().Branches().
Focus().
Lines(
Contains("branch-a"),
Contains("branch-b"),
).
Press(keys.Universal.DiffingMenu)
2022-12-21 13:52:23 +02:00
2022-12-28 02:00:22 +02:00
t.ExpectPopup().Menu().Title(Equals("Diffing")).Select(Equals("diff branch-a")).Confirm()
2022-12-27 12:35:36 +02:00
t.Views().Information().Content(Contains("showing output for: git diff branch-a branch-a"))
2022-12-21 13:52:23 +02:00
2022-12-27 12:35:36 +02:00
t.Views().Branches().
IsFocused().
2022-12-27 12:25:11 +02:00
SelectNextItem().
Tap(func() {
2022-12-27 12:35:36 +02:00
t.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
t.Views().Main().Content(Contains("+second line"))
2022-12-27 12:25:11 +02:00
}).
PressEnter()
2022-12-21 13:52:23 +02:00
2022-12-27 12:35:36 +02:00
t.Views().SubCommits().
IsFocused().
2022-12-27 12:25:11 +02:00
SelectedLine(Contains("update")).
Tap(func() {
2022-12-27 12:35:36 +02:00
t.Views().Main().Content(Contains("+second line"))
2022-12-27 12:25:11 +02:00
}).
PressEnter()
2022-12-27 12:35:36 +02:00
t.Views().CommitFiles().
IsFocused().
2022-12-27 12:25:11 +02:00
SelectedLine(Contains("file1")).
Tap(func() {
2022-12-27 12:35:36 +02:00
t.Views().Main().Content(Contains("+second line"))
2022-12-27 12:25:11 +02:00
}).
PressPrimaryAction(). // add the file to the patch
2022-12-27 12:25:11 +02:00
Press(keys.Universal.DiffingMenu).
Tap(func() {
2022-12-28 02:00:22 +02:00
t.ExpectPopup().Menu().Title(Equals("Diffing")).Select(Contains("exit diff mode")).Confirm()
2022-12-27 12:35:36 +02:00
t.Views().Information().Content(DoesNotContain("building patch"))
2022-12-27 12:25:11 +02:00
}).
Press(keys.Universal.CreatePatchOptionsMenu)
2022-12-21 13:52:23 +02:00
// adding the regex '$' here to distinguish the menu item from the 'apply patch in reverse' item
2022-12-28 02:00:22 +02:00
t.ExpectPopup().Menu().Title(Equals("Patch Options")).Select(MatchesRegexp("apply patch$")).Confirm()
2022-12-21 13:52:23 +02:00
2022-12-27 12:35:36 +02:00
t.Views().Files().
Focus().
SelectedLine(Contains("file1"))
2022-12-21 13:52:23 +02:00
2022-12-27 12:35:36 +02:00
t.Views().Main().Content(Contains("+second line"))
2022-12-21 13:52:23 +02:00
},
})