cleaner test assertions

This commit is contained in:
Jesse Duffield 2022-12-26 11:12:56 +11:00
parent fa0414777f
commit 9a6f21ce42
34 changed files with 442 additions and 378 deletions

View file

@ -3,10 +3,9 @@ package components
import ( import (
"fmt" "fmt"
"os" "os"
"regexp"
"strings"
"time" "time"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
) )
@ -21,46 +20,6 @@ func NewAssert(gui integrationTypes.GuiDriver) *Assert {
return &Assert{gui: gui} return &Assert{gui: gui}
} }
func Contains(target string) *matcher {
return NewMatcher(
fmt.Sprintf("contains '%s'", target),
func(value string) (bool, string) {
return strings.Contains(value, target), fmt.Sprintf("Expected '%s' to be found in '%s'", target, value)
},
)
}
func NotContains(target string) *matcher {
return NewMatcher(
fmt.Sprintf("does not contain '%s'", target),
func(value string) (bool, string) {
return !strings.Contains(value, target), fmt.Sprintf("Expected '%s' to NOT be found in '%s'", target, value)
},
)
}
func MatchesRegexp(target string) *matcher {
return NewMatcher(
fmt.Sprintf("matches regular expression '%s'", target),
func(value string) (bool, string) {
matched, err := regexp.MatchString(target, value)
if err != nil {
return false, fmt.Sprintf("Unexpected error parsing regular expression '%s': %s", target, err.Error())
}
return matched, fmt.Sprintf("Expected '%s' to match regular expression '%s'", value, target)
},
)
}
func Equals(target string) *matcher {
return NewMatcher(
fmt.Sprintf("equals '%s'", target),
func(value string) (bool, string) {
return target == value, fmt.Sprintf("Expected '%s' to equal '%s'", value, target)
},
)
}
func (self *Assert) WorkingTreeFileCount(expectedCount int) { func (self *Assert) WorkingTreeFileCount(expectedCount int) {
self.assertWithRetries(func() (bool, string) { self.assertWithRetries(func() (bool, string) {
actualCount := len(self.gui.Model().Files) actualCount := len(self.gui.Model().Files)
@ -114,13 +73,6 @@ func (self *Assert) HeadCommitMessage(matcher *matcher) {
) )
} }
func (self *Assert) CurrentViewName(expectedViewName string) {
self.assertWithRetries(func() (bool, string) {
actual := self.gui.CurrentContext().GetView().Name()
return actual == expectedViewName, fmt.Sprintf("Expected current view name to be '%s', but got '%s'", expectedViewName, actual)
})
}
func (self *Assert) CurrentWindowName(expectedWindowName string) { func (self *Assert) CurrentWindowName(expectedWindowName string) {
self.assertWithRetries(func() (bool, string) { self.assertWithRetries(func() (bool, string) {
actual := self.gui.CurrentContext().GetView().Name() actual := self.gui.CurrentContext().GetView().Name()
@ -143,21 +95,6 @@ func (self *Assert) InListContext() {
}) })
} }
func (self *Assert) CurrentLine(matcher *matcher) {
self.matchString(matcher, "Unexpected selected line.",
func() string {
return self.gui.CurrentContext().GetView().SelectedLine()
},
)
}
func (self *Assert) CurrentLineIdx(expected int) {
self.assertWithRetries(func() (bool, string) {
actual := self.gui.CurrentContext().GetView().SelectedLineIdx()
return expected == actual, fmt.Sprintf("Expected selected line index to be %d, got %d", expected, actual)
})
}
func (self *Assert) InPrompt() { func (self *Assert) InPrompt() {
self.assertWithRetries(func() (bool, string) { self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView() currentView := self.gui.CurrentContext().GetView()
@ -200,87 +137,6 @@ func (self *Assert) NotInPopup() {
}) })
} }
func (self *Assert) CurrentViewTitle(matcher *matcher) {
self.matchString(matcher, "Unexpected current view title.",
func() string {
return self.gui.CurrentContext().GetView().Title
},
)
}
func (self *Assert) ViewContent(viewName string, matcher *matcher) {
self.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", viewName),
func() string {
return self.gui.View(viewName).Buffer()
},
)
}
// asserts that the given view has lines matching the given matchers.
func (self *Assert) ViewLines(viewName string, matchers ...*matcher) {
self.assertWithRetries(func() (bool, string) {
lines := self.gui.View(viewName).BufferLines()
return len(lines) == len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", len(matchers), len(lines))
})
for i, matcher := range matchers {
self.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", viewName),
func() string {
return self.gui.View(viewName).BufferLines()[i]
},
)
}
}
func (self *Assert) CurrentViewLines(matchers ...*matcher) {
self.ViewLines(self.gui.CurrentContext().GetView().Name(), matchers...)
}
// asserts that the given view has lines matching the given matchers. So if three matchers
// are passed, we only check the first three lines of the view.
func (self *Assert) ViewTopLines(viewName string, matchers ...*matcher) {
self.assertWithRetries(func() (bool, string) {
lines := self.gui.View(viewName).BufferLines()
return len(lines) >= len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected at least %d, got %d", len(matchers), len(lines))
})
for i, matcher := range matchers {
self.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", viewName),
func() string {
return self.gui.View(viewName).BufferLines()[i]
},
)
}
}
func (self *Assert) CurrentViewTopLines(matchers ...*matcher) {
self.ViewTopLines(self.gui.CurrentContext().GetView().Name(), matchers...)
}
func (self *Assert) CurrentViewContent(matcher *matcher) {
self.matchString(matcher, "Unexpected content in current view.",
func() string {
return self.gui.CurrentContext().GetView().Buffer()
},
)
}
func (self *Assert) MainViewContent(matcher *matcher) {
self.matchString(matcher, "Unexpected main view content.",
func() string {
return self.gui.MainView().Buffer()
},
)
}
func (self *Assert) SecondaryViewContent(matcher *matcher) {
self.matchString(matcher, "Unexpected secondary view title.",
func() string {
return self.gui.SecondaryView().Buffer()
},
)
}
func (self *Assert) matchString(matcher *matcher, context string, getValue func() string) { func (self *Assert) matchString(matcher *matcher, context string, getValue func() string) {
self.assertWithRetries(func() (bool, string) { self.assertWithRetries(func() (bool, string) {
value := getValue() value := getValue()
@ -325,3 +181,35 @@ func (self *Assert) FileSystemPathNotPresent(path string) {
return os.IsNotExist(err), fmt.Sprintf("Expected path '%s' to not exist, but it does", path) return os.IsNotExist(err), fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
}) })
} }
func (self *Assert) CurrentView() *ViewAsserter {
return &ViewAsserter{
context: "current view",
getView: func() *gocui.View { return self.gui.CurrentContext().GetView() },
assert: self,
}
}
func (self *Assert) View(viewName string) *ViewAsserter {
return &ViewAsserter{
context: fmt.Sprintf("%s view", viewName),
getView: func() *gocui.View { return self.gui.View(viewName) },
assert: self,
}
}
func (self *Assert) MainView() *ViewAsserter {
return &ViewAsserter{
context: "main view",
getView: func() *gocui.View { return self.gui.MainView() },
assert: self,
}
}
func (self *Assert) SecondaryView() *ViewAsserter {
return &ViewAsserter{
context: "secondary view",
getView: func() *gocui.View { return self.gui.SecondaryView() },
assert: self,
}
}

View file

@ -103,7 +103,7 @@ func (self *Input) PreviousItem() {
func (self *Input) ContinueMerge() { func (self *Input) ContinueMerge() {
self.Press(self.keys.Universal.CreateRebaseOptionsMenu) self.Press(self.keys.Universal.CreateRebaseOptionsMenu)
self.assert.CurrentLine(Contains("continue")) self.assert.CurrentView().SelectedLine(Contains("continue"))
self.Confirm() self.Confirm()
} }
@ -166,41 +166,41 @@ func (self *Input) NavigateToListItem(matcher *matcher) {
selectedLineIdx := view.SelectedLineIdx() selectedLineIdx := view.SelectedLineIdx()
if selectedLineIdx == matchIndex { if selectedLineIdx == matchIndex {
self.assert.CurrentLine(matcher) self.assert.CurrentView().SelectedLine(matcher)
return return
} }
if selectedLineIdx < matchIndex { if selectedLineIdx < matchIndex {
for i := selectedLineIdx; i < matchIndex; i++ { for i := selectedLineIdx; i < matchIndex; i++ {
self.NextItem() self.NextItem()
} }
self.assert.CurrentLine(matcher) self.assert.CurrentView().SelectedLine(matcher)
return return
} else { } else {
for i := selectedLineIdx; i > matchIndex; i-- { for i := selectedLineIdx; i > matchIndex; i-- {
self.PreviousItem() self.PreviousItem()
} }
self.assert.CurrentLine(matcher) self.assert.CurrentView().SelectedLine(matcher)
return return
} }
} }
func (self *Input) AcceptConfirmation(title *matcher, content *matcher) { func (self *Input) AcceptConfirmation(title *matcher, content *matcher) {
self.assert.InConfirm() self.assert.InConfirm()
self.assert.CurrentViewTitle(title) self.assert.CurrentView().Title(title)
self.assert.CurrentViewContent(content) self.assert.CurrentView().Content(content)
self.Confirm() self.Confirm()
} }
func (self *Input) DenyConfirmation(title *matcher, content *matcher) { func (self *Input) DenyConfirmation(title *matcher, content *matcher) {
self.assert.InConfirm() self.assert.InConfirm()
self.assert.CurrentViewTitle(title) self.assert.CurrentView().Title(title)
self.assert.CurrentViewContent(content) self.assert.CurrentView().Content(content)
self.Cancel() self.Cancel()
} }
func (self *Input) Prompt(title *matcher, textToType string) { func (self *Input) Prompt(title *matcher, textToType string) {
self.assert.InPrompt() self.assert.InPrompt()
self.assert.CurrentViewTitle(title) self.assert.CurrentView().Title(title)
self.Type(textToType) self.Type(textToType)
self.Confirm() self.Confirm()
} }
@ -209,24 +209,24 @@ func (self *Input) Prompt(title *matcher, textToType string) {
// item to match the given matcher, then confirm that item. // item to match the given matcher, then confirm that item.
func (self *Input) Typeahead(title *matcher, textToType string, expectedFirstOption *matcher) { func (self *Input) Typeahead(title *matcher, textToType string, expectedFirstOption *matcher) {
self.assert.InPrompt() self.assert.InPrompt()
self.assert.CurrentViewTitle(title) self.assert.CurrentView().Title(title)
self.Type(textToType) self.Type(textToType)
self.Press(self.keys.Universal.TogglePanel) self.Press(self.keys.Universal.TogglePanel)
self.assert.CurrentViewName("suggestions") self.assert.CurrentView().Name("suggestions")
self.assert.CurrentLine(expectedFirstOption) self.assert.CurrentView().SelectedLine(expectedFirstOption)
self.Confirm() self.Confirm()
} }
func (self *Input) Menu(title *matcher, optionToSelect *matcher) { func (self *Input) Menu(title *matcher, optionToSelect *matcher) {
self.assert.InMenu() self.assert.InMenu()
self.assert.CurrentViewTitle(title) self.assert.CurrentView().Title(title)
self.NavigateToListItem(optionToSelect) self.NavigateToListItem(optionToSelect)
self.Confirm() self.Confirm()
} }
func (self *Input) Alert(title *matcher, content *matcher) { func (self *Input) Alert(title *matcher, content *matcher) {
self.assert.InListContext() self.assert.InListContext()
self.assert.CurrentViewTitle(title) self.assert.CurrentView().Title(title)
self.assert.CurrentViewContent(content) self.assert.CurrentView().Content(content)
self.Confirm() self.Confirm()
} }

View file

@ -1,5 +1,11 @@
package components package components
import (
"fmt"
"regexp"
"strings"
)
// for making assertions on string values // for making assertions on string values
type matcher struct { type matcher struct {
// e.g. "contains 'foo'" // e.g. "contains 'foo'"
@ -33,3 +39,43 @@ func (self *matcher) context(prefix string) *matcher {
return self return self
} }
func Contains(target string) *matcher {
return NewMatcher(
fmt.Sprintf("contains '%s'", target),
func(value string) (bool, string) {
return strings.Contains(value, target), fmt.Sprintf("Expected '%s' to be found in '%s'", target, value)
},
)
}
func NotContains(target string) *matcher {
return NewMatcher(
fmt.Sprintf("does not contain '%s'", target),
func(value string) (bool, string) {
return !strings.Contains(value, target), fmt.Sprintf("Expected '%s' to NOT be found in '%s'", target, value)
},
)
}
func MatchesRegexp(target string) *matcher {
return NewMatcher(
fmt.Sprintf("matches regular expression '%s'", target),
func(value string) (bool, string) {
matched, err := regexp.MatchString(target, value)
if err != nil {
return false, fmt.Sprintf("Unexpected error parsing regular expression '%s': %s", target, err.Error())
}
return matched, fmt.Sprintf("Expected '%s' to match regular expression '%s'", value, target)
},
)
}
func Equals(target string) *matcher {
return NewMatcher(
fmt.Sprintf("equals '%s'", target),
func(value string) (bool, string) {
return target == value, fmt.Sprintf("Expected '%s' to equal '%s'", value, target)
},
)
}

View file

@ -0,0 +1,111 @@
package components
import (
"fmt"
"github.com/jesseduffield/gocui"
)
type ViewAsserter struct {
// context is prepended to any error messages e.g. 'context: "current view"'
context string
getView func() *gocui.View
assert *Assert
}
// asserts that the view has the expected name. This is typically used in tandem with the CurrentView method i.e.;
// assert.CurrentView().Name("commits") to assert that the current view is the commits view.
func (self *ViewAsserter) Name(expected string) *ViewAsserter {
self.assert.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
}
// asserts that the view has the expected title
func (self *ViewAsserter) Title(expected *matcher) *ViewAsserter {
self.assert.assertWithRetries(func() (bool, string) {
actual := self.getView().Title
return expected.context(fmt.Sprintf("%s title", self.context)).test(actual)
})
return self
}
// asserts that the view has lines matching the given matchers. So if three matchers
// are passed, we only check the first three lines of the 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 *ViewAsserter) TopLines(matchers ...*matcher) *ViewAsserter {
self.assert.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))
})
view := self.getView()
for i, matcher := range matchers {
self.assert.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", view.Name()),
func() string {
return view.BufferLines()[i]
},
)
}
return self
}
// 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 *ViewAsserter) Lines(matchers ...*matcher) *ViewAsserter {
self.assert.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))
})
view := self.getView()
for i, matcher := range matchers {
self.assert.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", view.Name()),
func() string {
return view.BufferLines()[i]
},
)
}
return self
}
// asserts on the content of the view i.e. the stuff within the view's frame.
func (self *ViewAsserter) Content(matcher *matcher) *ViewAsserter {
self.assert.matchString(matcher, fmt.Sprintf("%s: Unexpected content.", self.context),
func() string {
return self.getView().Buffer()
},
)
return self
}
// asserts on the selected line of the view
func (self *ViewAsserter) SelectedLine(matcher *matcher) *ViewAsserter {
self.assert.matchString(matcher, fmt.Sprintf("%s: Unexpected selected line.", self.context),
func() string {
return self.getView().SelectedLine()
},
)
return self
}
// asserts on the index of the selected line. 0 is the first index, representing the line at the top of the view.
func (self *ViewAsserter) SelectedLineIdx(expected int) *ViewAsserter {
self.assert.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)
})
return self
}

View file

@ -34,39 +34,40 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentLine(Contains("commit 10")) assert.CurrentView().SelectedLine(Contains("commit 10"))
input.NavigateToListItem(Contains("commit 09")) input.NavigateToListItem(Contains("commit 09"))
markCommitAsBad() markCommitAsBad()
assert.ViewContent("information", Contains("bisecting")) assert.View("information").Content(Contains("bisecting"))
assert.CurrentViewName("commits") assert.CurrentView().Name("commits")
assert.CurrentLine(Contains("<-- bad")) assert.CurrentView().SelectedLine(Contains("<-- bad"))
input.NavigateToListItem(Contains("commit 02")) input.NavigateToListItem(Contains("commit 02"))
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.
assert.CurrentViewName("commits") assert.CurrentView().
assert.CurrentLine(Contains("commit 05")) Name("commits").
assert.CurrentLine(Contains("<-- current")) SelectedLine(Contains("commit 05")).
SelectedLine(Contains("<-- current"))
markCommitAsBad() markCommitAsBad()
assert.CurrentViewName("commits") assert.CurrentView().
assert.CurrentLine(Contains("commit 04")) Name("commits").
assert.CurrentLine(Contains("<-- current")) SelectedLine(Contains("commit 04")).
SelectedLine(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.Alert(Equals("Bisect complete"), MatchesRegexp("(?s)commit 05.*Do you want to reset")) input.Alert(Equals("Bisect complete"), MatchesRegexp("(?s)commit 05.*Do you want to reset"))
assert.CurrentViewName("commits") assert.CurrentView().Name("commits").Content(Contains("commit 04"))
assert.CurrentViewContent(Contains("commit 04")) assert.View("information").Content(NotContains("bisecting"))
assert.ViewContent("information", NotContains("bisecting"))
}, },
}) })

View file

@ -24,13 +24,13 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert *Assert, assert *Assert,
keys config.KeybindingConfig, keys config.KeybindingConfig,
) { ) {
assert.ViewContent("information", Contains("bisecting")) assert.View("information").Content(Contains("bisecting"))
assert.AtLeastOneCommit() assert.AtLeastOneCommit()
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.ViewTopLines("commits", assert.CurrentView().Name("commits").TopLines(
MatchesRegexp(`<-- bad.*commit 08`), MatchesRegexp(`<-- bad.*commit 08`),
MatchesRegexp(`<-- current.*commit 07`), MatchesRegexp(`<-- current.*commit 07`),
MatchesRegexp(`\?.*commit 06`), MatchesRegexp(`\?.*commit 06`),
@ -44,11 +44,10 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
input.Alert(Equals("Bisect complete"), MatchesRegexp(`(?s)commit 08.*Do you want to reset`)) input.Alert(Equals("Bisect complete"), MatchesRegexp(`(?s)commit 08.*Do you want to reset`))
assert.ViewContent("information", NotContains("bisecting")) assert.View("information").Content(NotContains("bisecting"))
// back in master branch which just had the one commit // back in master branch which just had the one commit
assert.CurrentViewName("commits") assert.CurrentView().Name("commits").Lines(
assert.CurrentViewLines(
Contains("only commit on master"), Contains("only commit on master"),
) )
}, },

View file

@ -19,9 +19,8 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches")
assert.CurrentViewLines( assert.CurrentView().Name("localBranches").Lines(
Contains("master"), Contains("master"),
Contains("@"), Contains("@"),
) )
@ -33,13 +32,12 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
input.Alert(Equals("Branch not found"), Equals("Branch not found. Create a new branch named new-branch?")) input.Alert(Equals("Branch not found"), Equals("Branch not found. Create a new branch named new-branch?"))
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches").
assert.CurrentViewLines( Lines(
MatchesRegexp(`\*.*new-branch`), MatchesRegexp(`\*.*new-branch`),
Contains("master"), Contains("master"),
Contains("@"), Contains("@"),
) ).
SelectedLine(Contains("new-branch"))
assert.CurrentLine(Contains("new-branch"))
}, },
}) })

View file

@ -18,9 +18,8 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches")
assert.CurrentViewLines( assert.CurrentView().Name("localBranches").Lines(
MatchesRegexp(`\*.*branch-two`), MatchesRegexp(`\*.*branch-two`),
MatchesRegexp(`branch-one`), MatchesRegexp(`branch-one`),
MatchesRegexp(`master`), MatchesRegexp(`master`),
@ -34,11 +33,11 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Universal.Remove) input.Press(keys.Universal.Remove)
input.AcceptConfirmation(Equals("Delete Branch"), Contains("Are you sure you want to delete the branch 'branch-one'?")) input.AcceptConfirmation(Equals("Delete Branch"), Contains("Are you sure you want to delete the branch 'branch-one'?"))
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches").
assert.CurrentViewLines( Lines(
MatchesRegexp(`\*.*branch-two`), MatchesRegexp(`\*.*branch-two`),
MatchesRegexp(`master`), MatchesRegexp(`master`),
) ).
assert.CurrentLineIdx(1) SelectedLineIdx(1)
}, },
}) })

View file

@ -16,17 +16,15 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches")
assert.ViewLines( assert.View("localBranches").Lines(
"localBranches",
Contains("first-change-branch"), Contains("first-change-branch"),
Contains("second-change-branch"), Contains("second-change-branch"),
Contains("original-branch"), Contains("original-branch"),
) )
assert.ViewTopLines( assert.View("commits").TopLines(
"commits",
Contains("first change"), Contains("first change"),
Contains("original"), Contains("original"),
) )
@ -35,27 +33,24 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Branches.RebaseBranch) input.Press(keys.Branches.RebaseBranch)
input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")) input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?"))
input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!"))
assert.CurrentViewName("files") assert.CurrentView().Name("files").SelectedLine(Contains("file"))
assert.CurrentLine(Contains("file"))
// not using Confirm() convenience method because I suspect we might change this // not using Confirm() convenience method because I suspect we might change this
// keybinding to something more bespoke // keybinding to something more bespoke
input.Press(keys.Universal.Confirm) input.Press(keys.Universal.Confirm)
assert.CurrentViewName("mergeConflicts") assert.CurrentView().Name("mergeConflicts")
input.PrimaryAction() input.PrimaryAction()
assert.ViewContent("information", Contains("rebasing")) assert.View("information").Content(Contains("rebasing"))
input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?"))
assert.ViewContent("information", NotContains("rebasing")) assert.View("information").Content(NotContains("rebasing"))
assert.ViewTopLines( assert.View("commits").TopLines(
"commits",
Contains("second-change-branch unrelated change"), Contains("second-change-branch unrelated change"),
Contains("second change"), Contains("second change"),
Contains("original"), Contains("original"),

View file

@ -19,17 +19,14 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches")
assert.ViewLines( assert.CurrentView().Name("localBranches").Lines(
"localBranches",
Contains("first-change-branch"), Contains("first-change-branch"),
Contains("second-change-branch"), Contains("second-change-branch"),
Contains("original-branch"), Contains("original-branch"),
) )
assert.ViewTopLines( assert.View("commits").TopLines(
"commits",
Contains("to keep"), Contains("to keep"),
Contains("to remove"), Contains("to remove"),
Contains("first change"), Contains("first change"),
@ -41,26 +38,29 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")) input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?"))
assert.ViewContent("information", Contains("rebasing")) assert.View("information").Content(Contains("rebasing"))
input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!"))
assert.CurrentViewName("files") assert.CurrentView().
assert.CurrentLine(Contains("file")) Name("files").
SelectedLine(Contains("file"))
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.ViewTopLines( assert.CurrentView().
"commits", Name("commits").
MatchesRegexp(`pick.*to keep`), TopLines(
MatchesRegexp(`pick.*to remove`), MatchesRegexp(`pick.*to keep`),
MatchesRegexp("YOU ARE HERE.*second-change-branch unrelated change"), MatchesRegexp(`pick.*to remove`),
MatchesRegexp("second change"), MatchesRegexp("YOU ARE HERE.*second-change-branch unrelated change"),
MatchesRegexp("original"), MatchesRegexp("second change"),
) MatchesRegexp("original"),
assert.CurrentLineIdx(0) ).
SelectedLineIdx(0)
input.NextItem() input.NextItem()
input.Press(keys.Universal.Remove) input.Press(keys.Universal.Remove)
assert.CurrentLine(MatchesRegexp(`drop.*to remove`)) assert.CurrentView().SelectedLine(MatchesRegexp(`drop.*to remove`))
input.SwitchToFilesWindow() input.SwitchToFilesWindow()
@ -68,15 +68,14 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
// keybinding to something more bespoke // keybinding to something more bespoke
input.Press(keys.Universal.Confirm) input.Press(keys.Universal.Confirm)
assert.CurrentViewName("mergeConflicts") assert.CurrentView().Name("mergeConflicts")
input.PrimaryAction() input.PrimaryAction()
input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?"))
assert.ViewContent("information", NotContains("rebasing")) assert.View("information").Content(NotContains("rebasing"))
assert.ViewTopLines( assert.View("commits").TopLines(
"commits",
Contains("to keep"), Contains("to keep"),
Contains("second-change-branch unrelated change"), Contains("second-change-branch unrelated change"),
Contains("second change"), Contains("second change"),

View file

@ -21,15 +21,14 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
shell.EmptyCommit("current-branch commit") shell.EmptyCommit("current-branch commit")
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.ViewLines("commits", assert.View("commits").Lines(
Contains("current-branch commit"), Contains("current-branch commit"),
Contains("root commit"), Contains("root commit"),
) )
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches")
assert.CurrentViewLines( assert.CurrentView().Name("localBranches").Lines(
Contains("current-branch"), Contains("current-branch"),
Contains("other-branch"), Contains("other-branch"),
) )
@ -40,12 +39,11 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
input.Menu(Contains("reset to other-branch"), Contains("hard reset")) input.Menu(Contains("reset to other-branch"), Contains("hard reset"))
// ensure that we've returned from the menu before continuing // ensure that we've returned from the menu before continuing
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches")
// 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.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits") assert.CurrentView().Name("commits").Lines(
assert.CurrentViewLines(
Contains("other-branch commit"), Contains("other-branch commit"),
Contains("root commit"), Contains("root commit"),
) )

View file

@ -22,7 +22,7 @@ var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches")
input.Press(keys.Branches.CheckoutBranchByName) input.Press(keys.Branches.CheckoutBranchByName)

View file

@ -25,9 +25,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches")
assert.CurrentViewLines( assert.CurrentView().Name("localBranches").Lines(
Contains("first-branch"), Contains("first-branch"),
Contains("second-branch"), Contains("second-branch"),
Contains("master"), Contains("master"),
@ -37,8 +36,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
input.Enter() input.Enter()
assert.CurrentViewName("subCommits") assert.CurrentView().Name("subCommits").Lines(
assert.CurrentViewLines(
Contains("four"), Contains("four"),
Contains("three"), Contains("three"),
Contains("base"), Contains("base"),
@ -46,15 +44,14 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
// copy commits 'four' and 'three' // copy commits 'four' and 'three'
input.Press(keys.Commits.CherryPickCopy) input.Press(keys.Commits.CherryPickCopy)
assert.ViewContent("information", Contains("1 commit copied")) assert.View("information").Content(Contains("1 commit copied"))
input.NextItem() input.NextItem()
input.Press(keys.Commits.CherryPickCopy) input.Press(keys.Commits.CherryPickCopy)
assert.ViewContent("information", Contains("2 commits copied")) assert.View("information").Content(Contains("2 commits copied"))
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits")
assert.CurrentViewLines( assert.CurrentView().Name("commits").Lines(
Contains("two"), Contains("two"),
Contains("one"), Contains("one"),
Contains("base"), Contains("base"),
@ -63,8 +60,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Commits.PasteCommits) input.Press(keys.Commits.PasteCommits)
input.Alert(Equals("Cherry-Pick"), Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")) input.Alert(Equals("Cherry-Pick"), Contains("Are you sure you want to cherry-pick the copied commits onto this branch?"))
assert.CurrentViewName("commits") assert.CurrentView().Name("commits").Lines(
assert.CurrentViewLines(
Contains("four"), Contains("four"),
Contains("three"), Contains("three"),
Contains("two"), Contains("two"),
@ -72,8 +68,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("base"), Contains("base"),
) )
assert.ViewContent("information", Contains("2 commits copied")) assert.View("information").Content(Contains("2 commits copied"))
input.Press(keys.Universal.Return) input.Press(keys.Universal.Return)
assert.ViewContent("information", NotContains("commits copied")) assert.View("information").Content(NotContains("commits copied"))
}, },
}) })

View file

@ -16,9 +16,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches").Lines(
assert.CurrentViewLines(
Contains("first-change-branch"), Contains("first-change-branch"),
Contains("second-change-branch"), Contains("second-change-branch"),
Contains("original-branch"), Contains("original-branch"),
@ -28,24 +26,21 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
input.Enter() input.Enter()
assert.CurrentViewName("subCommits") assert.CurrentView().Name("subCommits").TopLines(
assert.CurrentViewTopLines(
Contains("second-change-branch unrelated change"), Contains("second-change-branch unrelated change"),
Contains("second change"), Contains("second change"),
) )
input.Press(keys.Commits.CherryPickCopy) input.Press(keys.Commits.CherryPickCopy)
assert.ViewContent("information", Contains("1 commit copied")) assert.View("information").Content(Contains("1 commit copied"))
input.NextItem() input.NextItem()
input.Press(keys.Commits.CherryPickCopy) input.Press(keys.Commits.CherryPickCopy)
assert.ViewContent("information", Contains("2 commits copied")) assert.View("information").Content(Contains("2 commits copied"))
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits")
assert.CurrentViewTopLines( assert.CurrentView().Name("commits").TopLines(
Contains("first change"), Contains("first change"),
) )
@ -54,27 +49,26 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!"))
assert.CurrentViewName("files") assert.CurrentView().Name("files")
assert.CurrentLine(Contains("file")) assert.CurrentView().SelectedLine(Contains("file"))
// not using Confirm() convenience method because I suspect we might change this // not using Confirm() convenience method because I suspect we might change this
// keybinding to something more bespoke // keybinding to something more bespoke
input.Press(keys.Universal.Confirm) input.Press(keys.Universal.Confirm)
assert.CurrentViewName("mergeConflicts") assert.CurrentView().Name("mergeConflicts")
// picking 'Second change' // picking 'Second change'
input.NextItem() input.NextItem()
input.PrimaryAction() input.PrimaryAction()
input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?"))
assert.CurrentViewName("files") assert.CurrentView().Name("files")
assert.WorkingTreeFileCount(0) assert.WorkingTreeFileCount(0)
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits")
assert.CurrentViewTopLines( assert.CurrentView().Name("commits").TopLines(
Contains("second-change-branch unrelated change"), Contains("second-change-branch unrelated change"),
Contains("second change"), Contains("second change"),
Contains("first change"), Contains("first change"),
@ -83,11 +77,12 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
// 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'
assert.MainViewContent(Contains("-First Change")) assert.MainView().
assert.MainViewContent(Contains("+Second Change")) Content(Contains("-First Change")).
Content(Contains("+Second Change"))
assert.ViewContent("information", Contains("2 commits copied")) assert.View("information").Content(Contains("2 commits copied"))
input.Press(keys.Universal.Return) input.Press(keys.Universal.Return)
assert.ViewContent("information", NotContains("commits copied")) assert.View("information").Content(NotContains("commits copied"))
}, },
}) })

View file

@ -30,6 +30,6 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
assert.HeadCommitMessage(Equals("first line")) assert.HeadCommitMessage(Equals("first line"))
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.MainViewContent(MatchesRegexp("first line\n\\s*\n\\s*third line")) assert.MainView().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
}, },
}) })

View file

@ -20,8 +20,7 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(3) assert.CommitCount(3)
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits") assert.CurrentView().Name("commits").Lines(
assert.CurrentViewLines(
Contains("commit 3"), Contains("commit 3"),
Contains("commit 2"), Contains("commit 2"),
Contains("commit 1"), Contains("commit 1"),
@ -35,7 +34,7 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentBranchName(branchName) assert.CurrentBranchName(branchName)
assert.ViewLines("commits", assert.View("commits").Lines(
Contains("commit 2"), Contains("commit 2"),
Contains("commit 1"), Contains("commit 1"),
) )

View file

@ -20,13 +20,21 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentView().Name("commits").Lines(
Contains("first commit"),
)
input.Press(keys.Commits.RevertCommit) input.Press(keys.Commits.RevertCommit)
input.AcceptConfirmation(Equals("Revert commit"), MatchesRegexp(`Are you sure you want to revert \w+?`)) input.AcceptConfirmation(Equals("Revert commit"), MatchesRegexp(`Are you sure you want to revert \w+?`))
assert.CommitCount(2) assert.CurrentView().Name("commits").
assert.HeadCommitMessage(Contains("Revert \"first commit\"")) Lines(
input.PreviousItem() Contains("Revert \"first commit\""),
assert.MainViewContent(Contains("-myfile content")) Contains("first commit"),
).
SelectedLineIdx(0)
assert.MainView().Content(Contains("-myfile content"))
assert.FileSystemPathNotPresent("myfile") assert.FileSystemPathNotPresent("myfile")
}, },
}) })

View file

@ -18,26 +18,26 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0) assert.CommitCount(0)
assert.CurrentViewName("files") assert.CurrentView().Name("files")
assert.CurrentLine(Contains("myfile")) assert.CurrentView().SelectedLine(Contains("myfile"))
// stage the file // stage the file
input.PrimaryAction() input.PrimaryAction()
input.Enter() input.Enter()
assert.CurrentViewName("stagingSecondary") assert.CurrentView().Name("stagingSecondary")
// we start with both lines having been staged // we start with both lines having been staged
assert.ViewContent("stagingSecondary", Contains("+myfile content")) assert.View("stagingSecondary").Content(Contains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line")) assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.ViewContent("staging", NotContains("+myfile content")) assert.View("staging").Content(NotContains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line")) assert.View("staging").Content(NotContains("+with a second line"))
// unstage the selected line // unstage the selected line
input.PrimaryAction() input.PrimaryAction()
// the line should have been moved to the main view // the line should have been moved to the main view
assert.ViewContent("stagingSecondary", NotContains("+myfile content")) assert.View("stagingSecondary").Content(NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line")) assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.ViewContent("staging", Contains("+myfile content")) assert.View("staging").Content(Contains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line")) assert.View("staging").Content(NotContains("+with a second line"))
input.Press(keys.Files.CommitChanges) input.Press(keys.Files.CommitChanges)
commitMessage := "my commit message" commitMessage := "my commit message"

View file

@ -19,36 +19,36 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(0) assert.CommitCount(0)
// stage the file // stage the file
assert.CurrentViewName("files") assert.CurrentView().Name("files")
assert.CurrentLine(Contains("myfile")) assert.CurrentView().SelectedLine(Contains("myfile"))
input.PrimaryAction() input.PrimaryAction()
input.Enter() input.Enter()
assert.CurrentViewName("stagingSecondary") assert.CurrentView().Name("stagingSecondary")
// we start with both lines having been staged // we start with both lines having been staged
assert.ViewContent("stagingSecondary", Contains("+myfile content")) assert.View("stagingSecondary").Content(Contains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line")) assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.ViewContent("staging", NotContains("+myfile content")) assert.View("staging").Content(NotContains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line")) assert.View("staging").Content(NotContains("+with a second line"))
// unstage the selected line // unstage the selected line
input.PrimaryAction() input.PrimaryAction()
// the line should have been moved to the main view // the line should have been moved to the main view
assert.ViewContent("stagingSecondary", NotContains("+myfile content")) assert.View("stagingSecondary").Content(NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line")) assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.ViewContent("staging", Contains("+myfile content")) assert.View("staging").Content(Contains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line")) assert.View("staging").Content(NotContains("+with a second line"))
input.Press(keys.Files.CommitChangesWithoutHook) input.Press(keys.Files.CommitChangesWithoutHook)
assert.InCommitMessagePanel() assert.InCommitMessagePanel()
assert.CurrentViewContent(Contains("WIP")) assert.CurrentView().Content(Contains("WIP"))
commitMessage := ": my commit message" commitMessage := ": my commit message"
input.Type(commitMessage) input.Type(commitMessage)
input.Confirm() input.Confirm()
assert.CommitCount(1) assert.CommitCount(1)
assert.HeadCommitMessage(Equals("WIP" + commitMessage)) assert.HeadCommitMessage(Equals("WIP" + commitMessage))
assert.CurrentViewName("stagingSecondary") assert.CurrentView().Name("stagingSecondary")
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed) // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
}, },

View file

@ -20,15 +20,14 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0) assert.CommitCount(0)
assert.CurrentViewName("files") assert.CurrentView().Name("files").SelectedLine(Contains("myfile"))
assert.CurrentLine(Contains("myfile"))
input.Enter() input.Enter()
assert.CurrentViewName("staging") assert.CurrentView().Name("staging")
assert.ViewContent("stagingSecondary", NotContains("+myfile content")) assert.View("stagingSecondary").Content(NotContains("+myfile content"))
// stage the first line // stage the first line
input.PrimaryAction() input.PrimaryAction()
assert.ViewContent("staging", NotContains("+myfile content")) assert.View("staging").Content(NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+myfile content")) assert.View("stagingSecondary").Content(Contains("+myfile content"))
input.Press(keys.Files.CommitChanges) input.Press(keys.Files.CommitChanges)
assert.InCommitMessagePanel() assert.InCommitMessagePanel()

View file

@ -21,6 +21,7 @@ var RemoteNamedStar = NewIntegrationTest(NewIntegrationTestArgs{
assert *Assert, assert *Assert,
keys config.KeybindingConfig, keys config.KeybindingConfig,
) { ) {
// here we're just asserting that we haven't panicked upon starting lazygit
assert.AtLeastOneCommit() assert.AtLeastOneCommit()
}, },
}) })

View file

@ -30,7 +30,9 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
assert.WorkingTreeFileCount(0) assert.WorkingTreeFileCount(0)
input.Press("a") input.Press("a")
assert.WorkingTreeFileCount(1)
assert.CurrentLine(Contains("myfile")) assert.View("files").Lines(
Contains("myfile"),
)
}, },
}) })

View file

@ -72,7 +72,7 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
input.AcceptConfirmation(Equals("Are you sure?"), Equals("Are you REALLY sure you want to make this file? Up to you buddy.")) input.AcceptConfirmation(Equals("Are you sure?"), Equals("Are you REALLY sure you want to make this file? Up to you buddy."))
assert.WorkingTreeFileCount(1) assert.WorkingTreeFileCount(1)
assert.CurrentLine(Contains("my file")) assert.CurrentView().SelectedLine(Contains("my file"))
assert.MainViewContent(Contains(`"BAR"`)) assert.MainView().Content(Contains(`"BAR"`))
}, },
}) })

View file

@ -60,7 +60,7 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
input.SwitchToFilesWindow() input.SwitchToFilesWindow()
assert.WorkingTreeFileCount(1) assert.WorkingTreeFileCount(1)
assert.CurrentLine(Contains("output.txt")) assert.CurrentView().SelectedLine(Contains("output.txt"))
assert.MainViewContent(Contains("bar Branch: #feature/foo my branch feature/foo")) assert.MainView().Content(Contains("bar Branch: #feature/foo my branch feature/foo"))
}, },
}) })

View file

@ -55,8 +55,9 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
input.Press("a") input.Press("a")
assert.InPrompt() assert.InPrompt()
assert.CurrentViewTitle(Equals("Which git command do you want to run?")) assert.CurrentView().
assert.CurrentLine(Equals("branch")) Title(Equals("Which git command do you want to run?")).
SelectedLine(Equals("branch"))
input.Confirm() input.Confirm()
input.Menu(Equals("Branch:"), Equals("master")) input.Menu(Equals("Branch:"), Equals("master"))

View file

@ -70,7 +70,7 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{
input.AcceptConfirmation(Equals("Are you sure?"), Equals("Are you REALLY sure you want to make this file? Up to you buddy.")) input.AcceptConfirmation(Equals("Are you sure?"), Equals("Are you REALLY sure you want to make this file? Up to you buddy."))
assert.WorkingTreeFileCount(1) assert.WorkingTreeFileCount(1)
assert.CurrentLine(Contains("myfile")) assert.CurrentView().SelectedLine(Contains("myfile"))
assert.MainViewContent(Contains("BAR")) assert.MainView().Content(Contains("BAR"))
}, },
}) })

View file

@ -23,38 +23,36 @@ var Diff = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches")
assert.CurrentViewTopLines( assert.CurrentView().Name("localBranches").TopLines(
Contains("branch-a"), Contains("branch-a"),
Contains("branch-b"), Contains("branch-b"),
) )
input.Press(keys.Universal.DiffingMenu) input.Press(keys.Universal.DiffingMenu)
input.Menu(Equals("Diffing"), Contains(`diff branch-a`)) input.Menu(Equals("Diffing"), Contains(`diff branch-a`))
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches")
assert.ViewContent("information", Contains("showing output for: git diff branch-a branch-a")) assert.View("information").Content(Contains("showing output for: git diff branch-a branch-a"))
input.NextItem() input.NextItem()
assert.ViewContent("information", Contains("showing output for: git diff branch-a branch-b")) assert.View("information").Content(Contains("showing output for: git diff branch-a branch-b"))
assert.MainViewContent(Contains("+second line")) assert.MainView().Content(Contains("+second line"))
input.Enter() input.Enter()
assert.CurrentViewName("subCommits") assert.CurrentView().Name("subCommits")
assert.MainViewContent(Contains("+second line")) assert.MainView().Content(Contains("+second line"))
assert.CurrentLine(Contains("update")) assert.CurrentView().SelectedLine(Contains("update"))
input.Enter() input.Enter()
assert.CurrentViewName("commitFiles") assert.CurrentView().Name("commitFiles").SelectedLine(Contains("file1"))
assert.CurrentLine(Contains("file1")) assert.MainView().Content(Contains("+second line"))
assert.MainViewContent(Contains("+second line"))
input.Press(keys.Universal.Return) input.Press(keys.Universal.Return)
input.Press(keys.Universal.Return) input.Press(keys.Universal.Return)
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches")
input.Press(keys.Universal.DiffingMenu) input.Press(keys.Universal.DiffingMenu)
input.Menu(Equals("Diffing"), Contains("reverse diff direction")) input.Menu(Equals("Diffing"), Contains("reverse diff direction"))
assert.ViewContent("information", Contains("showing output for: git diff branch-a branch-b -R")) assert.View("information").Content(Contains("showing output for: git diff branch-a branch-b -R"))
assert.MainViewContent(Contains("-second line")) assert.MainView().Content(Contains("-second line"))
}, },
}) })

View file

@ -23,8 +23,7 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToBranchesWindow() input.SwitchToBranchesWindow()
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches").Lines(
assert.CurrentViewLines(
Contains("branch-a"), Contains("branch-a"),
Contains("branch-b"), Contains("branch-b"),
) )
@ -33,21 +32,21 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
input.Menu(Equals("Diffing"), Equals("diff branch-a")) input.Menu(Equals("Diffing"), Equals("diff branch-a"))
assert.CurrentViewName("localBranches") assert.CurrentView().Name("localBranches")
assert.ViewContent("information", Contains("showing output for: git diff branch-a branch-a")) assert.View("information").Content(Contains("showing output for: git diff branch-a branch-a"))
input.NextItem() input.NextItem()
assert.ViewContent("information", Contains("showing output for: git diff branch-a branch-b")) assert.View("information").Content(Contains("showing output for: git diff branch-a branch-b"))
assert.MainViewContent(Contains("+second line")) assert.MainView().Content(Contains("+second line"))
input.Enter() input.Enter()
assert.CurrentViewName("subCommits") assert.CurrentView().Name("subCommits")
assert.MainViewContent(Contains("+second line")) assert.MainView().Content(Contains("+second line"))
assert.CurrentLine(Contains("update")) assert.CurrentView().SelectedLine(Contains("update"))
input.Enter() input.Enter()
assert.CurrentViewName("commitFiles") assert.CurrentView().Name("commitFiles")
assert.CurrentLine(Contains("file1")) assert.CurrentView().SelectedLine(Contains("file1"))
assert.MainViewContent(Contains("+second line")) assert.MainView().Content(Contains("+second line"))
// add the file to the patch // add the file to the patch
input.PrimaryAction() input.PrimaryAction()
@ -55,7 +54,7 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
input.Press(keys.Universal.DiffingMenu) input.Press(keys.Universal.DiffingMenu)
input.Menu(Equals("Diffing"), Contains("exit diff mode")) input.Menu(Equals("Diffing"), Contains("exit diff mode"))
assert.ViewContent("information", NotContains("building patch")) assert.View("information").Content(NotContains("building patch"))
input.Press(keys.Universal.CreatePatchOptionsMenu) input.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
@ -63,7 +62,7 @@ var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
input.SwitchToFilesWindow() input.SwitchToFilesWindow()
assert.CurrentLine(Contains("file1")) assert.CurrentView().SelectedLine(Contains("file1"))
assert.MainViewContent(Contains("+second line")) assert.MainView().Content(Contains("+second line"))
}, },
}) })

View file

@ -20,9 +20,8 @@ var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits")
assert.CurrentViewLines( assert.CurrentView().Name("commits").Lines(
Contains("third commit"), Contains("third commit"),
Contains("second commit"), Contains("second commit"),
Contains("first commit"), Contains("first commit"),
@ -33,24 +32,24 @@ var DiffCommits = NewIntegrationTest(NewIntegrationTestArgs{
assert.NotInPopup() assert.NotInPopup()
assert.ViewContent("information", Contains("showing output for: git diff")) assert.View("information").Content(Contains("showing output for: git diff"))
input.NextItem() input.NextItem()
input.NextItem() input.NextItem()
assert.CurrentLine(Contains("first commit")) assert.CurrentView().SelectedLine(Contains("first commit"))
assert.MainViewContent(Contains("-second line\n-third line")) assert.MainView().Content(Contains("-second line\n-third line"))
input.Press(keys.Universal.DiffingMenu) input.Press(keys.Universal.DiffingMenu)
input.Menu(Equals("Diffing"), Contains("reverse diff direction")) input.Menu(Equals("Diffing"), Contains("reverse diff direction"))
assert.NotInPopup() assert.NotInPopup()
assert.MainViewContent(Contains("+second line\n+third line")) assert.MainView().Content(Contains("+second line\n+third line"))
input.Enter() input.Enter()
assert.CurrentViewName("commitFiles") assert.CurrentView().Name("commitFiles")
assert.CurrentLine(Contains("file1")) assert.CurrentView().SelectedLine(Contains("file1"))
assert.MainViewContent(Contains("+second line\n+third line")) assert.MainView().Content(Contains("+second line\n+third line"))
}, },
}) })

View file

@ -24,9 +24,10 @@ var DirWithUntrackedFile = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(1) assert.CommitCount(1)
assert.MainViewContent(NotContains("error: Could not access")) assert.MainView().
// we show baz because it's a modified file but we don't show bar because it's untracked Content(NotContains("error: Could not access")).
// (though it would be cool if we could show that too) // we show baz because it's a modified file but we don't show bar because it's untracked
assert.MainViewContent(Contains("baz")) // (though it would be cool if we could show that too)
Content(Contains("baz"))
}, },
}) })

View file

@ -82,7 +82,7 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
discardOneByOne := func(files []statusFile) { discardOneByOne := func(files []statusFile) {
for _, file := range files { for _, file := range files {
assert.CurrentLine(Contains(file.status + " " + file.label)) assert.CurrentView().SelectedLine(Contains(file.status + " " + file.label))
input.Press(keys.Universal.Remove) input.Press(keys.Universal.Remove)
input.Menu(Equals(file.menuTitle), Contains("discard all changes")) input.Menu(Equals(file.menuTitle), Contains("discard all changes"))
} }
@ -98,10 +98,7 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
{status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"}, {status: "DU", label: "deleted-us.txt", menuTitle: "deleted-us.txt"},
}) })
assert.InConfirm() input.DenyConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?"))
assert.CurrentViewTitle(Contains("continue"))
assert.CurrentViewContent(Contains("all merge conflicts resolved. Continue?"))
input.Press(keys.Universal.Return)
discardOneByOne([]statusFile{ discardOneByOne([]statusFile{
{status: "MD", label: "change-delete.txt", menuTitle: "change-delete.txt"}, {status: "MD", label: "change-delete.txt", menuTitle: "change-delete.txt"},

View file

@ -31,7 +31,7 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(3) assert.CommitCount(3)
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits") assert.CurrentView().Name("commits")
mergeCommitMessage := "Merge branch 'feature-branch' into development-branch" mergeCommitMessage := "Merge branch 'feature-branch' into development-branch"
assert.HeadCommitMessage(Contains(mergeCommitMessage)) assert.HeadCommitMessage(Contains(mergeCommitMessage))
@ -44,7 +44,8 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
assert.HeadCommitMessage(Contains(mergeCommitMessage)) assert.HeadCommitMessage(Contains(mergeCommitMessage))
// assuring the post-merge file shows up in the merge commit. // assuring the post-merge file shows up in the merge commit.
assert.MainViewContent(Contains(postMergeFilename)) assert.MainView().
assert.MainViewContent(Contains("++" + postMergeFileContent)) Content(Contains(postMergeFilename)).
Content(Contains("++" + postMergeFileContent))
}, },
}) })

View file

@ -16,26 +16,61 @@ var One = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToCommitsWindow() input.SwitchToCommitsWindow()
assert.CurrentViewName("commits") assert.CurrentView().Name("commits").Lines(
Contains("commit 05"),
Contains("commit 04"),
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 01"),
)
input.NavigateToListItem(Contains("commit 02")) input.NavigateToListItem(Contains("commit 02"))
input.Press(keys.Universal.Edit) input.Press(keys.Universal.Edit)
assert.CurrentLine(Contains("YOU ARE HERE"))
assert.CurrentView().Lines(
MatchesRegexp("pick.*commit 05"),
MatchesRegexp("pick.*commit 04"),
MatchesRegexp("pick.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
)
input.PreviousItem() input.PreviousItem()
input.Press(keys.Commits.MarkCommitAsFixup) input.Press(keys.Commits.MarkCommitAsFixup)
assert.CurrentLine(Contains("fixup")) assert.CurrentView().Lines(
MatchesRegexp("pick.*commit 05"),
MatchesRegexp("pick.*commit 04"),
MatchesRegexp("fixup.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
)
input.PreviousItem() input.PreviousItem()
input.Press(keys.Universal.Remove) input.Press(keys.Universal.Remove)
assert.CurrentLine(Contains("drop")) assert.CurrentView().Lines(
MatchesRegexp("pick.*commit 05"),
MatchesRegexp("drop.*commit 04"),
MatchesRegexp("fixup.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
)
input.PreviousItem() input.PreviousItem()
input.Press(keys.Commits.SquashDown) input.Press(keys.Commits.SquashDown)
assert.CurrentLine(Contains("squash"))
assert.CurrentView().Lines(
MatchesRegexp("squash.*commit 05"),
MatchesRegexp("drop.*commit 04"),
MatchesRegexp("fixup.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
)
input.ContinueRebase() input.ContinueRebase()
assert.CommitCount(2) assert.CurrentView().Lines(
Contains("commit 02"),
Contains("commit 01"),
)
}, },
}) })

View file

@ -20,9 +20,8 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
}, },
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
input.SwitchToStashWindow() input.SwitchToStashWindow()
assert.CurrentViewName("stash")
assert.CurrentViewLines( assert.CurrentView().Name("stash").Lines(
Equals("On master: bar"), Equals("On master: bar"),
Equals("On master: foo"), Equals("On master: foo"),
) )
@ -31,6 +30,6 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
input.Prompt(Equals("Rename stash: stash@{1}"), " baz") input.Prompt(Equals("Rename stash: stash@{1}"), " baz")
assert.CurrentLine(Equals("On master: foo baz")) assert.CurrentView().SelectedLine(Equals("On master: foo baz"))
}, },
}) })