From d1f8c450995ace6b1b0e352ba10dcc0653da4030 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 20 Jan 2024 17:55:25 +0100 Subject: [PATCH] Add integration test --- .../commit_description_panel_driver.go | 10 ++++ .../tests/commit/auto_wrap_message.go | 59 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 70 insertions(+) create mode 100644 pkg/integration/tests/commit/auto_wrap_message.go diff --git a/pkg/integration/components/commit_description_panel_driver.go b/pkg/integration/components/commit_description_panel_driver.go index 0c4b2cfbb..eddc53533 100644 --- a/pkg/integration/components/commit_description_panel_driver.go +++ b/pkg/integration/components/commit_description_panel_driver.go @@ -31,6 +31,16 @@ func (self *CommitDescriptionPanelDriver) AddNewline() *CommitDescriptionPanelDr return self } +func (self *CommitDescriptionPanelDriver) GoToBeginning() *CommitDescriptionPanelDriver { + numLines := len(self.getViewDriver().getView().BufferLines()) + for i := 0; i < numLines; i++ { + self.t.pressFast("") + } + + self.t.pressFast("") + return self +} + func (self *CommitDescriptionPanelDriver) Title(expected *TextMatcher) *CommitDescriptionPanelDriver { self.getViewDriver().Title(expected) diff --git a/pkg/integration/tests/commit/auto_wrap_message.go b/pkg/integration/tests/commit/auto_wrap_message.go new file mode 100644 index 000000000..477bfae62 --- /dev/null +++ b/pkg/integration/tests/commit/auto_wrap_message.go @@ -0,0 +1,59 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var AutoWrapMessage = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Commit, and test how the commit message body is auto-wrapped", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + // Use a ridiculously small width so that we don't have to use so much test data + config.UserConfig.Git.Commit.AutoWrapWidth = 20 + }, + SetupRepo: func(shell *Shell) { + shell.CreateFile("file", "file content") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + IsEmpty() + + t.Views().Files(). + IsFocused(). + PressPrimaryAction(). // stage file + Press(keys.Files.CommitChanges) + + t.ExpectPopup().CommitMessagePanel(). + Type("subject"). + SwitchToDescription(). + Type("Lorem ipsum dolor sit amet, consectetur adipiscing elit."). + // See how it automatically inserted line feeds to wrap the text: + Content(Equals("Lorem ipsum dolor \nsit amet, \nconsectetur \nadipiscing elit.")). + SwitchToSummary(). + Confirm() + + t.Views().Commits(). + Lines( + Contains("subject"), + ). + Focus(). + Tap(func() { + t.Views().Main().Content(Contains( + "subject\n \n Lorem ipsum dolor\n sit amet,\n consectetur\n adipiscing elit.")) + }). + Press(keys.Commits.RenameCommit) + + // Test that when rewording, the hard line breaks are turned back into + // soft ones, so that we can insert text at the beginning and have the + // paragraph reflow nicely. + t.ExpectPopup().CommitMessagePanel(). + InitialText(Equals("subject")). + SwitchToDescription(). + Content(Equals("Lorem ipsum dolor \nsit amet, \nconsectetur \nadipiscing elit.")). + GoToBeginning(). + Type("More text. "). + Content(Equals("More text. Lorem \nipsum dolor sit \namet, consectetur \nadipiscing elit.")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 402a40acf..8c2891d47 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -65,6 +65,7 @@ var tests = []*components.IntegrationTest{ cherry_pick.CherryPickRange, commit.AddCoAuthor, commit.Amend, + commit.AutoWrapMessage, commit.Commit, commit.CommitMultiline, commit.CommitSwitchToEditor,