Add a Click() primitive to the integration test library
This commit is contained in:
@@ -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)))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user