1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-08 22:36:49 +02:00

migrate patch building tests

This commit is contained in:
Jesse Duffield
2023-02-25 13:08:45 +11:00
parent 6c0b805137
commit dd1bf629b8
161 changed files with 1204 additions and 489 deletions

View File

@ -0,0 +1,64 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Apply = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Apply a custom 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")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("branch-a").IsSelected(),
Contains("branch-b"),
).
Press(keys.Universal.NextItem).
PressEnter()
t.Views().SubCommits().
IsFocused().
Lines(
Contains("update").IsSelected(),
Contains("first commit"),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("M file1").IsSelected(),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Views().PatchBuildingSecondary().Content(Contains("second line"))
t.Actions().SelectPatchOption(MatchesRegexp(`apply patch$`))
t.Views().Files().
Focus().
Lines(
Contains("file1").IsSelected(),
)
t.Views().Main().
Content(Contains("second line"))
},
})

View File

@ -0,0 +1,49 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ApplyInReverse = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Apply a custom patch in reverse",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content\n")
shell.CreateFileAndAdd("file2", "file2 content\n")
shell.Commit("first commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("first commit").IsSelected(),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
Contains("file2"),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))
t.Actions().SelectPatchOption(Contains("apply patch in reverse"))
t.Views().Files().
Focus().
Lines(
Contains("D").Contains("file1").IsSelected(),
)
t.Views().Main().
Content(Contains("-file1 content"))
},
})

View File

@ -8,7 +8,7 @@ import (
var CopyPatchToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Create a patch from the commits and copy the patch to clipbaord.",
ExtraCmdArgs: "",
Skip: true,
Skip: true, // skipping because CI doesn't have clipboard functionality
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.NewBranch("branch-a")
@ -40,11 +40,7 @@ var CopyPatchToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
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.Actions().SelectPatchOption(Contains("copy patch to clipboard"))
t.ExpectToast(Contains("Patch copied to clipboard"))

View File

@ -0,0 +1,66 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveToIndex = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to the index",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content\n")
shell.CreateFileAndAdd("file2", "file2 content\n")
shell.Commit("first commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("first commit").IsSelected(),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
Contains("file2"),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))
t.Actions().SelectPatchOption(Contains("move patch out into index"))
t.Views().Files().
Lines(
Contains("A").Contains("file1"),
)
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file2").IsSelected(),
).
PressEscape()
t.Views().Main().
Content(Contains("+file2 content"))
t.Views().Commits().
Lines(
Contains("first commit").IsSelected(),
)
t.Views().Files().
Focus()
t.Views().Main().
Content(Contains("file1 content"))
},
})

View File

@ -0,0 +1,98 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveToIndexPartial = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to the index. This is different from the MoveToIndex test in that we're only selecting a partial patch from a file",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "first line\nsecond line\nthird line\n")
shell.Commit("first commit")
shell.UpdateFileAndAdd("file1", "first line2\nsecond line\nthird line2\n")
shell.Commit("second commit")
shell.CreateFileAndAdd("file2", "file1 content")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("second commit"),
Contains("first commit"),
).
NavigateToListItem(Contains("second commit")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
).
PressEnter()
t.Views().PatchBuilding().
IsFocused().
ContainsLines(
Contains(`-first line`).IsSelected(),
Contains(`+first line2`),
Contains(` second line`),
Contains(`-third line`),
Contains(`+third line2`),
).
PressPrimaryAction().
SelectNextItem().
PressPrimaryAction().
Tap(func() {
t.Views().Information().Content(Contains("building patch"))
t.Views().PatchBuildingSecondary().
ContainsLines(
Contains(`-first line`),
Contains(`+first line2`),
Contains(` second line`),
Contains(` third line`),
)
t.Actions().SelectPatchOption(Contains("move patch out into index"))
t.Views().Files().
Lines(
Contains("M").Contains("file1"),
)
})
// Focus is automatically returned to the commit files panel. Arguably it shouldn't be.
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1"),
)
t.Views().Main().
ContainsLines(
Contains(` first line`),
Contains(` second line`),
Contains(`-third line`),
Contains(`+third line2`),
)
t.Views().Files().
Focus()
t.Views().Main().
ContainsLines(
Contains(`-first line`),
Contains(`+first line2`),
Contains(` second line`),
Contains(` third line2`),
)
},
})

View File

@ -0,0 +1,89 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveToIndexWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to the index, causing a conflict",
ExtraCmdArgs: "",
Skip: true, // Skipping until https://github.com/jesseduffield/lazygit/pull/2471 is merged
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content")
shell.Commit("first commit")
shell.UpdateFileAndAdd("file1", "file1 content with old changes")
shell.Commit("second commit")
shell.UpdateFileAndAdd("file1", "file1 content with new changes")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("second commit"),
Contains("first commit"),
).
SelectNextItem().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Actions().SelectPatchOption(Contains("move patch out into index"))
t.Actions().AcknowledgeConflicts()
t.Views().Files().
IsFocused().
Lines(
Contains("UU").Contains("file1"),
).
PressPrimaryAction()
t.Views().MergeConflicts().
IsFocused().
ContainsLines(
Contains("<<<<<<< HEAD").IsSelected(),
Contains("file1 content").IsSelected(),
Contains("=======").IsSelected(),
Contains("file1 content with new changes"),
Contains(">>>>>>>"),
).
PressPrimaryAction()
t.Actions().ContinueOnConflictsResolved()
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Contains("Applied patch to 'file1' with conflicts")).
Confirm()
t.Views().Files().
IsFocused().
Lines(
Contains("UU").Contains("file1"),
).
PressEnter()
t.Views().MergeConflicts().
TopLines(
Contains("<<<<<<< ours"),
Contains("file1 content"),
Contains("======="),
Contains("file1 content with old changes"),
Contains(">>>>>>> theirs"),
).
IsFocused()
},
})

View File

@ -0,0 +1,70 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveToNewCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to a new commit",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content")
shell.Commit("first commit")
shell.UpdateFileAndAdd("file1", "file1 content with old changes")
shell.Commit("second commit")
shell.UpdateFileAndAdd("file1", "file1 content with new changes")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("second commit"),
Contains("first commit"),
).
SelectNextItem().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Actions().SelectPatchOption(Contains("move patch into new commit"))
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
).
PressEscape()
t.Views().Commits().
IsFocused().
Lines(
Contains("third commit"),
Contains(`Split from "second commit"`).IsSelected(),
Contains("second commit"),
Contains("first commit"),
).
SelectNextItem().
PressEnter()
// the original commit has no more files in it
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("(none)"),
)
},
})

View File

@ -0,0 +1,57 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var RemoveFromCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Remove a custom patch from a commit",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content\n")
shell.CreateFileAndAdd("file2", "file2 content\n")
shell.Commit("first commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("first commit").IsSelected(),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
Contains("file2"),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Views().PatchBuildingSecondary().Content(Contains("+file1 content"))
t.Actions().SelectPatchOption(Contains("remove patch from original commit"))
t.Views().Files().IsEmpty()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file2").IsSelected(),
).
PressEscape()
t.Views().Main().
Content(Contains("+file2 content"))
t.Views().Commits().
Lines(
Contains("first commit").IsSelected(),
)
},
})

View File

@ -0,0 +1,43 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ResetWithEscape = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Reset a custom patch with the escape keybinding",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content")
shell.Commit("first commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("first commit").IsSelected(),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
).
PressPrimaryAction().
Tap(func() {
t.Views().Information().Content(Contains("building patch"))
}).
PressEscape()
// hitting escape at the top level will reset the patch
t.Views().Commits().
IsFocused().
PressEscape()
t.Views().Information().Content(DoesNotContain("building patch"))
},
})

View File

@ -0,0 +1,42 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SelectAllFiles = NewIntegrationTest(NewIntegrationTestArgs{
Description: "All all files of a commit to a custom patch with the 'a' keybinding",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content")
shell.CreateFileAndAdd("file2", "file2 content")
shell.CreateFileAndAdd("file3", "file3 content")
shell.Commit("first commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("first commit").IsSelected(),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
Contains("file2"),
Contains("file3"),
).
Press(keys.Files.ToggleStagedAll)
t.Views().Information().Content(Contains("building patch"))
t.Views().Secondary().Content(
Contains("file1").Contains("file3").Contains("file3"),
)
},
})

View File

@ -0,0 +1,167 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SpecificSelection = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Build a custom patch with a specific selection of lines, adding individual lines, as well as a range and hunk, and adding a file directly",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("hunk-file", "1a\n1b\n1c\n1d\n1e\n1f\n1g\n1h\n1i\n1j\n1k\n1l\n1m\n1n\n1o\n1p\n1q\n1r\n1s\n1t\n1u\n1v\n1w\n1x\n1y\n1z\n")
shell.Commit("first commit")
// making changes in two separate places for the sake of having two hunks
shell.UpdateFileAndAdd("hunk-file", "aa\n1b\ncc\n1d\n1e\n1f\n1g\n1h\n1i\n1j\n1k\n1l\n1m\n1n\n1o\n1p\n1q\n1r\n1s\ntt\nuu\nvv\n1w\n1x\n1y\n1z\n")
shell.CreateFileAndAdd("line-file", "2a\n2b\n2c\n2d\n2e\n2f\n2g\n2h\n2i\n2j\n2k\n2l\n2m\n2n\n2o\n2p\n2q\n2r\n2s\n2t\n2u\n2v\n2w\n2x\n2y\n2z\n")
shell.CreateFileAndAdd("direct-file", "direct file content")
shell.Commit("second commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("second commit").IsSelected(),
Contains("first commit"),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("direct-file").IsSelected(),
Contains("hunk-file"),
Contains("line-file"),
).
PressPrimaryAction().
Tap(func() {
t.Views().Information().Content(Contains("building patch"))
t.Views().Secondary().Content(Contains("direct file content"))
}).
NavigateToListItem(Contains("hunk-file")).
PressEnter()
t.Views().PatchBuilding().
IsFocused().
SelectedLines(
Contains("-1a"),
).
Press(keys.Main.ToggleSelectHunk).
SelectedLines(
Contains(`@@ -1,6 +1,6 @@`),
Contains(`-1a`),
Contains(`+aa`),
Contains(` 1b`),
Contains(`-1c`),
Contains(`+cc`),
Contains(` 1d`),
Contains(` 1e`),
Contains(` 1f`),
).
PressPrimaryAction().
// unlike in the staging panel, we don't remove lines from the patch building panel
// upon 'adding' them. So the same lines will be selected
SelectedLines(
Contains(`@@ -1,6 +1,6 @@`),
Contains(`-1a`),
Contains(`+aa`),
Contains(` 1b`),
Contains(`-1c`),
Contains(`+cc`),
Contains(` 1d`),
Contains(` 1e`),
Contains(` 1f`),
).
Tap(func() {
t.Views().Information().Content(Contains("building patch"))
t.Views().Secondary().Content(
// when we're inside the patch building panel, we only show the patch
// in the secondary panel that relates to the selected file
DoesNotContain("direct file content").
Contains("@@ -1,6 +1,6 @@").
Contains(" 1f"),
)
}).
PressEscape()
t.Views().CommitFiles().
IsFocused().
NavigateToListItem(Contains("line-file")).
PressEnter()
t.Views().PatchBuilding().
IsFocused().
// hunk is selected because selection mode persists across files
ContainsLines(
Contains("@@ -0,0 +1,26 @@").IsSelected(),
).
Press(keys.Main.ToggleSelectHunk).
SelectedLines(
Contains("+2a"),
).
PressPrimaryAction().
NavigateToListItem(Contains("+2c")).
Press(keys.Main.ToggleDragSelect).
NavigateToListItem(Contains("+2e")).
PressPrimaryAction().
NavigateToListItem(Contains("+2g")).
PressPrimaryAction().
Tap(func() {
t.Views().Information().Content(Contains("building patch"))
t.Views().Secondary().ContainsLines(
Contains("+2a"),
Contains("+2c"),
Contains("+2d"),
Contains("+2e"),
Contains("+2g"),
)
}).
PressEscape().
Tap(func() {
t.Views().Secondary().ContainsLines(
// direct-file patch
Contains(`diff --git a/direct-file b/direct-file`),
Contains(`new file mode 100644`),
Contains(`index`),
Contains(`--- /dev/null`),
Contains(`+++ b/direct-file`),
Contains(`@@ -0,0 +1 @@`),
Contains(`+direct file content`),
Contains(`\ No newline at end of file`),
// hunk-file patch
Contains(`diff --git a/hunk-file b/hunk-file`),
Contains(`index`),
Contains(`--- a/hunk-file`),
Contains(`+++ b/hunk-file`),
Contains(`@@ -1,6 +1,6 @@`),
Contains(`-1a`),
Contains(`+aa`),
Contains(` 1b`),
Contains(`-1c`),
Contains(`+cc`),
Contains(` 1d`),
Contains(` 1e`),
Contains(` 1f`),
// line-file patch
Contains(`diff --git a/line-file b/line-file`),
Contains(`new file mode 100644`),
Contains(`index`),
Contains(`--- /dev/null`),
Contains(`+++ b/line-file`),
Contains(`@@ -0,0 +1,5 @@`),
Contains(`+2a`),
Contains(`+2c`),
Contains(`+2d`),
Contains(`+2e`),
Contains(`+2g`),
)
})
},
})

View File

@ -0,0 +1,62 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StartNewPatch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Attempt to add a file from another commit to a patch, then agree to start a new patch",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content")
shell.Commit("first commit")
shell.CreateFileAndAdd("file2", "file2 content")
shell.Commit("second commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("second commit").IsSelected(),
Contains("first commit"),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file2").IsSelected(),
).
PressPrimaryAction().
Tap(func() {
t.Views().Information().Content(Contains("building patch"))
t.Views().Secondary().Content(Contains("file2"))
}).
PressEscape()
t.Views().Commits().
IsFocused().
NavigateToListItem(Contains("first commit")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
).
PressPrimaryAction().
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Contains("Discard Patch")).
Content(Contains("You can only build a patch from one commit/stash-entry at a time. Discard current patch?")).
Confirm()
t.Views().Secondary().Content(Contains("file1").DoesNotContain("file2"))
})
},
})

View File

@ -94,7 +94,18 @@ var tests = []*components.IntegrationTest{
interactive_rebase.SwapWithConflict,
misc.ConfirmOnQuit,
misc.InitialOpen,
patch_building.Apply,
patch_building.ApplyInReverse,
patch_building.CopyPatchToClipboard,
patch_building.MoveToIndex,
patch_building.MoveToIndexPartial,
patch_building.MoveToIndexWithConflict,
patch_building.MoveToNewCommit,
patch_building.RemoveFromCommit,
patch_building.ResetWithEscape,
patch_building.SelectAllFiles,
patch_building.SpecificSelection,
patch_building.StartNewPatch,
reflog.Checkout,
reflog.CherryPick,
reflog.Patch,