summaryrefslogtreecommitdiffstats
path: root/pkg/integration
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/integration')
-rw-r--r--pkg/integration/README.md2
-rw-r--r--pkg/integration/clients/cli.go6
-rw-r--r--pkg/integration/clients/tui.go12
-rw-r--r--pkg/integration/components/runner.go14
-rw-r--r--pkg/integration/components/test.go12
-rw-r--r--pkg/integration/components/test_driver.go20
-rw-r--r--pkg/integration/components/test_test.go16
-rw-r--r--pkg/integration/components/view_driver.go8
-rw-r--r--pkg/integration/types/types.go1
9 files changed, 59 insertions, 32 deletions
diff --git a/pkg/integration/README.md b/pkg/integration/README.md
index 8b6ec15df..e0d32665a 100644
--- a/pkg/integration/README.md
+++ b/pkg/integration/README.md
@@ -48,7 +48,7 @@ The third, the go-test command, intended only for use in CI, to be run along wit
The name of a test is based on its path, so the name of the test at `pkg/integration/tests/commit/new_branch.go` is commit/new_branch. So to run it with our test runner you would run `go run cmd/integration_test/main.go cli commit/new_branch`.
-You can pass the KEY_PRESS_DELAY env var to the test runner in order to set a delay in milliseconds between keypresses, which helps for watching a test at a realistic speed to understand what it's doing. Or you can pass the '--slow' flag which sets a pre-set 'slow' key delay. In the tui you can press 't' to run the test in slow mode.
+You can pass the INPUT_DELAY env var to the test runner in order to set a delay in milliseconds between keypresses or mouse clicks, which helps for watching a test at a realistic speed to understand what it's doing. Or you can pass the '--slow' flag which sets a pre-set 'slow' key delay. In the tui you can press 't' to run the test in slow mode.
The resultant repo will be stored in `test/results`, so if you're not sure what went wrong you can go there and inspect the repo.
diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go
index 79853b224..08cff3f00 100644
--- a/pkg/integration/clients/cli.go
+++ b/pkg/integration/clients/cli.go
@@ -24,9 +24,9 @@ import (
// If invoked directly, you can specify tests to run by passing their names as positional arguments
func RunCLI(testNames []string, slow bool, sandbox bool) {
- keyPressDelay := tryConvert(os.Getenv("KEY_PRESS_DELAY"), 0)
+ inputDelay := tryConvert(os.Getenv("INPUT_DELAY"), 0)
if slow {
- keyPressDelay = SLOW_KEY_PRESS_DELAY
+ inputDelay = SLOW_INPUT_DELAY
}
err := components.RunTests(
@@ -35,7 +35,7 @@ func RunCLI(testNames []string, slow bool, sandbox bool) {
runCmdInTerminal,
runAndPrintFatalError,
sandbox,
- keyPressDelay,
+ inputDelay,
1,
)
if err != nil {
diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go
index 904712037..9b873caab 100644
--- a/pkg/integration/clients/tui.go
+++ b/pkg/integration/clients/tui.go
@@ -19,7 +19,7 @@ import (
// This program lets you run integration tests from a TUI. See pkg/integration/README.md for more info.
-var SLOW_KEY_PRESS_DELAY = 600
+var SLOW_INPUT_DELAY = 600
func RunTUI() {
rootDir := utils.GetLazyRootDirectory()
@@ -111,7 +111,7 @@ func RunTUI() {
return nil
}
- suspendAndRunTest(currentTest, false, SLOW_KEY_PRESS_DELAY)
+ suspendAndRunTest(currentTest, false, SLOW_INPUT_DELAY)
return nil
}); err != nil {
@@ -271,12 +271,12 @@ func (self *app) wrapEditor(f func(v *gocui.View, key gocui.Key, ch rune, mod go
}
}
-func suspendAndRunTest(test *components.IntegrationTest, sandbox bool, keyPressDelay int) {
+func suspendAndRunTest(test *components.IntegrationTest, sandbox bool, inputDelay int) {
if err := gocui.Screen.Suspend(); err != nil {
panic(err)
}
- runTuiTest(test, sandbox, keyPressDelay)
+ runTuiTest(test, sandbox, inputDelay)
fmt.Fprintf(os.Stdout, "\n%s", style.FgGreen.Sprint("press enter to return"))
fmt.Scanln() // wait for enter press
@@ -371,14 +371,14 @@ func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
-func runTuiTest(test *components.IntegrationTest, sandbox bool, keyPressDelay int) {
+func runTuiTest(test *components.IntegrationTest, sandbox bool, inputDelay int) {
err := components.RunTests(
[]*components.IntegrationTest{test},
log.Printf,
runCmdInTerminal,
runAndPrintError,
sandbox,
- keyPressDelay,
+ inputDelay,
1,
)
if err != nil {
diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go
index 908d7e1d8..9d380044a 100644
--- a/pkg/integration/components/runner.go
+++ b/pkg/integration/components/runner.go
@@ -29,7 +29,7 @@ func RunTests(
runCmd func(cmd *exec.Cmd) error,
testWrapper func(test *IntegrationTest, f func() error),
sandbox bool,
- keyPressDelay int,
+ inputDelay int,
maxAttempts int,
) error {
projectRootDir := lazycoreUtils.GetLazyRootDirectory()
@@ -58,7 +58,7 @@ func RunTests(
)
for i := 0; i < maxAttempts; i++ {
- err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, keyPressDelay, gitVersion)
+ err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, inputDelay, gitVersion)
if err != nil {
if i == maxAttempts-1 {
return err
@@ -83,7 +83,7 @@ func runTest(
logf func(format string, formatArgs ...interface{}),
runCmd func(cmd *exec.Cmd) error,
sandbox bool,
- keyPressDelay int,
+ inputDelay int,
gitVersion *git_commands.GitVersion,
) error {
if test.Skip() {
@@ -100,7 +100,7 @@ func runTest(
return err
}
- cmd, err := getLazygitCommand(test, paths, projectRootDir, sandbox, keyPressDelay)
+ cmd, err := getLazygitCommand(test, paths, projectRootDir, sandbox, inputDelay)
if err != nil {
return err
}
@@ -165,7 +165,7 @@ func getGitVersion() (*git_commands.GitVersion, error) {
return git_commands.ParseGitVersion(versionStr)
}
-func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandbox bool, keyPressDelay int) (*exec.Cmd, error) {
+func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandbox bool, inputDelay int) (*exec.Cmd, error) {
osCommand := oscommands.NewDummyOSCommand()
err := os.RemoveAll(paths.Config())
@@ -203,8 +203,8 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb
}
}
- if keyPressDelay > 0 {
- cmdObj.AddEnvVars(fmt.Sprintf("KEY_PRESS_DELAY=%d", keyPressDelay))
+ if inputDelay > 0 {
+ cmdObj.AddEnvVars(fmt.Sprintf("INPUT_DELAY=%d", inputDelay))
}
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", GIT_CONFIG_GLOBAL_ENV_VAR, globalGitConfigPath(rootDir)))
diff --git a/pkg/integration/components/test.go b/pkg/integration/components/test.go
index af307beeb..e0970f6a2 100644
--- a/pkg/integration/components/test.go
+++ b/pkg/integration/components/test.go
@@ -190,9 +190,9 @@ func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) {
shell := NewShell(pwd, func(errorMsg string) { gui.Fail(errorMsg) })
keys := gui.Keys()
- testDriver := NewTestDriver(gui, shell, keys, KeyPressDelay())
+ testDriver := NewTestDriver(gui, shell, keys, InputDelay())
- if KeyPressDelay() > 0 {
+ if InputDelay() > 0 {
// Setting caption to clear the options menu from whatever it starts with
testDriver.SetCaption("")
testDriver.SetCaptionPrefix("")
@@ -200,7 +200,7 @@ func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) {
self.run(testDriver, keys)
- if KeyPressDelay() > 0 {
+ if InputDelay() > 0 {
// Clear whatever caption there was so it doesn't linger
testDriver.SetCaption("")
testDriver.SetCaptionPrefix("")
@@ -232,10 +232,10 @@ func TestNameFromFilePath(path string) string {
return name[:len(name)-len(".go")]
}
-// this is the delay in milliseconds between keypresses
+// this is the delay in milliseconds between keypresses or mouse clicks
// defaults to zero
-func KeyPressDelay() int {
- delayStr := os.Getenv("KEY_PRESS_DELAY")
+func InputDelay() int {
+ delayStr := os.Getenv("INPUT_DELAY")
if delayStr == "" {
return 0
}
diff --git a/pkg/integration/components/test_driver.go b/pkg/integration/components/test_driver.go
index 80e4cb948..a862dce06 100644
--- a/pkg/integration/components/test_driver.go
+++ b/pkg/integration/components/test_driver.go
@@ -10,18 +10,18 @@ import (
)
type TestDriver struct {
- gui integrationTypes.GuiDriver
- keys config.KeybindingConfig
- pushKeyDelay int
+ gui integrationTypes.GuiDriver
+ keys config.KeybindingConfig
+ inputDelay int
*assertionHelper
shell *Shell
}
-func NewTestDriver(gui integrationTypes.GuiDriver, shell *Shell, keys config.KeybindingConfig, pushKeyDelay int) *TestDriver {
+func NewTestDriver(gui integrationTypes.GuiDriver, shell *Shell, keys config.KeybindingConfig, inputDelay int) *TestDriver {
return &TestDriver{
gui: gui,
keys: keys,
- pushKeyDelay: pushKeyDelay,
+ inputDelay: inputDelay,
assertionHelper: &assertionHelper{gui: gui},
shell: shell,
}
@@ -32,7 +32,7 @@ func NewTestDriver(gui integrationTypes.GuiDriver, shell *Shell, keys config.Key
func (self *TestDriver) press(keyStr string) {
self.SetCaption(fmt.Sprintf("Pressing %s", keyStr))
self.gui.PressKey(keyStr)
- self.Wait(self.pushKeyDelay)
+ self.Wait(self.inputDelay)
}
// for use when typing or navigating, because in demos we want that to happen
@@ -40,7 +40,13 @@ func (self *TestDriver) press(keyStr string) {
func (self *TestDriver) pressFast(keyStr string) {
self.SetCaption("")
self.gui.PressKey(keyStr)
- self.Wait(self.pushKeyDelay / 5)
+ self.Wait(self.inputDelay / 5)
+}
+
+func (self *TestDriver) click(x, y int) {
+ self.SetCaption(fmt.Sprintf("Clicking %d, %d", x, y))
+ self.gui.Click(x, y)
+ self.Wait(self.inputDelay)
}
// Should only be used in specific cases where you're doing something weird!
diff --git a/pkg/integration/components/test_test.go b/pkg/integration/components/test_test.go
index b5c1c6055..99e52f5e9 100644
--- a/pkg/integration/components/test_test.go
+++ b/pkg/integration/components/test_test.go
@@ -14,9 +14,14 @@ import (
// this file is for testing our test code (meta, I know)
+type coordinate struct {
+ x, y int
+}
+
type fakeGuiDriver struct {
- failureMessage string
- pressedKeys []string
+ failureMessage string
+ pressedKeys []string
+ clickedCoordinates []coordinate
}
var _ integrationTypes.GuiDriver = &fakeGuiDriver{}
@@ -25,6 +30,10 @@ func (self *fakeGuiDriver) PressKey(key string) {
self.pressedKeys = append(self.pressedKeys, key)
}
+func (self *fakeGuiDriver) Click(x, y int) {
+ self.clickedCoordinates = append(self.clickedCoordinates, coordinate{x: x, y: y})
+}
+
func (self *fakeGuiDriver) Keys() config.KeybindingConfig {
return config.KeybindingConfig{}
}
@@ -87,11 +96,14 @@ func TestSuccess(t *testing.T) {
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.press("a")
t.press("b")
+ t.click(0, 1)
+ t.click(2, 3)
},
})
driver := &fakeGuiDriver{}
test.Run(driver)
assert.EqualValues(t, []string{"a", "b"}, driver.pressedKeys)
+ assert.EqualValues(t, []coordinate{{0, 1}, {2, 3}}, driver.clickedCoordinates)
assert.Equal(t, "", driver.failureMessage)
}
diff --git a/pkg/integration/components/view_driver.go b/pkg/integration/components/view_driver.go
index 4e6cbd1d1..6778dd8dd 100644
--- a/pkg/integration/components/view_driver.go
+++ b/pkg/integration/components/view_driver.go
@@ -403,6 +403,14 @@ func (self *ViewDriver) PressFast(keyStr string) *ViewDriver {
return self
}
+func (self *ViewDriver) Click(x, y int) *ViewDriver {
+ offsetX, offsetY, _, _ := self.getView().Dimensions()
+
+ self.t.click(offsetX+1+x, offsetY+1+y)
+
+ return self
+}
+
// i.e. pressing down arrow
func (self *ViewDriver) SelectNextItem() *ViewDriver {
return self.PressFast(self.t.keys.Universal.NextItem)
diff --git a/pkg/integration/types/types.go b/pkg/integration/types/types.go
index 689fef4d0..15a2d514f 100644
--- a/pkg/integration/types/types.go
+++ b/pkg/integration/types/types.go
@@ -23,6 +23,7 @@ type IntegrationTest interface {
// this is the interface through which our integration tests interact with the lazygit gui
type GuiDriver interface {
PressKey(string)
+ Click(int, int)
Keys() config.KeybindingConfig
CurrentContext() types.Context
ContextForView(viewName string) types.Context