From 3ebba5f32cdd1549f032a68592928b23bbddf3f8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 19 Dec 2023 16:44:16 +0100 Subject: [PATCH] Add test demonstrating a bug with preserving the commit message SplitCommitMessageAndDescription splits at the first '\n\n' that it finds (if there is one), which in this case is between the two paragraphs of the description. This is wrong. --- .../commit_description_panel_driver.go | 11 +++++ .../tests/commit/preserve_commit_message.go | 48 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 60 insertions(+) create mode 100644 pkg/integration/tests/commit/preserve_commit_message.go diff --git a/pkg/integration/components/commit_description_panel_driver.go b/pkg/integration/components/commit_description_panel_driver.go index 993b1316f..0c4b2cfbb 100644 --- a/pkg/integration/components/commit_description_panel_driver.go +++ b/pkg/integration/components/commit_description_panel_driver.go @@ -8,6 +8,13 @@ func (self *CommitDescriptionPanelDriver) getViewDriver() *ViewDriver { return self.t.Views().CommitDescription() } +// asserts on the current context of the description +func (self *CommitDescriptionPanelDriver) Content(expected *TextMatcher) *CommitDescriptionPanelDriver { + self.getViewDriver().Content(expected) + + return self +} + func (self *CommitDescriptionPanelDriver) Type(value string) *CommitDescriptionPanelDriver { self.t.typeContent(value) @@ -29,3 +36,7 @@ func (self *CommitDescriptionPanelDriver) Title(expected *TextMatcher) *CommitDe return self } + +func (self *CommitDescriptionPanelDriver) Cancel() { + self.getViewDriver().PressEscape() +} diff --git a/pkg/integration/tests/commit/preserve_commit_message.go b/pkg/integration/tests/commit/preserve_commit_message.go new file mode 100644 index 000000000..5a580e854 --- /dev/null +++ b/pkg/integration/tests/commit/preserve_commit_message.go @@ -0,0 +1,48 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var PreserveCommitMessage = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Test that the commit message is preserved correctly when canceling the commit message panel", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("myfile", "myfile content") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Press(keys.Files.CommitChanges) + + t.ExpectPopup().CommitMessagePanel(). + InitialText(Equals("")). + Type("my commit message"). + SwitchToDescription(). + Type("first paragraph"). + AddNewline(). + AddNewline(). + Type("second paragraph"). + Cancel() + + t.Views().Files(). + IsFocused(). + Press(keys.Files.CommitChanges) + + /* EXPECTED: + t.ExpectPopup().CommitMessagePanel(). + Content(Equals("my commit message")). + SwitchToDescription(). + Content(Equals("first paragraph\n\nsecond paragraph")) + + ACTUAL: + */ + t.ExpectPopup().CommitMessagePanel(). + Content(Equals("my commit message\nfirst paragraph")). + SwitchToDescription(). + Content(Equals("second paragraph")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index c61a7c2e6..ccefd1dd2 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -74,6 +74,7 @@ var tests = []*components.IntegrationTest{ commit.History, commit.HistoryComplex, commit.NewBranch, + commit.PreserveCommitMessage, commit.ResetAuthor, commit.Revert, commit.RevertMerge,