mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-21 22:43:27 +02:00
remove dependency on model
This commit is contained in:
parent
c5050ecabd
commit
ed93e0a2b0
@ -49,10 +49,6 @@ func (self *GuiDriver) CurrentContext() types.Context {
|
|||||||
return self.gui.c.CurrentContext()
|
return self.gui.c.CurrentContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *GuiDriver) Model() *types.Model {
|
|
||||||
return self.gui.State.Model
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *GuiDriver) Fail(message string) {
|
func (self *GuiDriver) Fail(message string) {
|
||||||
self.gui.g.Close()
|
self.gui.g.Close()
|
||||||
// need to give the gui time to close
|
// need to give the gui time to close
|
||||||
|
28
pkg/integration/components/git.go
Normal file
28
pkg/integration/components/git.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package components
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Git struct {
|
||||||
|
*assertionHelper
|
||||||
|
shell *Shell
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Git) CurrentBranchName(expectedName string) *Git {
|
||||||
|
return self.assert("git rev-parse --abbrev-ref HEAD", expectedName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Git) assert(cmdStr string, expected string) *Git {
|
||||||
|
self.assertWithRetries(func() (bool, string) {
|
||||||
|
output, err := self.shell.runCommandWithOutput(cmdStr)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Sprintf("Unexpected error running command: `%s`. Error: %s", cmdStr, err.Error())
|
||||||
|
}
|
||||||
|
actual := strings.TrimSpace(output)
|
||||||
|
return actual == expected, fmt.Sprintf("Expected current branch name to be '%s', but got '%s'", expected, actual)
|
||||||
|
})
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
@ -1,84 +0,0 @@
|
|||||||
package components
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Model struct {
|
|
||||||
*assertionHelper
|
|
||||||
gui integrationTypes.GuiDriver
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Model) WorkingTreeFileCount(expectedCount int) *Model {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
actualCount := len(self.gui.Model().Files)
|
|
||||||
|
|
||||||
return actualCount == expectedCount, fmt.Sprintf(
|
|
||||||
"Expected %d changed working tree files, but got %d",
|
|
||||||
expectedCount, actualCount,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Model) CommitCount(expectedCount int) *Model {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
actualCount := len(self.gui.Model().Commits)
|
|
||||||
|
|
||||||
return actualCount == expectedCount, fmt.Sprintf(
|
|
||||||
"Expected %d commits present, but got %d",
|
|
||||||
expectedCount, actualCount,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Model) StashCount(expectedCount int) *Model {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
actualCount := len(self.gui.Model().StashEntries)
|
|
||||||
|
|
||||||
return actualCount == expectedCount, fmt.Sprintf(
|
|
||||||
"Expected %d stash entries, but got %d",
|
|
||||||
expectedCount, actualCount,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Model) AtLeastOneCommit() *Model {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
actualCount := len(self.gui.Model().Commits)
|
|
||||||
|
|
||||||
return actualCount > 0, "Expected at least one commit present"
|
|
||||||
})
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Model) HeadCommitMessage(matcher *matcher) *Model {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
return len(self.gui.Model().Commits) > 0, "Expected at least one commit to be present"
|
|
||||||
})
|
|
||||||
|
|
||||||
self.matchString(matcher, "Unexpected commit message.",
|
|
||||||
func() string {
|
|
||||||
return self.gui.Model().Commits[0].Name
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Model) CurrentBranchName(expectedViewName string) *Model {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
actual := self.gui.CheckedOutRef().Name
|
|
||||||
return actual == expectedViewName, fmt.Sprintf("Expected current branch name to be '%s', but got '%s'", expectedViewName, actual)
|
|
||||||
})
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
@ -38,6 +38,17 @@ func (self *Shell) RunCommand(cmdStr string) *Shell {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Shell) runCommandWithOutput(cmdStr string) (string, error) {
|
||||||
|
args := str.ToArgv(cmdStr)
|
||||||
|
cmd := secureexec.Command(args[0], args[1:]...)
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Dir = self.dir
|
||||||
|
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
return string(output), err
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Shell) RunShellCommand(cmdStr string) *Shell {
|
func (self *Shell) RunShellCommand(cmdStr string) *Shell {
|
||||||
cmd := secureexec.Command("sh", "-c", cmdStr)
|
cmd := secureexec.Command("sh", "-c", cmdStr)
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/env"
|
||||||
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
@ -89,9 +90,12 @@ func (self *IntegrationTest) SetupRepo(shell *Shell) {
|
|||||||
self.setupRepo(shell)
|
self.setupRepo(shell)
|
||||||
}
|
}
|
||||||
|
|
||||||
// I want access to all contexts, the model, the ability to press a key, the ability to log,
|
|
||||||
func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) {
|
func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) {
|
||||||
shell := NewShell("/tmp/lazygit-test", func(errorMsg string) { gui.Fail(errorMsg) })
|
// we pass the --pass arg to lazygit when running an integration test, and that
|
||||||
|
// ends up stored in the following env var
|
||||||
|
repoPath := env.GetGitWorkTreeEnv()
|
||||||
|
|
||||||
|
shell := NewShell(repoPath, func(errorMsg string) { gui.Fail(errorMsg) })
|
||||||
keys := gui.Keys()
|
keys := gui.Keys()
|
||||||
testDriver := NewTestDriver(gui, shell, keys, KeyPressDelay())
|
testDriver := NewTestDriver(gui, shell, keys, KeyPressDelay())
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"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"
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestDriver struct {
|
type TestDriver struct {
|
||||||
@ -220,9 +219,9 @@ func (self *TestDriver) Views() *Views {
|
|||||||
return &Views{t: self}
|
return &Views{t: self}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for making assertions on the lazygit model
|
// for making assertions through git itself
|
||||||
func (self *TestDriver) Model() *Model {
|
func (self *TestDriver) Git() *Git {
|
||||||
return &Model{assertionHelper: self.assertionHelper, gui: self.gui}
|
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for making assertions on the file system
|
// for making assertions on the file system
|
||||||
@ -235,10 +234,3 @@ func (self *TestDriver) FileSystem() *FileSystem {
|
|||||||
func (self *TestDriver) Fail(message string) {
|
func (self *TestDriver) Fail(message string) {
|
||||||
self.assertionHelper.fail(message)
|
self.assertionHelper.fail(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *TestDriver) NotInPopup() {
|
|
||||||
self.assertWithRetries(func() (bool, string) {
|
|
||||||
viewName := self.gui.CurrentContext().GetView().Name()
|
|
||||||
return !lo.Contains([]string{"menu", "confirmation", "commitMessage"}, viewName), fmt.Sprintf("Unexpected popup view present: %s view", viewName)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -30,10 +30,6 @@ func (self *fakeGuiDriver) CurrentContext() types.Context {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *fakeGuiDriver) Model() *types.Model {
|
|
||||||
return &types.Model{Commits: []*models.Commit{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *fakeGuiDriver) Fail(message string) {
|
func (self *fakeGuiDriver) Fail(message string) {
|
||||||
self.failureMessage = message
|
self.failureMessage = message
|
||||||
}
|
}
|
||||||
@ -66,7 +62,6 @@ func TestAssertionFailure(t *testing.T) {
|
|||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.press("a")
|
t.press("a")
|
||||||
t.press("b")
|
t.press("b")
|
||||||
t.Model().CommitCount(2)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
driver := &fakeGuiDriver{}
|
driver := &fakeGuiDriver{}
|
||||||
@ -93,7 +88,6 @@ func TestSuccess(t *testing.T) {
|
|||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.press("a")
|
t.press("a")
|
||||||
t.press("b")
|
t.press("b")
|
||||||
t.Model().CommitCount(0)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
driver := &fakeGuiDriver{}
|
driver := &fakeGuiDriver{}
|
||||||
|
@ -2,6 +2,7 @@ package components
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
@ -28,6 +29,10 @@ func (self *View) Title(expected *matcher) *View {
|
|||||||
// This method is convenient when you have a list of commits but you only want to
|
// This method is convenient when you have a list of commits but you only want to
|
||||||
// assert on the first couple of commits.
|
// assert on the first couple of commits.
|
||||||
func (self *View) TopLines(matchers ...*matcher) *View {
|
func (self *View) TopLines(matchers ...*matcher) *View {
|
||||||
|
if len(matchers) < 1 {
|
||||||
|
self.t.fail("TopLines method requires at least one matcher. If you are trying to assert that there are no lines, use .IsEmpty()")
|
||||||
|
}
|
||||||
|
|
||||||
self.t.assertWithRetries(func() (bool, string) {
|
self.t.assertWithRetries(func() (bool, string) {
|
||||||
lines := self.getView().BufferLines()
|
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))
|
return len(lines) >= len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected at least %d, got %d", len(matchers), len(lines))
|
||||||
@ -39,10 +44,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.
|
// 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.
|
// If you only care about the top n lines, use the TopLines method instead.
|
||||||
func (self *View) Lines(matchers ...*matcher) *View {
|
func (self *View) Lines(matchers ...*matcher) *View {
|
||||||
self.t.assertWithRetries(func() (bool, string) {
|
self.LineCount(len(matchers))
|
||||||
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))
|
|
||||||
})
|
|
||||||
|
|
||||||
return self.assertLines(matchers...)
|
return self.assertLines(matchers...)
|
||||||
}
|
}
|
||||||
@ -184,6 +186,41 @@ func (self *View) NavigateToListItem(matcher *matcher) *View {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns true if the view is a list view and it contains no items
|
||||||
|
func (self *View) IsEmpty() *View {
|
||||||
|
self.t.assertWithRetries(func() (bool, string) {
|
||||||
|
actual := strings.TrimSpace(self.getView().Buffer())
|
||||||
|
return actual == "", fmt.Sprintf("%s: Unexpected content in view: expected no content. Content: %s", self.context, actual)
|
||||||
|
})
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *View) LineCount(expectedCount int) *View {
|
||||||
|
if expectedCount == 0 {
|
||||||
|
return self.IsEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
self.t.assertWithRetries(func() (bool, string) {
|
||||||
|
lines := self.getView().BufferLines()
|
||||||
|
return len(lines) == expectedCount, fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", expectedCount, len(lines))
|
||||||
|
})
|
||||||
|
|
||||||
|
self.t.assertWithRetries(func() (bool, string) {
|
||||||
|
lines := self.getView().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(self.getView().Buffer())
|
||||||
|
return actual == "", fmt.Sprintf("unexpected number of lines in view. Expected %d, got 0", expectedCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(lines) == expectedCount, fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", expectedCount, len(lines))
|
||||||
|
})
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
// for when you want to make some assertion unrelated to the current view
|
// for when you want to make some assertion unrelated to the current view
|
||||||
// without breaking the method chain
|
// without breaking the method chain
|
||||||
func (self *View) Tap(f func()) *View {
|
func (self *View) Tap(f func()) *View {
|
||||||
|
@ -29,8 +29,6 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
t.ExpectMenu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm()
|
t.ExpectMenu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm()
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Model().AtLeastOneCommit()
|
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
Focus().
|
Focus().
|
||||||
SelectedLine(Contains("commit 10")).
|
SelectedLine(Contains("commit 10")).
|
||||||
|
@ -21,8 +21,6 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Views().Information().Content(Contains("bisecting"))
|
t.Views().Information().Content(Contains("bisecting"))
|
||||||
|
|
||||||
t.Model().AtLeastOneCommit()
|
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
Focus().
|
Focus().
|
||||||
TopLines(
|
TopLines(
|
||||||
|
@ -34,6 +34,6 @@ var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SelectFirstSuggestion().
|
SelectFirstSuggestion().
|
||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
t.Model().CurrentBranchName("branch-to-checkout")
|
t.Git().CurrentBranchName("branch-to-checkout")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -70,7 +70,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Content(Contains("all merge conflicts resolved. Continue?")).
|
Content(Contains("all merge conflicts resolved. Continue?")).
|
||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
t.Model().WorkingTreeFileCount(0)
|
t.Views().Files().IsEmpty()
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
Focus().
|
Focus().
|
||||||
|
@ -15,7 +15,8 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.CreateFile("myfile2", "myfile2 content")
|
shell.CreateFile("myfile2", "myfile2 content")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(0)
|
t.Views().Commits().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
@ -28,8 +29,9 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
|
t.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
|
||||||
|
|
||||||
t.Model().
|
t.Views().Commits().
|
||||||
CommitCount(1).
|
Lines(
|
||||||
HeadCommitMessage(Equals(commitMessage))
|
Contains(commitMessage),
|
||||||
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -14,7 +14,8 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.CreateFile("myfile", "myfile content")
|
shell.CreateFile("myfile", "myfile content")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(0)
|
t.Views().Commits().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
@ -23,8 +24,10 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.ExpectCommitMessagePanel().Type("first line").AddNewline().AddNewline().Type("third line").Confirm()
|
t.ExpectCommitMessagePanel().Type("first line").AddNewline().AddNewline().Type("third line").Confirm()
|
||||||
|
|
||||||
t.Model().CommitCount(1)
|
t.Views().Commits().
|
||||||
t.Model().HeadCommitMessage(Equals("first line"))
|
Lines(
|
||||||
|
Contains("first line"),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Commits().Focus()
|
t.Views().Commits().Focus()
|
||||||
t.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
|
t.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
|
||||||
|
@ -17,22 +17,20 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
EmptyCommit("commit 3")
|
EmptyCommit("commit 3")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(3)
|
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
Focus().
|
Focus().
|
||||||
SelectNextItem().
|
|
||||||
Lines(
|
Lines(
|
||||||
Contains("commit 3"),
|
Contains("commit 3").IsSelected(),
|
||||||
Contains("commit 2").IsSelected(),
|
Contains("commit 2"),
|
||||||
Contains("commit 1"),
|
Contains("commit 1"),
|
||||||
).
|
).
|
||||||
|
SelectNextItem().
|
||||||
Press(keys.Universal.New).
|
Press(keys.Universal.New).
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
branchName := "my-branch-name"
|
branchName := "my-branch-name"
|
||||||
t.ExpectPrompt().Title(Contains("New Branch Name")).Type(branchName).Confirm()
|
t.ExpectPrompt().Title(Contains("New Branch Name")).Type(branchName).Confirm()
|
||||||
|
|
||||||
t.Model().CurrentBranchName(branchName)
|
t.Git().CurrentBranchName(branchName)
|
||||||
}).
|
}).
|
||||||
Lines(
|
Lines(
|
||||||
Contains("commit 2"),
|
Contains("commit 2"),
|
||||||
|
@ -16,8 +16,6 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.Commit("first commit")
|
shell.Commit("first commit")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(1)
|
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
Focus().
|
Focus().
|
||||||
Lines(
|
Lines(
|
||||||
|
@ -16,7 +16,8 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
CreateFile("myfile2", "myfile2 content")
|
CreateFile("myfile2", "myfile2 content")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(0)
|
t.Views().Commits().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
@ -47,8 +48,11 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
commitMessage := "my commit message"
|
commitMessage := "my commit message"
|
||||||
t.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
|
t.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
|
||||||
|
|
||||||
t.Model().CommitCount(1)
|
t.Views().Commits().
|
||||||
t.Model().HeadCommitMessage(Equals(commitMessage))
|
Lines(
|
||||||
|
Contains(commitMessage),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().StagingSecondary().IsFocused()
|
t.Views().StagingSecondary().IsFocused()
|
||||||
|
|
||||||
// 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)
|
||||||
|
@ -16,7 +16,8 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
CreateFile("myfile2", "myfile2 content")
|
CreateFile("myfile2", "myfile2 content")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(0)
|
t.Views().Commits().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
// stage the file
|
// stage the file
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
@ -47,8 +48,11 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
commitMessage := ": my commit message"
|
commitMessage := ": my commit message"
|
||||||
t.ExpectCommitMessagePanel().InitialText(Contains("WIP")).Type(commitMessage).Confirm()
|
t.ExpectCommitMessagePanel().InitialText(Contains("WIP")).Type(commitMessage).Confirm()
|
||||||
|
|
||||||
t.Model().CommitCount(1)
|
t.Views().Commits().
|
||||||
t.Model().HeadCommitMessage(Equals("WIP" + commitMessage))
|
Lines(
|
||||||
|
Contains("WIP" + commitMessage),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().StagingSecondary().IsFocused()
|
t.Views().StagingSecondary().IsFocused()
|
||||||
|
|
||||||
// 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)
|
||||||
|
@ -18,7 +18,8 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
CreateFile("myfile2", "myfile2 content")
|
CreateFile("myfile2", "myfile2 content")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(0)
|
t.Views().Commits().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
@ -41,8 +42,11 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
commitMessage := "my commit message"
|
commitMessage := "my commit message"
|
||||||
t.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
|
t.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
|
||||||
|
|
||||||
t.Model().CommitCount(1)
|
t.Views().Commits().
|
||||||
t.Model().HeadCommitMessage(Equals(commitMessage))
|
Lines(
|
||||||
|
Contains(commitMessage),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Staging().IsFocused()
|
t.Views().Staging().IsFocused()
|
||||||
|
|
||||||
// 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)
|
||||||
|
@ -17,6 +17,10 @@ var RemoteNamedStar = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
SetupConfig: func(cfg *config.AppConfig) {},
|
SetupConfig: func(cfg *config.AppConfig) {},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
// here we're just asserting that we haven't panicked upon starting lazygit
|
// here we're just asserting that we haven't panicked upon starting lazygit
|
||||||
t.Model().AtLeastOneCommit()
|
t.Views().Commits().
|
||||||
|
Lines(
|
||||||
|
Anything(),
|
||||||
|
Anything(),
|
||||||
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -22,9 +22,8 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().WorkingTreeFileCount(0)
|
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
IsEmpty().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
Press("a").
|
Press("a").
|
||||||
Lines(
|
Lines(
|
||||||
|
@ -56,9 +56,8 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().WorkingTreeFileCount(0)
|
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
IsEmpty().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
Press("a")
|
Press("a")
|
||||||
|
|
||||||
@ -71,8 +70,11 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
|
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
|
||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
t.Model().WorkingTreeFileCount(1)
|
t.Views().Files().
|
||||||
t.Views().Files().SelectedLine(Contains("my file"))
|
Lines(
|
||||||
|
Contains("my file").IsSelected(),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Main().Content(Contains(`"BAR"`))
|
t.Views().Main().Content(Contains(`"BAR"`))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -43,7 +43,9 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().WorkingTreeFileCount(0)
|
t.Views().Files().
|
||||||
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Branches().
|
t.Views().Branches().
|
||||||
Focus().
|
Focus().
|
||||||
Press("a")
|
Press("a")
|
||||||
@ -52,9 +54,12 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.ExpectPrompt().Title(Equals("Description")).Type(" my branch").Confirm()
|
t.ExpectPrompt().Title(Equals("Description")).Type(" my branch").Confirm()
|
||||||
|
|
||||||
t.Model().WorkingTreeFileCount(1)
|
t.Views().Files().
|
||||||
|
Focus().
|
||||||
|
Lines(
|
||||||
|
Contains("output.txt").IsSelected(),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Files().Focus().SelectedLine(Contains("output.txt"))
|
|
||||||
t.Views().Main().Content(Contains("bar Branch: #feature/foo my branch feature/foo"))
|
t.Views().Main().Content(Contains("bar Branch: #feature/foo my branch feature/foo"))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -42,8 +42,7 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CurrentBranchName("feature/bar")
|
t.Git().CurrentBranchName("feature/bar")
|
||||||
t.Model().WorkingTreeFileCount(0)
|
|
||||||
|
|
||||||
t.Views().Branches().
|
t.Views().Branches().
|
||||||
Focus().
|
Focus().
|
||||||
@ -56,6 +55,6 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.ExpectMenu().Title(Equals("Branch:")).Select(Equals("master")).Confirm()
|
t.ExpectMenu().Title(Equals("Branch:")).Select(Equals("master")).Confirm()
|
||||||
|
|
||||||
t.Model().CurrentBranchName("master")
|
t.Git().CurrentBranchName("master")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -54,9 +54,8 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().WorkingTreeFileCount(0)
|
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
IsEmpty().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
Press("a")
|
Press("a")
|
||||||
|
|
||||||
@ -69,8 +68,12 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
|
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
|
||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
t.Model().WorkingTreeFileCount(1)
|
t.Views().Files().
|
||||||
t.Views().Files().SelectedLine(Contains("myfile"))
|
Focus().
|
||||||
|
Lines(
|
||||||
|
Contains("myfile").IsSelected(),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Main().Content(Contains("BAR"))
|
t.Views().Main().Content(Contains("BAR"))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -22,7 +22,10 @@ var DirWithUntrackedFile = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.UpdateFile("dir/file", "baz")
|
shell.UpdateFile("dir/file", "baz")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(1)
|
t.Views().Commits().
|
||||||
|
Lines(
|
||||||
|
Contains("first commit"),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Main().
|
t.Views().Main().
|
||||||
Content(DoesNotContain("error: Could not access")).
|
Content(DoesNotContain("error: Could not access")).
|
||||||
|
@ -72,8 +72,6 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
},
|
},
|
||||||
|
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(3)
|
|
||||||
|
|
||||||
type statusFile struct {
|
type statusFile struct {
|
||||||
status string
|
status string
|
||||||
label string
|
label string
|
||||||
@ -121,6 +119,6 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
{status: "??", label: "new.txt", menuTitle: "new.txt"},
|
{status: "??", label: "new.txt", menuTitle: "new.txt"},
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Model().WorkingTreeFileCount(0)
|
t.Views().Files().IsEmpty()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -28,10 +28,14 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
CreateFileAndAdd(postMergeFilename, postMergeFileContent)
|
CreateFileAndAdd(postMergeFilename, postMergeFileContent)
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(3)
|
|
||||||
|
|
||||||
mergeCommitMessage := "Merge branch 'feature-branch' into development-branch"
|
mergeCommitMessage := "Merge branch 'feature-branch' into development-branch"
|
||||||
t.Model().HeadCommitMessage(Contains(mergeCommitMessage))
|
|
||||||
|
t.Views().Commits().
|
||||||
|
Lines(
|
||||||
|
Contains(mergeCommitMessage),
|
||||||
|
Contains("new feature commit"),
|
||||||
|
Contains("initial commit"),
|
||||||
|
)
|
||||||
|
|
||||||
t.Views().Commits().
|
t.Views().Commits().
|
||||||
Focus().
|
Focus().
|
||||||
@ -43,8 +47,12 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
// assuring we haven't added a brand new commit
|
// assuring we haven't added a brand new commit
|
||||||
t.Model().CommitCount(3)
|
t.Views().Commits().
|
||||||
t.Model().HeadCommitMessage(Contains(mergeCommitMessage))
|
Lines(
|
||||||
|
Contains(mergeCommitMessage),
|
||||||
|
Contains("new feature commit"),
|
||||||
|
Contains("initial commit"),
|
||||||
|
)
|
||||||
|
|
||||||
// assuring the post-merge file shows up in the merge commit.
|
// assuring the post-merge file shows up in the merge commit.
|
||||||
t.Views().Main().
|
t.Views().Main().
|
||||||
|
@ -14,8 +14,6 @@ var ConfirmOnQuit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
},
|
},
|
||||||
SetupRepo: func(shell *Shell) {},
|
SetupRepo: func(shell *Shell) {},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().CommitCount(0)
|
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
Press(keys.Universal.Quit)
|
Press(keys.Universal.Quit)
|
||||||
|
@ -16,17 +16,25 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.GitAddAll()
|
shell.GitAddAll()
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().StashCount(0)
|
t.Views().Stash().
|
||||||
t.Model().WorkingTreeFileCount(1)
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
Lines(
|
||||||
|
Contains("file"),
|
||||||
|
).
|
||||||
Press(keys.Files.ViewStashOptions)
|
Press(keys.Files.ViewStashOptions)
|
||||||
|
|
||||||
t.ExpectMenu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm()
|
t.ExpectMenu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm()
|
||||||
|
|
||||||
t.ExpectPrompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
|
t.ExpectPrompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
|
||||||
|
|
||||||
t.Model().StashCount(1)
|
t.Views().Stash().
|
||||||
t.Model().WorkingTreeFileCount(0)
|
Lines(
|
||||||
|
Contains("my stashed file"),
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
IsEmpty()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -17,17 +17,26 @@ var StashIncludingUntrackedFiles = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.GitAdd("file_1")
|
shell.GitAdd("file_1")
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
t.Model().StashCount(0)
|
t.Views().Stash().
|
||||||
t.Model().WorkingTreeFileCount(2)
|
IsEmpty()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
Lines(
|
||||||
|
Contains("file_1"),
|
||||||
|
Contains("file_2"),
|
||||||
|
).
|
||||||
Press(keys.Files.ViewStashOptions)
|
Press(keys.Files.ViewStashOptions)
|
||||||
|
|
||||||
t.ExpectMenu().Title(Equals("Stash options")).Select(Contains("stash all changes including untracked files")).Confirm()
|
t.ExpectMenu().Title(Equals("Stash options")).Select(Contains("stash all changes including untracked files")).Confirm()
|
||||||
|
|
||||||
t.ExpectPrompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
|
t.ExpectPrompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm()
|
||||||
|
|
||||||
t.Model().StashCount(1)
|
t.Views().Stash().
|
||||||
t.Model().WorkingTreeFileCount(0)
|
Lines(
|
||||||
|
Contains("my stashed file"),
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
IsEmpty()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -20,7 +20,6 @@ type GuiDriver interface {
|
|||||||
PressKey(string)
|
PressKey(string)
|
||||||
Keys() config.KeybindingConfig
|
Keys() config.KeybindingConfig
|
||||||
CurrentContext() types.Context
|
CurrentContext() types.Context
|
||||||
Model() *types.Model
|
|
||||||
Fail(message string)
|
Fail(message string)
|
||||||
// These two log methods are for the sake of debugging while testing. There's no need to actually
|
// These two log methods are for the sake of debugging while testing. There's no need to actually
|
||||||
// commit any logging.
|
// commit any logging.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user