From 7351907474715c2bf86c6d52ef87b9d6d96d8f53 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 19 Feb 2023 11:33:58 +0100 Subject: [PATCH] Add integration tests for rebasing to the initial commit --- .../interactive_rebase/edit_first_commit.go | 38 ++++++++++++++++ .../interactive_rebase/fixup_second_commit.go | 44 +++++++++++++++++++ .../interactive_rebase/reword_first_commit.go | 39 ++++++++++++++++ .../squash_down_second_commit.go | 43 ++++++++++++++++++ pkg/integration/tests/tests_gen.go | 4 ++ 5 files changed, 168 insertions(+) create mode 100644 pkg/integration/tests/interactive_rebase/edit_first_commit.go create mode 100644 pkg/integration/tests/interactive_rebase/fixup_second_commit.go create mode 100644 pkg/integration/tests/interactive_rebase/reword_first_commit.go create mode 100644 pkg/integration/tests/interactive_rebase/squash_down_second_commit.go diff --git a/pkg/integration/tests/interactive_rebase/edit_first_commit.go b/pkg/integration/tests/interactive_rebase/edit_first_commit.go new file mode 100644 index 000000000..def3b7fca --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/edit_first_commit.go @@ -0,0 +1,38 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var EditFirstCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Edits the first commit, just to show that it's possible", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + CreateNCommits(2) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit 02"), + Contains("commit 01"), + ). + NavigateToListItem(Contains("commit 01")). + Press(keys.Universal.Edit). + Lines( + Contains("commit 02"), + MatchesRegexp("YOU ARE HERE.*commit 01").IsSelected(), + ). + Tap(func() { + t.Actions().ContinueRebase() + }). + Lines( + Contains("commit 02"), + Contains("commit 01"), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/fixup_second_commit.go b/pkg/integration/tests/interactive_rebase/fixup_second_commit.go new file mode 100644 index 000000000..007eba84f --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/fixup_second_commit.go @@ -0,0 +1,44 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var FixupSecondCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Fixup the second commit into the first (initial)", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + CreateNCommits(3) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit 03"), + Contains("commit 02"), + Contains("commit 01"), + ). + NavigateToListItem(Contains("commit 02")). + Press(keys.Commits.MarkCommitAsFixup). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Fixup")). + Content(Equals("Are you sure you want to 'fixup' this commit? It will be merged into the commit below")). + Confirm() + }). + Lines( + Contains("commit 03"), + Contains("commit 01").IsSelected(), + ) + + t.Views().Main(). + Content(Contains("commit 01")). + Content(DoesNotContain("commit 02")). + Content(Contains("+file01 content")). + Content(Contains("+file02 content")) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/reword_first_commit.go b/pkg/integration/tests/interactive_rebase/reword_first_commit.go new file mode 100644 index 000000000..9e631da09 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/reword_first_commit.go @@ -0,0 +1,39 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RewordFirstCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Rewords the first commit, just to show that it's possible", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + CreateNCommits(2) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit 02"), + Contains("commit 01"), + ). + NavigateToListItem(Contains("commit 01")). + Press(keys.Commits.RenameCommit). + Tap(func() { + t.ExpectPopup().Prompt(). + Title(Equals("reword commit")). + InitialText(Equals("commit 01")). + Clear(). + Type("renamed 01"). + Confirm() + }). + Lines( + Contains("commit 02"), + Contains("renamed 01"), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/squash_down_second_commit.go b/pkg/integration/tests/interactive_rebase/squash_down_second_commit.go new file mode 100644 index 000000000..ffa54584f --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/squash_down_second_commit.go @@ -0,0 +1,43 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SquashDownSecondCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Squash down the second commit into the first (initial)", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + CreateNCommits(3) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit 03"), + Contains("commit 02"), + Contains("commit 01"), + ). + NavigateToListItem(Contains("commit 02")). + Press(keys.Commits.SquashDown). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Squash")). + Content(Equals("Are you sure you want to squash this commit into the commit below?")). + Confirm() + }). + Lines( + Contains("commit 03"), + Contains("commit 01").IsSelected(), + ) + + t.Views().Main(). + Content(Contains(" commit 01\n \n commit 02")). + Content(Contains("+file01 content")). + Content(Contains("+file02 content")) + }, +}) diff --git a/pkg/integration/tests/tests_gen.go b/pkg/integration/tests/tests_gen.go index b711ea6d7..0e1b3b01c 100644 --- a/pkg/integration/tests/tests_gen.go +++ b/pkg/integration/tests/tests_gen.go @@ -66,9 +66,13 @@ var tests = []*components.IntegrationTest{ filter_by_path.SelectFile, filter_by_path.TypeFile, interactive_rebase.AmendMerge, + interactive_rebase.EditFirstCommit, interactive_rebase.FixupFirstCommit, + interactive_rebase.FixupSecondCommit, interactive_rebase.One, + interactive_rebase.RewordFirstCommit, interactive_rebase.SquashDownFirstCommit, + interactive_rebase.SquashDownSecondCommit, misc.ConfirmOnQuit, misc.InitialOpen, patch_building.CopyPatchToClipboard,