summaryrefslogtreecommitdiffstats
path: root/pkg/integration/components
diff options
context:
space:
mode:
authorSimon Whitaker <sw@netcetera.org>2023-08-06 14:55:14 +0100
committerSimon Whitaker <sw@netcetera.org>2023-08-07 15:10:28 +0100
commited1547e0cb60d9234fe901f8b3330fbae2e1fd87 (patch)
treee6e9a7459d817609cd10222b64e70fa61f837c32 /pkg/integration/components
parent579791e7bc8261e9ed578f882f4b8b11a486bf78 (diff)
Add a Click() primitive to the integration test library
Diffstat (limited to 'pkg/integration/components')
-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
5 files changed, 48 insertions, 22 deletions
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)