1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

rename input to t

This commit is contained in:
Jesse Duffield
2022-12-27 21:35:36 +11:00
parent 53e06b71ae
commit 78b495f50a
45 changed files with 376 additions and 399 deletions

View File

@ -10,23 +10,12 @@ type View struct {
// context is prepended to any error messages e.g. 'context: "current view"'
context string
getView func() *gocui.View
input *Input
}
// asserts that the view has the expected name. This is typically used in tandem with the CurrentView method i.e.;
// input.CurrentView().Name("commits") to assert that the current view is the commits view.
func (self *View) Name(expected string) *View {
self.input.assertWithRetries(func() (bool, string) {
actual := self.getView().Name()
return actual == expected, fmt.Sprintf("%s: Expected view name to be '%s', but got '%s'", self.context, expected, actual)
})
return self
t *TestDriver
}
// asserts that the view has the expected title
func (self *View) Title(expected *matcher) *View {
self.input.assertWithRetries(func() (bool, string) {
self.t.assertWithRetries(func() (bool, string) {
actual := self.getView().Title
return expected.context(fmt.Sprintf("%s title", self.context)).test(actual)
})
@ -39,7 +28,7 @@ func (self *View) Title(expected *matcher) *View {
// This method is convenient when you have a list of commits but you only want to
// assert on the first couple of commits.
func (self *View) TopLines(matchers ...*matcher) *View {
self.input.assertWithRetries(func() (bool, string) {
self.t.assertWithRetries(func() (bool, string) {
lines := self.getView().BufferLines()
return len(lines) >= len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected at least %d, got %d", len(matchers), len(lines))
})
@ -50,7 +39,7 @@ func (self *View) TopLines(matchers ...*matcher) *View {
// asserts that the view has lines matching the given matchers. One matcher must be passed for each line.
// If you only care about the top n lines, use the TopLines method instead.
func (self *View) Lines(matchers ...*matcher) *View {
self.input.assertWithRetries(func() (bool, string) {
self.t.assertWithRetries(func() (bool, string) {
lines := self.getView().BufferLines()
return len(lines) == len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", len(matchers), len(lines))
})
@ -64,14 +53,14 @@ func (self *View) assertLines(matchers ...*matcher) *View {
for i, matcher := range matchers {
checkIsSelected, matcher := matcher.checkIsSelected()
self.input.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", view.Name()),
self.t.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", view.Name()),
func() string {
return view.BufferLines()[i]
},
)
if checkIsSelected {
self.input.assertWithRetries(func() (bool, string) {
self.t.assertWithRetries(func() (bool, string) {
lineIdx := view.SelectedLineIdx()
return lineIdx == i, fmt.Sprintf("Unexpected selected line index in view '%s'. Expected %d, got %d", view.Name(), i, lineIdx)
})
@ -83,7 +72,7 @@ func (self *View) assertLines(matchers ...*matcher) *View {
// asserts on the content of the view i.e. the stuff within the view's frame.
func (self *View) Content(matcher *matcher) *View {
self.input.matchString(matcher, fmt.Sprintf("%s: Unexpected content.", self.context),
self.t.matchString(matcher, fmt.Sprintf("%s: Unexpected content.", self.context),
func() string {
return self.getView().Buffer()
},
@ -94,7 +83,7 @@ func (self *View) Content(matcher *matcher) *View {
// asserts on the selected line of the view
func (self *View) SelectedLine(matcher *matcher) *View {
self.input.matchString(matcher, fmt.Sprintf("%s: Unexpected selected line.", self.context),
self.t.matchString(matcher, fmt.Sprintf("%s: Unexpected selected line.", self.context),
func() string {
return self.getView().SelectedLine()
},
@ -105,7 +94,7 @@ func (self *View) SelectedLine(matcher *matcher) *View {
// asserts on the index of the selected line. 0 is the first index, representing the line at the top of the view.
func (self *View) SelectedLineIdx(expected int) *View {
self.input.assertWithRetries(func() (bool, string) {
self.t.assertWithRetries(func() (bool, string) {
actual := self.getView().SelectedLineIdx()
return expected == actual, fmt.Sprintf("%s: Expected selected line index to be %d, got %d", self.context, expected, actual)
})
@ -132,10 +121,10 @@ func (self *View) Focus() *View {
index, ok := windowIndexMap[viewName]
if !ok {
self.input.fail(fmt.Sprintf("Cannot focus view %s: Focus() method not implemented", viewName))
self.t.fail(fmt.Sprintf("Cannot focus view %s: Focus() method not implemented", viewName))
}
self.input.press(self.input.keys.Universal.JumpToBlock[index])
self.t.press(self.t.keys.Universal.JumpToBlock[index])
// assert that we land in the expected view
self.IsFocused()
@ -145,9 +134,9 @@ func (self *View) Focus() *View {
// asserts that the view is focused
func (self *View) IsFocused() *View {
self.input.assertWithRetries(func() (bool, string) {
self.t.assertWithRetries(func() (bool, string) {
expected := self.getView().Name()
actual := self.input.gui.CurrentContext().GetView().Name()
actual := self.t.gui.CurrentContext().GetView().Name()
return actual == expected, fmt.Sprintf("%s: Unexpected view focused. Expected %s, got %s", self.context, expected, actual)
})
@ -157,40 +146,40 @@ func (self *View) IsFocused() *View {
func (self *View) Press(keyStr string) *View {
self.IsFocused()
self.input.press(keyStr)
self.t.press(keyStr)
return self
}
// i.e. pressing down arrow
func (self *View) SelectNextItem() *View {
return self.Press(self.input.keys.Universal.NextItem)
return self.Press(self.t.keys.Universal.NextItem)
}
// i.e. pressing up arrow
func (self *View) SelectPreviousItem() *View {
return self.Press(self.input.keys.Universal.PrevItem)
return self.Press(self.t.keys.Universal.PrevItem)
}
// i.e. pressing space
func (self *View) PressPrimaryAction() *View {
return self.Press(self.input.keys.Universal.Select)
return self.Press(self.t.keys.Universal.Select)
}
// i.e. pressing space
func (self *View) PressEnter() *View {
return self.Press(self.input.keys.Universal.Confirm)
return self.Press(self.t.keys.Universal.Confirm)
}
// i.e. pressing escape
func (self *View) PressEscape() *View {
return self.Press(self.input.keys.Universal.Return)
return self.Press(self.t.keys.Universal.Return)
}
func (self *View) NavigateToListItem(matcher *matcher) *View {
self.IsFocused()
self.input.navigateToListItem(matcher)
self.t.navigateToListItem(matcher)
return self
}