From f601b1cbb43ba4141b2facf2d50b568e595ca924 Mon Sep 17 00:00:00 2001 From: Gabriel Lanata Date: Mon, 13 Jan 2025 07:39:36 +0000 Subject: [PATCH] Add Tests --- pkg/integration/tests/test_list.go | 1 + .../tests/undo/undo_commit_soft.go | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 pkg/integration/tests/undo/undo_commit_soft.go diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index d7ce5e20462..a4b0031327d 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -366,6 +366,7 @@ var tests = []*components.IntegrationTest{ ui.SwitchTabFromMenu, ui.SwitchTabWithPanelJumpKeys, undo.UndoCheckoutAndDrop, + undo.UndoCommitSoft, undo.UndoDrop, worktree.AddFromBranch, worktree.AddFromBranchDetached, diff --git a/pkg/integration/tests/undo/undo_commit_soft.go b/pkg/integration/tests/undo/undo_commit_soft.go new file mode 100644 index 00000000000..168b026dfd9 --- /dev/null +++ b/pkg/integration/tests/undo/undo_commit_soft.go @@ -0,0 +1,70 @@ +package undo + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var UndoCommitSoft = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Undo/redo a commit using soft reset", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Git.Undo.CommitReset = "soft" + }, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.CreateFileAndAdd("file", "content1") + shell.Commit("two") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + confirmUndo := func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Undo")). + Content(MatchesRegexp(`Are you sure you want to soft reset to '.*'\? An auto-stash will be performed if necessary\.`)). + Confirm() + } + + confirmRedo := func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Redo")). + Content(MatchesRegexp(`Are you sure you want to soft reset to '.*'\? An auto-stash will be performed if necessary\.`)). + Confirm() + } + + confirmAutostash := func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Autostash?")). + Content(MatchesRegexp(`You must stash and pop your changes to bring them across\. Do this automatically\? \(enter\/esc\)`)). + Confirm() + } + + t.Views().Commits().Focus(). + Lines( + Contains("two").IsSelected(), + Contains("one"), + ). + Press(keys.Universal.Undo). + Tap(confirmUndo). + Lines( + Contains("one").IsSelected(), + ) + + t.Views().Files(). + Lines( + Contains("A file"), + ) + + t.Views().Commits().Focus(). + Press(keys.Universal.Redo). + Tap(confirmRedo). + Tap(confirmAutostash). + Lines( + Contains("two").IsSelected(), + Contains("one"), + ) + + t.Views().Files(). + IsEmpty() + }, +})