mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Add integration tests for searching/filtering
This commit is contained in:
@ -10,9 +10,9 @@ type IntMatcher struct {
|
||||
|
||||
func (self *IntMatcher) EqualsInt(target int) *IntMatcher {
|
||||
self.appendRule(matcherRule[int]{
|
||||
name: fmt.Sprintf("equals '%d'", target),
|
||||
name: fmt.Sprintf("equals %d", target),
|
||||
testFn: func(value int) (bool, string) {
|
||||
return value == target, fmt.Sprintf("Expected '%d' to equal '%d'", value, target)
|
||||
return value == target, fmt.Sprintf("Expected %d to equal %d", value, target)
|
||||
},
|
||||
})
|
||||
|
||||
@ -21,9 +21,9 @@ func (self *IntMatcher) EqualsInt(target int) *IntMatcher {
|
||||
|
||||
func (self *IntMatcher) GreaterThan(target int) *IntMatcher {
|
||||
self.appendRule(matcherRule[int]{
|
||||
name: fmt.Sprintf("greater than '%d'", target),
|
||||
name: fmt.Sprintf("greater than %d", target),
|
||||
testFn: func(value int) (bool, string) {
|
||||
return value > target, fmt.Sprintf("Expected '%d' to greater than '%d'", value, target)
|
||||
return value > target, fmt.Sprintf("Expected %d to greater than %d", value, target)
|
||||
},
|
||||
})
|
||||
|
||||
@ -32,9 +32,9 @@ func (self *IntMatcher) GreaterThan(target int) *IntMatcher {
|
||||
|
||||
func (self *IntMatcher) LessThan(target int) *IntMatcher {
|
||||
self.appendRule(matcherRule[int]{
|
||||
name: fmt.Sprintf("less than '%d'", target),
|
||||
name: fmt.Sprintf("less than %d", target),
|
||||
testFn: func(value int) (bool, string) {
|
||||
return value < target, fmt.Sprintf("Expected '%d' to less than '%d'", value, target)
|
||||
return value < target, fmt.Sprintf("Expected %d to less than %d", value, target)
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -48,6 +48,18 @@ func (self *MenuDriver) TopLines(matchers ...*TextMatcher) *MenuDriver {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *MenuDriver) Filter(text string) *MenuDriver {
|
||||
self.getViewDriver().FilterOrSearch(text)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *MenuDriver) LineCount(matcher *IntMatcher) *MenuDriver {
|
||||
self.getViewDriver().LineCount(matcher)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *MenuDriver) checkNecessaryChecksCompleted() {
|
||||
if !self.hasCheckedTitle {
|
||||
self.t.Fail("You must check the title of a menu popup by calling Title() before calling Confirm()/Cancel().")
|
||||
|
@ -66,7 +66,7 @@ func (self *ViewDriver) Title(expected *TextMatcher) *ViewDriver {
|
||||
// If you only care about a subset of lines, use the ContainsLines method instead.
|
||||
func (self *ViewDriver) Lines(matchers ...*TextMatcher) *ViewDriver {
|
||||
self.validateMatchersPassed(matchers)
|
||||
self.LineCount(len(matchers))
|
||||
self.LineCount(EqualsInt(len(matchers)))
|
||||
|
||||
return self.assertLines(0, matchers...)
|
||||
}
|
||||
@ -470,33 +470,60 @@ func (self *ViewDriver) IsEmpty() *ViewDriver {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *ViewDriver) LineCount(expectedCount int) *ViewDriver {
|
||||
if expectedCount == 0 {
|
||||
return self.IsEmpty()
|
||||
}
|
||||
|
||||
func (self *ViewDriver) LineCount(matcher *IntMatcher) *ViewDriver {
|
||||
view := self.getView()
|
||||
|
||||
self.t.assertWithRetries(func() (bool, string) {
|
||||
lines := view.BufferLines()
|
||||
return len(lines) == expectedCount, fmt.Sprintf("unexpected number of lines in view '%s'. Expected %d, got %d", view.Name(), expectedCount, len(lines))
|
||||
lineCount := self.getLineCount()
|
||||
ok, _ := matcher.test(lineCount)
|
||||
return ok, fmt.Sprintf("unexpected number of lines in view '%s'. Expected %s, got %d", view.Name(), matcher.name(), lineCount)
|
||||
})
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *ViewDriver) getLineCount() int {
|
||||
// can't rely entirely on view.BufferLines because it returns 1 even if there's nothing in the view
|
||||
if strings.TrimSpace(self.getView().Buffer()) == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
view := self.getView()
|
||||
return len(view.BufferLines())
|
||||
}
|
||||
|
||||
func (self *ViewDriver) IsVisible() *ViewDriver {
|
||||
self.t.assertWithRetries(func() (bool, string) {
|
||||
lines := view.BufferLines()
|
||||
|
||||
// if the view has a single blank line (often the case) we want to treat that as having no lines
|
||||
if len(lines) == 1 && expectedCount == 1 {
|
||||
actual := strings.TrimSpace(view.Buffer())
|
||||
return actual != "", fmt.Sprintf("unexpected number of lines in view '%s'. Expected 1, got 0", view.Name())
|
||||
}
|
||||
|
||||
return len(lines) == expectedCount, fmt.Sprintf("unexpected number of lines in view '%s'. Expected %d, got %d", view.Name(), expectedCount, len(lines))
|
||||
return self.getView().Visible, fmt.Sprintf("%s: Expected view to be visible, but it was not", self.context)
|
||||
})
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *ViewDriver) IsInvisible() *ViewDriver {
|
||||
self.t.assertWithRetries(func() (bool, string) {
|
||||
return !self.getView().Visible, fmt.Sprintf("%s: Expected view to be visible, but it was not", self.context)
|
||||
})
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// will filter or search depending on whether the view supports filtering/searching
|
||||
func (self *ViewDriver) FilterOrSearch(text string) *ViewDriver {
|
||||
self.IsFocused()
|
||||
|
||||
self.Press(self.t.keys.Universal.StartSearch).
|
||||
Tap(func() {
|
||||
self.t.ExpectSearch().
|
||||
Type(text).
|
||||
Confirm()
|
||||
|
||||
self.t.Views().Search().IsVisible().Content(Contains(fmt.Sprintf("matches for '%s'", text)))
|
||||
})
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// for when you want to make some assertion unrelated to the current view
|
||||
// without breaking the method chain
|
||||
func (self *ViewDriver) Tap(f func()) *ViewDriver {
|
||||
|
Reference in New Issue
Block a user