1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-08 23:56:15 +02:00

add tap function

This commit is contained in:
Jesse Duffield 2022-12-27 21:25:11 +11:00
parent b166b8f776
commit 53e06b71ae
19 changed files with 210 additions and 230 deletions

View File

@ -194,3 +194,11 @@ func (self *View) NavigateToListItem(matcher *matcher) *View {
return self return self
} }
// for when you want to make some assertion unrelated to the current view
// without breaking the method chain
func (self *View) Tap(f func()) *View {
f()
return self
}

View File

@ -38,34 +38,28 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Commits(). input.Views().Commits().
Focus(). Focus().
SelectedLine(Contains("commit 10")). SelectedLine(Contains("commit 10")).
NavigateToListItem(Contains("commit 09")) NavigateToListItem(Contains("commit 09")).
Tap(func() {
markCommitAsBad() markCommitAsBad()
input.Views().Information().Content(Contains("bisecting")) input.Views().Information().Content(Contains("bisecting"))
}).
input.Views().Commits().
IsFocused().
SelectedLine(Contains("<-- bad")). SelectedLine(Contains("<-- bad")).
NavigateToListItem(Contains("commit 02")) NavigateToListItem(Contains("commit 02")).
Tap(markCommitAsGood).
markCommitAsGood()
// lazygit will land us in the commit between our good and bad commits. // lazygit will land us in the commit between our good and bad commits.
input.Views().Commits().IsFocused(). SelectedLine(Contains("commit 05").Contains("<-- current")).
SelectedLine(Contains("commit 05").Contains("<-- current")) Tap(markCommitAsBad).
SelectedLine(Contains("commit 04").Contains("<-- current")).
markCommitAsBad() Tap(func() {
input.Views().Commits().IsFocused().
SelectedLine(Contains("commit 04").Contains("<-- current"))
markCommitAsGood() markCommitAsGood()
// commit 5 is the culprit because we marked 4 as good and 5 as bad. // commit 5 is the culprit because we marked 4 as good and 5 as bad.
input.ExpectAlert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 05.*Do you want to reset")).Confirm() input.ExpectAlert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 05.*Do you want to reset")).Confirm()
}).
IsFocused().
Content(Contains("commit 04"))
input.Views().Commits().IsFocused().Content(Contains("commit 04"))
input.Views().Information().Content(DoesNotContain("bisecting")) input.Views().Information().Content(DoesNotContain("bisecting"))
}, },
}) })

View File

@ -36,16 +36,16 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
MatchesRegexp(`<-- good.*commit 05`), MatchesRegexp(`<-- good.*commit 05`),
). ).
SelectNextItem(). SelectNextItem().
Press(keys.Commits.ViewBisectOptions) Press(keys.Commits.ViewBisectOptions).
Tap(func() {
input.ExpectMenu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm() input.ExpectMenu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm()
input.ExpectAlert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 08.*Do you want to reset")).Confirm() input.ExpectAlert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit 08.*Do you want to reset")).Confirm()
input.Views().Information().Content(DoesNotContain("bisecting")) input.Views().Information().Content(DoesNotContain("bisecting"))
}).
// back in master branch which just had the one commit // back in master branch which just had the one commit
input.Views().Commits().Lines( Lines(
Contains("only commit on master"), Contains("only commit on master"),
) )
}, },

View File

@ -21,22 +21,20 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Branches(). input.Views().Branches().
Focus(). Focus().
Lines( Lines(
Contains("master"), Contains("master").IsSelected(),
Contains("@"), Contains("@"),
). ).
SelectNextItem(). SelectNextItem().
Press(keys.Branches.CheckoutBranchByName) Press(keys.Branches.CheckoutBranchByName).
Tap(func() {
input.ExpectPrompt().Title(Equals("Branch name:")).Type("new-branch").Confirm() input.ExpectPrompt().Title(Equals("Branch name:")).Type("new-branch").Confirm()
input.ExpectAlert().Title(Equals("Branch not found")).Content(Equals("Branch not found. Create a new branch named new-branch?")).Confirm() input.ExpectAlert().Title(Equals("Branch not found")).Content(Equals("Branch not found. Create a new branch named new-branch?")).Confirm()
}).
input.Views().Branches().IsFocused().
Lines( Lines(
MatchesRegexp(`\*.*new-branch`), MatchesRegexp(`\*.*new-branch`).IsSelected(),
Contains("master"), Contains("master"),
Contains("@"), Contains("@"),
). )
SelectedLine(Contains("new-branch"))
}, },
}) })

View File

@ -24,20 +24,18 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{
MatchesRegexp(`branch-one`), MatchesRegexp(`branch-one`),
MatchesRegexp(`master`), MatchesRegexp(`master`),
). ).
Press(keys.Universal.Remove) Press(keys.Universal.Remove).
Tap(func() {
input.ExpectAlert().Title(Equals("Error")).Content(Contains("You cannot delete the checked out branch!")).Confirm() input.ExpectAlert().Title(Equals("Error")).Content(Contains("You cannot delete the checked out branch!")).Confirm()
}).
input.Views().Branches().
SelectNextItem(). SelectNextItem().
Press(keys.Universal.Remove) Press(keys.Universal.Remove).
Tap(func() {
input.ExpectConfirmation(). input.ExpectConfirmation().
Title(Equals("Delete Branch")). Title(Equals("Delete Branch")).
Content(Contains("Are you sure you want to delete the branch 'branch-one'?")). Content(Contains("Are you sure you want to delete the branch 'branch-one'?")).
Confirm() Confirm()
}).
input.Views().Branches().IsFocused().
Lines( Lines(
MatchesRegexp(`\*.*branch-two`), MatchesRegexp(`\*.*branch-two`),
MatchesRegexp(`master`).IsSelected(), MatchesRegexp(`master`).IsSelected(),

View File

@ -37,9 +37,6 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
input.ExpectMenu().Title(Contains("reset to other-branch")).Select(Contains("hard reset")).Confirm() input.ExpectMenu().Title(Contains("reset to other-branch")).Select(Contains("hard reset")).Confirm()
// ensure that we've returned from the menu before continuing
input.Views().Branches().IsFocused()
// assert that we now have the expected commits in the commit panel // assert that we now have the expected commits in the commit panel
input.Views().Commits(). input.Views().Commits().
Lines( Lines(

View File

@ -42,11 +42,10 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("base"), Contains("base"),
). ).
// copy commits 'four' and 'three' // copy commits 'four' and 'three'
Press(keys.Commits.CherryPickCopy) Press(keys.Commits.CherryPickCopy).
Tap(func() {
input.Views().Information().Content(Contains("1 commit copied")) input.Views().Information().Content(Contains("1 commit copied"))
}).
input.Views().SubCommits().
SelectNextItem(). SelectNextItem().
Press(keys.Commits.CherryPickCopy) Press(keys.Commits.CherryPickCopy)
@ -59,29 +58,27 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("one"), Contains("one"),
Contains("base"), Contains("base"),
). ).
Press(keys.Commits.PasteCommits) Press(keys.Commits.PasteCommits).
Tap(func() {
input.ExpectAlert(). input.ExpectAlert().
Title(Equals("Cherry-Pick")). Title(Equals("Cherry-Pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")). Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Confirm() Confirm()
}).
input.Views().Commits().
IsFocused().
Lines( Lines(
Contains("four"), Contains("four"),
Contains("three"), Contains("three"),
Contains("two"), Contains("two"),
Contains("one"), Contains("one"),
Contains("base"), Contains("base"),
) ).
Tap(func() {
// we need to manually exit out of cherrry pick mode // we need to manually exit out of cherry pick mode
input.Views().Information().Content(Contains("2 commits copied")) input.Views().Information().Content(Contains("2 commits copied"))
}).
input.Views().Commits(). PressEscape().
PressEscape() Tap(func() {
input.Views().Information().Content(DoesNotContain("commits copied")) input.Views().Information().Content(DoesNotContain("commits copied"))
})
}, },
}) })

View File

@ -31,11 +31,10 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
Contains("second-change-branch unrelated change"), Contains("second-change-branch unrelated change"),
Contains("second change"), Contains("second change"),
). ).
Press(keys.Commits.CherryPickCopy) Press(keys.Commits.CherryPickCopy).
Tap(func() {
input.Views().Information().Content(Contains("1 commit copied")) input.Views().Information().Content(Contains("1 commit copied"))
}).
input.Views().SubCommits().
SelectNextItem(). SelectNextItem().
Press(keys.Commits.CherryPickCopy) Press(keys.Commits.CherryPickCopy)
@ -80,8 +79,8 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
Contains("second change"), Contains("second change"),
Contains("first change"), Contains("first change"),
). ).
SelectNextItem() SelectNextItem().
Tap(func() {
// because we picked 'Second change' when resolving the conflict, // because we picked 'Second change' when resolving the conflict,
// we now see this commit as having replaced First Change with Second Change, // we now see this commit as having replaced First Change with Second Change,
// as opposed to replacing 'Original' with 'Second change' // as opposed to replacing 'Original' with 'Second change'
@ -90,10 +89,10 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
Content(Contains("+Second Change")) Content(Contains("+Second Change"))
input.Views().Information().Content(Contains("2 commits copied")) input.Views().Information().Content(Contains("2 commits copied"))
}).
input.Views().Commits(). PressEscape().
PressEscape() Tap(func() {
input.Views().Information().Content(DoesNotContain("commits copied")) input.Views().Information().Content(DoesNotContain("commits copied"))
})
}, },
}) })

View File

@ -28,7 +28,8 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
input.ExpectCommitMessagePanel().Type(commitMessage).Confirm() input.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
input.Model().CommitCount(1) input.Model().
input.Model().HeadCommitMessage(Equals(commitMessage)) CommitCount(1).
HeadCommitMessage(Equals(commitMessage))
}, },
}) })

View File

@ -21,20 +21,20 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Commits(). input.Views().Commits().
Focus(). Focus().
SelectNextItem().
Lines( Lines(
Contains("commit 3"), Contains("commit 3"),
Contains("commit 2"), Contains("commit 2").IsSelected(),
Contains("commit 1"), Contains("commit 1"),
). ).
SelectNextItem(). Press(keys.Universal.New).
Press(keys.Universal.New) Tap(func() {
branchName := "my-branch-name" branchName := "my-branch-name"
input.ExpectPrompt().Title(Contains("New Branch Name")).Type(branchName).Confirm() input.ExpectPrompt().Title(Contains("New Branch Name")).Type(branchName).Confirm()
input.Model().CurrentBranchName(branchName) input.Model().CurrentBranchName(branchName)
}).
input.Views().Commits().Lines( Lines(
Contains("commit 2"), Contains("commit 2"),
Contains("commit 1"), Contains("commit 1"),
) )

View File

@ -23,14 +23,13 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
Lines( Lines(
Contains("first commit"), Contains("first commit"),
). ).
Press(keys.Commits.RevertCommit) Press(keys.Commits.RevertCommit).
Tap(func() {
input.ExpectConfirmation(). input.ExpectConfirmation().
Title(Equals("Revert commit")). Title(Equals("Revert commit")).
Content(MatchesRegexp(`Are you sure you want to revert \w+?`)). Content(MatchesRegexp(`Are you sure you want to revert \w+?`)).
Confirm() Confirm()
}).
input.Views().Commits().IsFocused().
Lines( Lines(
Contains("Revert \"first commit\"").IsSelected(), Contains("Revert \"first commit\"").IsSelected(),
Contains("first commit"), Contains("first commit"),

View File

@ -24,24 +24,24 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
PressPrimaryAction(). // stage the file PressPrimaryAction(). // stage the file
PressEnter() PressEnter()
input.Views().StagingSecondary().IsFocused() input.Views().StagingSecondary().
IsFocused().
Tap(func() {
// we start with both lines having been staged // we start with both lines having been staged
input.Views().StagingSecondary().Content(Contains("+myfile content")) input.Views().StagingSecondary().Content(Contains("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+with a second line")) input.Views().StagingSecondary().Content(Contains("+with a second line"))
input.Views().Staging().Content(DoesNotContain("+myfile content")) input.Views().Staging().Content(DoesNotContain("+myfile content"))
input.Views().Staging().Content(DoesNotContain("+with a second line")) input.Views().Staging().Content(DoesNotContain("+with a second line"))
}).
// unstage the selected line // unstage the selected line
input.Views().StagingSecondary(). PressPrimaryAction().
PressPrimaryAction() Tap(func() {
// the line should have been moved to the main view // the line should have been moved to the main view
input.Views().StagingSecondary().Content(DoesNotContain("+myfile content")) input.Views().StagingSecondary().Content(DoesNotContain("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+with a second line")) input.Views().StagingSecondary().Content(Contains("+with a second line"))
input.Views().Staging().Content(Contains("+myfile content")) input.Views().Staging().Content(Contains("+myfile content"))
input.Views().Staging().Content(DoesNotContain("+with a second line")) input.Views().Staging().Content(DoesNotContain("+with a second line"))
}).
input.Views().StagingSecondary().
Press(keys.Files.CommitChanges) Press(keys.Files.CommitChanges)
commitMessage := "my commit message" commitMessage := "my commit message"

View File

@ -36,11 +36,11 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
// unstage the selected line // unstage the selected line
input.Views().StagingSecondary(). input.Views().StagingSecondary().
IsFocused(). IsFocused().
PressPrimaryAction() PressPrimaryAction().
Tap(func() {
// the line should have been moved to the main view // the line should have been moved to the main view
input.Views().Staging().Content(Contains("+myfile content").DoesNotContain("+with a second line")) input.Views().Staging().Content(Contains("+myfile content").DoesNotContain("+with a second line"))
input.Views().StagingSecondary(). }).
Content(DoesNotContain("+myfile content").Contains("+with a second line")). Content(DoesNotContain("+myfile content").Contains("+with a second line")).
Press(keys.Files.CommitChangesWithoutHook) Press(keys.Files.CommitChangesWithoutHook)

View File

@ -26,18 +26,16 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
PressEnter() PressEnter()
input.Views().Staging(). input.Views().Staging().
IsFocused() IsFocused().
Tap(func() {
input.Views().StagingSecondary().Content(DoesNotContain("+myfile content")) input.Views().StagingSecondary().Content(DoesNotContain("+myfile content"))
}).
// stage the first line // stage the first line
input.Views().Staging(). PressPrimaryAction().
PressPrimaryAction() Tap(func() {
input.Views().Staging().Content(DoesNotContain("+myfile content")) input.Views().Staging().Content(DoesNotContain("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+myfile content")) input.Views().StagingSecondary().Content(Contains("+myfile content"))
}).
input.Views().Staging().
Press(keys.Files.CommitChanges) Press(keys.Files.CommitChanges)
commitMessage := "my commit message" commitMessage := "my commit message"

View File

@ -33,35 +33,33 @@ var Diff = NewIntegrationTest(NewIntegrationTestArgs{
input.ExpectMenu().Title(Equals("Diffing")).Select(Contains(`diff branch-a`)).Confirm() input.ExpectMenu().Title(Equals("Diffing")).Select(Contains(`diff branch-a`)).Confirm()
input.Views().Branches(). input.Views().Branches().
IsFocused() IsFocused().
Tap(func() {
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-a")) input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-a"))
}).
input.Views().Branches(). SelectNextItem().
SelectNextItem() Tap(func() {
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b")) input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
input.Views().Main().Content(Contains("+second line")) input.Views().Main().Content(Contains("+second line"))
}).
input.Views().Branches().
PressEnter() PressEnter()
input.Views().SubCommits(). input.Views().SubCommits().
IsFocused(). IsFocused().
SelectedLine(Contains("update")) SelectedLine(Contains("update")).
Tap(func() {
input.Views().Main().Content(Contains("+second line")) input.Views().Main().Content(Contains("+second line"))
}).
input.Views().SubCommits().
PressEnter() PressEnter()
input.Views().CommitFiles(). input.Views().CommitFiles().
IsFocused(). IsFocused().
SelectedLine(Contains("file1")) SelectedLine(Contains("file1")).
Tap(func() {
input.Views().Main().Content(Contains("+second line")) input.Views().Main().Content(Contains("+second line"))
}).
PressEscape()
input.Views().CommitFiles().PressEscape()
input.Views().SubCommits().PressEscape() input.Views().SubCommits().PressEscape()
input.Views().Branches(). input.Views().Branches().

View File

@ -36,38 +36,34 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Branches(). input.Views().Branches().
IsFocused(). IsFocused().
SelectNextItem() SelectNextItem().
Tap(func() {
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b")) input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
input.Views().Main().Content(Contains("+second line")) input.Views().Main().Content(Contains("+second line"))
}).
input.Views().Branches().
PressEnter() PressEnter()
input.Views().SubCommits(). input.Views().SubCommits().
IsFocused(). IsFocused().
SelectedLine(Contains("update")) SelectedLine(Contains("update")).
Tap(func() {
input.Views().Main().Content(Contains("+second line")) input.Views().Main().Content(Contains("+second line"))
}).
input.Views().SubCommits().
PressEnter() PressEnter()
input.Views().CommitFiles(). input.Views().CommitFiles().
IsFocused(). IsFocused().
SelectedLine(Contains("file1")) SelectedLine(Contains("file1")).
Tap(func() {
input.Views().Main().Content(Contains("+second line")) input.Views().Main().Content(Contains("+second line"))
}).
input.Views().CommitFiles().
PressPrimaryAction(). // add the file to the patch PressPrimaryAction(). // add the file to the patch
Press(keys.Universal.DiffingMenu) Press(keys.Universal.DiffingMenu).
Tap(func() {
input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("exit diff mode")).Confirm() input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("exit diff mode")).Confirm()
input.Views().Information().Content(DoesNotContain("building patch")) input.Views().Information().Content(DoesNotContain("building patch"))
}).
input.Views().CommitFiles().
Press(keys.Universal.CreatePatchOptionsMenu) Press(keys.Universal.CreatePatchOptionsMenu)
// adding the regex '$' here to distinguish the menu item from the 'apply patch in reverse' item // adding the regex '$' here to distinguish the menu item from the 'apply patch in reverse' item

View File

@ -22,31 +22,28 @@ var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Commits(). input.Views().Commits().
Focus(). Focus().
Lines( Lines(
Contains("third commit"), Contains("third commit").IsSelected(),
Contains("second commit"), Contains("second commit"),
Contains("first commit"), Contains("first commit"),
). ).
Press(keys.Universal.DiffingMenu) Press(keys.Universal.DiffingMenu).
Tap(func() {
input.ExpectMenu().Title(Equals("Diffing")).Select(MatchesRegexp(`diff \w+`)).Confirm() input.ExpectMenu().Title(Equals("Diffing")).Select(MatchesRegexp(`diff \w+`)).Confirm()
input.Views().Information().Content(Contains("showing output for: git diff")) input.Views().Information().Content(Contains("showing output for: git diff"))
}).
input.Views().Commits().
SelectNextItem(). SelectNextItem().
SelectNextItem(). SelectNextItem().
SelectedLine(Contains("first commit")) SelectedLine(Contains("first commit")).
Tap(func() {
input.Views().Main().Content(Contains("-second line\n-third line")) input.Views().Main().Content(Contains("-second line\n-third line"))
}).
input.Views().Commits(). Press(keys.Universal.DiffingMenu).
Press(keys.Universal.DiffingMenu) Tap(func() {
input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("reverse diff direction")).Confirm() input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("reverse diff direction")).Confirm()
input.Views().Main().Content(Contains("+second line\n+third line")) input.Views().Main().Content(Contains("+second line\n+third line"))
}).
input.Views().Commits().
PressEnter() PressEnter()
input.Views().CommitFiles(). input.Views().CommitFiles().

View File

@ -59,11 +59,11 @@ var One = NewIntegrationTest(NewIntegrationTestArgs{
MatchesRegexp("fixup.*commit 03"), MatchesRegexp("fixup.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"), MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"), Contains("commit 01"),
) ).
Tap(func() {
input.ContinueRebase() input.ContinueRebase()
}).
input.Views().Commits().Lines( Lines(
Contains("commit 02"), Contains("commit 02"),
Contains("commit 01"), Contains("commit 01"),
) )

View File

@ -26,10 +26,10 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
Equals("On master: foo"), Equals("On master: foo"),
). ).
SelectNextItem(). SelectNextItem().
Press(keys.Stash.RenameStash) Press(keys.Stash.RenameStash).
Tap(func() {
input.ExpectPrompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm() input.ExpectPrompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm()
}).
input.Views().Stash().SelectedLine(Equals("On master: foo baz")) SelectedLine(Equals("On master: foo baz"))
}, },
}) })