Skip to content

Commit

Permalink
Add Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellanata committed Jan 13, 2025
1 parent a236882 commit f601b1c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ var tests = []*components.IntegrationTest{
ui.SwitchTabFromMenu,
ui.SwitchTabWithPanelJumpKeys,
undo.UndoCheckoutAndDrop,
undo.UndoCommitSoft,
undo.UndoDrop,
worktree.AddFromBranch,
worktree.AddFromBranchDetached,
Expand Down
70 changes: 70 additions & 0 deletions pkg/integration/tests/undo/undo_commit_soft.go
Original file line number Diff line number Diff line change
@@ -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()
},
})

0 comments on commit f601b1c

Please sign in to comment.