1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-20 05:19:24 +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
}
// 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().
Focus().
SelectedLine(Contains("commit 10")).
NavigateToListItem(Contains("commit 09"))
NavigateToListItem(Contains("commit 09")).
Tap(func() {
markCommitAsBad()
markCommitAsBad()
input.Views().Information().Content(Contains("bisecting"))
input.Views().Commits().
IsFocused().
input.Views().Information().Content(Contains("bisecting"))
}).
SelectedLine(Contains("<-- bad")).
NavigateToListItem(Contains("commit 02"))
NavigateToListItem(Contains("commit 02")).
Tap(markCommitAsGood).
// lazygit will land us in the commit between our good and bad commits.
SelectedLine(Contains("commit 05").Contains("<-- current")).
Tap(markCommitAsBad).
SelectedLine(Contains("commit 04").Contains("<-- current")).
Tap(func() {
markCommitAsGood()
markCommitAsGood()
// 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()
}).
IsFocused().
Content(Contains("commit 04"))
// lazygit will land us in the commit between our good and bad commits.
input.Views().Commits().IsFocused().
SelectedLine(Contains("commit 05").Contains("<-- current"))
markCommitAsBad()
input.Views().Commits().IsFocused().
SelectedLine(Contains("commit 04").Contains("<-- current"))
markCommitAsGood()
// 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.Views().Commits().IsFocused().Content(Contains("commit 04"))
input.Views().Information().Content(DoesNotContain("bisecting"))
},
})

View File

@ -36,17 +36,17 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
MatchesRegexp(`<-- good.*commit 05`),
).
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"))
// back in master branch which just had the one commit
input.Views().Commits().Lines(
Contains("only commit on master"),
)
input.Views().Information().Content(DoesNotContain("bisecting"))
}).
// back in master branch which just had the one commit
Lines(
Contains("only commit on master"),
)
},
})

View File

@ -21,22 +21,20 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Branches().
Focus().
Lines(
Contains("master"),
Contains("master").IsSelected(),
Contains("@"),
).
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.Views().Branches().IsFocused().
input.ExpectAlert().Title(Equals("Branch not found")).Content(Equals("Branch not found. Create a new branch named new-branch?")).Confirm()
}).
Lines(
MatchesRegexp(`\*.*new-branch`),
MatchesRegexp(`\*.*new-branch`).IsSelected(),
Contains("master"),
Contains("@"),
).
SelectedLine(Contains("new-branch"))
)
},
})

View File

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

View File

@ -42,11 +42,10 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("base"),
).
// copy commits 'four' and 'three'
Press(keys.Commits.CherryPickCopy)
input.Views().Information().Content(Contains("1 commit copied"))
input.Views().SubCommits().
Press(keys.Commits.CherryPickCopy).
Tap(func() {
input.Views().Information().Content(Contains("1 commit copied"))
}).
SelectNextItem().
Press(keys.Commits.CherryPickCopy)
@ -59,29 +58,27 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("one"),
Contains("base"),
).
Press(keys.Commits.PasteCommits)
input.ExpectAlert().
Title(Equals("Cherry-Pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Confirm()
input.Views().Commits().
IsFocused().
Press(keys.Commits.PasteCommits).
Tap(func() {
input.ExpectAlert().
Title(Equals("Cherry-Pick")).
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Confirm()
}).
Lines(
Contains("four"),
Contains("three"),
Contains("two"),
Contains("one"),
Contains("base"),
)
// we need to manually exit out of cherrry pick mode
input.Views().Information().Content(Contains("2 commits copied"))
input.Views().Commits().
PressEscape()
input.Views().Information().Content(DoesNotContain("commits copied"))
).
Tap(func() {
// we need to manually exit out of cherry pick mode
input.Views().Information().Content(Contains("2 commits copied"))
}).
PressEscape().
Tap(func() {
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"),
).
Press(keys.Commits.CherryPickCopy)
input.Views().Information().Content(Contains("1 commit copied"))
input.Views().SubCommits().
Press(keys.Commits.CherryPickCopy).
Tap(func() {
input.Views().Information().Content(Contains("1 commit copied"))
}).
SelectNextItem().
Press(keys.Commits.CherryPickCopy)
@ -80,20 +79,20 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
Contains("second change"),
Contains("first change"),
).
SelectNextItem()
SelectNextItem().
Tap(func() {
// because we picked 'Second change' when resolving the conflict,
// we now see this commit as having replaced First Change with Second Change,
// as opposed to replacing 'Original' with 'Second change'
input.Views().Main().
Content(Contains("-First Change")).
Content(Contains("+Second Change"))
// because we picked 'Second change' when resolving the conflict,
// we now see this commit as having replaced First Change with Second Change,
// as opposed to replacing 'Original' with 'Second change'
input.Views().Main().
Content(Contains("-First Change")).
Content(Contains("+Second Change"))
input.Views().Information().Content(Contains("2 commits copied"))
input.Views().Commits().
PressEscape()
input.Views().Information().Content(DoesNotContain("commits copied"))
input.Views().Information().Content(Contains("2 commits copied"))
}).
PressEscape().
Tap(func() {
input.Views().Information().Content(DoesNotContain("commits copied"))
})
},
})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,18 +26,16 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
PressEnter()
input.Views().Staging().
IsFocused()
input.Views().StagingSecondary().Content(DoesNotContain("+myfile content"))
// stage the first line
input.Views().Staging().
PressPrimaryAction()
input.Views().Staging().Content(DoesNotContain("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+myfile content"))
input.Views().Staging().
IsFocused().
Tap(func() {
input.Views().StagingSecondary().Content(DoesNotContain("+myfile content"))
}).
// stage the first line
PressPrimaryAction().
Tap(func() {
input.Views().Staging().Content(DoesNotContain("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+myfile content"))
}).
Press(keys.Files.CommitChanges)
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.Views().Branches().
IsFocused()
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-a"))
input.Views().Branches().
SelectNextItem()
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
input.Views().Main().Content(Contains("+second line"))
input.Views().Branches().
IsFocused().
Tap(func() {
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-a"))
}).
SelectNextItem().
Tap(func() {
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
input.Views().Main().Content(Contains("+second line"))
}).
PressEnter()
input.Views().SubCommits().
IsFocused().
SelectedLine(Contains("update"))
input.Views().Main().Content(Contains("+second line"))
input.Views().SubCommits().
SelectedLine(Contains("update")).
Tap(func() {
input.Views().Main().Content(Contains("+second line"))
}).
PressEnter()
input.Views().CommitFiles().
IsFocused().
SelectedLine(Contains("file1"))
SelectedLine(Contains("file1")).
Tap(func() {
input.Views().Main().Content(Contains("+second line"))
}).
PressEscape()
input.Views().Main().Content(Contains("+second line"))
input.Views().CommitFiles().PressEscape()
input.Views().SubCommits().PressEscape()
input.Views().Branches().

View File

@ -36,38 +36,34 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
input.Views().Branches().
IsFocused().
SelectNextItem()
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
input.Views().Main().Content(Contains("+second line"))
input.Views().Branches().
SelectNextItem().
Tap(func() {
input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
input.Views().Main().Content(Contains("+second line"))
}).
PressEnter()
input.Views().SubCommits().
IsFocused().
SelectedLine(Contains("update"))
input.Views().Main().Content(Contains("+second line"))
input.Views().SubCommits().
SelectedLine(Contains("update")).
Tap(func() {
input.Views().Main().Content(Contains("+second line"))
}).
PressEnter()
input.Views().CommitFiles().
IsFocused().
SelectedLine(Contains("file1"))
input.Views().Main().Content(Contains("+second line"))
input.Views().CommitFiles().
SelectedLine(Contains("file1")).
Tap(func() {
input.Views().Main().Content(Contains("+second line"))
}).
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().CommitFiles().
input.Views().Information().Content(DoesNotContain("building patch"))
}).
Press(keys.Universal.CreatePatchOptionsMenu)
// 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().
Focus().
Lines(
Contains("third commit"),
Contains("third commit").IsSelected(),
Contains("second 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().Commits().
input.Views().Information().Content(Contains("showing output for: git diff"))
}).
SelectNextItem().
SelectNextItem().
SelectedLine(Contains("first commit"))
SelectedLine(Contains("first commit")).
Tap(func() {
input.Views().Main().Content(Contains("-second line\n-third line"))
}).
Press(keys.Universal.DiffingMenu).
Tap(func() {
input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("reverse diff direction")).Confirm()
input.Views().Main().Content(Contains("-second line\n-third line"))
input.Views().Commits().
Press(keys.Universal.DiffingMenu)
input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("reverse diff direction")).Confirm()
input.Views().Main().Content(Contains("+second line\n+third line"))
input.Views().Commits().
input.Views().Main().Content(Contains("+second line\n+third line"))
}).
PressEnter()
input.Views().CommitFiles().

View File

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

View File

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