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,