1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

add switch-to-view methods

This commit is contained in:
Jesse Duffield 2022-12-26 16:49:54 +11:00
parent 9a6f21ce42
commit c841ba8237
22 changed files with 77 additions and 51 deletions

View File

@ -45,26 +45,56 @@ func (self *Input) SwitchToStatusWindow() {
self.assert.CurrentWindowName("status")
}
// switch to status window and assert that the status view is on top
func (self *Input) SwitchToStatusView() {
self.SwitchToStatusWindow()
self.assert.CurrentView().Name("status")
}
func (self *Input) SwitchToFilesWindow() {
self.press(self.keys.Universal.JumpToBlock[1])
self.assert.CurrentWindowName("files")
}
// switch to files window and assert that the files view is on top
func (self *Input) SwitchToFilesView() {
self.SwitchToFilesWindow()
self.assert.CurrentView().Name("files")
}
func (self *Input) SwitchToBranchesWindow() {
self.press(self.keys.Universal.JumpToBlock[2])
self.assert.CurrentWindowName("localBranches")
}
// switch to branches window and assert that the branches view is on top
func (self *Input) SwitchToBranchesView() {
self.SwitchToBranchesWindow()
self.assert.CurrentView().Name("localBranches")
}
func (self *Input) SwitchToCommitsWindow() {
self.press(self.keys.Universal.JumpToBlock[3])
self.assert.CurrentWindowName("commits")
}
// switch to commits window and assert that the commits view is on top
func (self *Input) SwitchToCommitsView() {
self.SwitchToCommitsWindow()
self.assert.CurrentView().Name("commits")
}
func (self *Input) SwitchToStashWindow() {
self.press(self.keys.Universal.JumpToBlock[4])
self.assert.CurrentWindowName("stash")
}
// switch to stash window and assert that the stash view is on top
func (self *Input) SwitchToStashView() {
self.SwitchToStashWindow()
self.assert.CurrentView().Name("stash")
}
func (self *Input) Type(content string) {
for _, char := range content {
self.press(string(char))

View File

@ -32,7 +32,7 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
assert.AtLeastOneCommit()
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().SelectedLine(Contains("commit 10"))

View File

@ -28,9 +28,9 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert.AtLeastOneCommit()
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().Name("commits").TopLines(
assert.CurrentView().TopLines(
MatchesRegexp(`<-- bad.*commit 08`),
MatchesRegexp(`<-- current.*commit 07`),
MatchesRegexp(`\?.*commit 06`),

View File

@ -18,9 +18,9 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
EmptyCommit("blah")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
assert.CurrentView().Name("localBranches").Lines(
assert.CurrentView().Lines(
Contains("master"),
Contains("@"),
)

View File

@ -17,9 +17,9 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{
NewBranch("branch-two")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
assert.CurrentView().Name("localBranches").Lines(
assert.CurrentView().Lines(
MatchesRegexp(`\*.*branch-two`),
MatchesRegexp(`branch-one`),
MatchesRegexp(`master`),

View File

@ -15,8 +15,7 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
shared.MergeConflictsSetup(shell)
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
assert.CurrentView().Name("localBranches")
input.SwitchToBranchesView()
assert.View("localBranches").Lines(
Contains("first-change-branch"),

View File

@ -18,9 +18,9 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
shell.EmptyCommit("to keep")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
assert.CurrentView().Name("localBranches").Lines(
assert.CurrentView().Lines(
Contains("first-change-branch"),
Contains("second-change-branch"),
Contains("original-branch"),
@ -46,9 +46,8 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
Name("files").
SelectedLine(Contains("file"))
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().
Name("commits").
TopLines(
MatchesRegexp(`pick.*to keep`),
MatchesRegexp(`pick.*to remove`),
@ -62,7 +61,7 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Universal.Remove)
assert.CurrentView().SelectedLine(MatchesRegexp(`drop.*to remove`))
input.SwitchToFilesWindow()
input.SwitchToFilesView()
// not using Confirm() convenience method because I suspect we might change this
// keybinding to something more bespoke

View File

@ -26,9 +26,9 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
Contains("root commit"),
)
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
assert.CurrentView().Name("localBranches").Lines(
assert.CurrentView().Lines(
Contains("current-branch"),
Contains("other-branch"),
)
@ -42,8 +42,8 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentView().Name("localBranches")
// assert that we now have the expected commits in the commit panel
input.SwitchToCommitsWindow()
assert.CurrentView().Name("commits").Lines(
input.SwitchToCommitsView()
assert.CurrentView().Lines(
Contains("other-branch commit"),
Contains("root commit"),
)

View File

@ -21,8 +21,7 @@ var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{
NewBranch("other-new-branch-3")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
assert.CurrentView().Name("localBranches")
input.SwitchToBranchesView()
input.Press(keys.Branches.CheckoutBranchByName)

View File

@ -24,9 +24,9 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Checkout("first-branch")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
assert.CurrentView().Name("localBranches").Lines(
assert.CurrentView().Lines(
Contains("first-branch"),
Contains("second-branch"),
Contains("master"),
@ -49,9 +49,9 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Commits.CherryPickCopy)
assert.View("information").Content(Contains("2 commits copied"))
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().Name("commits").Lines(
assert.CurrentView().Lines(
Contains("two"),
Contains("one"),
Contains("base"),

View File

@ -15,8 +15,8 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
shared.MergeConflictsSetup(shell)
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
assert.CurrentView().Name("localBranches").Lines(
input.SwitchToBranchesView()
assert.CurrentView().Lines(
Contains("first-change-branch"),
Contains("second-change-branch"),
Contains("original-branch"),
@ -38,9 +38,9 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Commits.CherryPickCopy)
assert.View("information").Content(Contains("2 commits copied"))
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().Name("commits").TopLines(
assert.CurrentView().TopLines(
Contains("first change"),
)
@ -66,9 +66,9 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentView().Name("files")
assert.WorkingTreeFileCount(0)
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().Name("commits").TopLines(
assert.CurrentView().TopLines(
Contains("second-change-branch unrelated change"),
Contains("second change"),
Contains("first change"),

View File

@ -29,7 +29,7 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(1)
assert.HeadCommitMessage(Equals("first line"))
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.MainView().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
},
})

View File

@ -19,8 +19,8 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(3)
input.SwitchToCommitsWindow()
assert.CurrentView().Name("commits").Lines(
input.SwitchToCommitsView()
assert.CurrentView().Lines(
Contains("commit 3"),
Contains("commit 2"),
Contains("commit 1"),

View File

@ -18,9 +18,9 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(1)
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().Name("commits").Lines(
assert.CurrentView().Lines(
Contains("first commit"),
)

View File

@ -49,7 +49,7 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
keys config.KeybindingConfig,
) {
assert.WorkingTreeFileCount(0)
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
input.Press("a")
@ -57,7 +57,7 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
input.Prompt(Equals("Description"), " my branch")
input.SwitchToFilesWindow()
input.SwitchToFilesView()
assert.WorkingTreeFileCount(1)
assert.CurrentView().SelectedLine(Contains("output.txt"))

View File

@ -50,7 +50,7 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentBranchName("feature/bar")
assert.WorkingTreeFileCount(0)
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
input.Press("a")

View File

@ -22,9 +22,9 @@ var Diff = NewIntegrationTest(NewIntegrationTestArgs{
shell.Checkout("branch-a")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
input.SwitchToBranchesView()
assert.CurrentView().Name("localBranches").TopLines(
assert.CurrentView().TopLines(
Contains("branch-a"),
Contains("branch-b"),
)

View File

@ -22,8 +22,8 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
shell.Checkout("branch-a")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow()
assert.CurrentView().Name("localBranches").Lines(
input.SwitchToBranchesView()
assert.CurrentView().Lines(
Contains("branch-a"),
Contains("branch-b"),
)
@ -60,7 +60,7 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
// adding the regex '$' here to distinguish the menu item from the 'apply patch in reverse' item
input.Menu(Equals("Patch Options"), MatchesRegexp("apply patch$"))
input.SwitchToFilesWindow()
input.SwitchToFilesView()
assert.CurrentView().SelectedLine(Contains("file1"))
assert.MainView().Content(Contains("+second line"))

View File

@ -19,9 +19,9 @@ var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{
shell.Commit("third commit")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToCommitsWindow()
input.SwitchToCommitsView()
assert.CurrentView().Name("commits").Lines(
assert.CurrentView().Lines(
Contains("third commit"),
Contains("second commit"),
Contains("first commit"),

View File

@ -30,8 +30,7 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(3)
input.SwitchToCommitsWindow()
assert.CurrentView().Name("commits")
input.SwitchToCommitsView()
mergeCommitMessage := "Merge branch 'feature-branch' into development-branch"
assert.HeadCommitMessage(Contains(mergeCommitMessage))

View File

@ -15,8 +15,8 @@ var One = NewIntegrationTest(NewIntegrationTestArgs{
CreateNCommits(5) // these will appears at commit 05, 04, 04, down to 01
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToCommitsWindow()
assert.CurrentView().Name("commits").Lines(
input.SwitchToCommitsView()
assert.CurrentView().Lines(
Contains("commit 05"),
Contains("commit 04"),
Contains("commit 03"),

View File

@ -19,9 +19,9 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
StashWithMessage("bar")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToStashWindow()
input.SwitchToStashView()
assert.CurrentView().Name("stash").Lines(
assert.CurrentView().Lines(
Equals("On master: bar"),
Equals("On master: foo"),
)