diff --git a/test/org/jetbrains/plugins/ideavim/TestHelper.kt b/test/org/jetbrains/plugins/ideavim/TestHelper.kt index e57bf0046d..578e95920a 100644 --- a/test/org/jetbrains/plugins/ideavim/TestHelper.kt +++ b/test/org/jetbrains/plugins/ideavim/TestHelper.kt @@ -27,6 +27,7 @@ import com.maddyhome.idea.vim.command.CommandState import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.helper.mode import com.maddyhome.idea.vim.option.OptionsManager +import java.time.Duration import kotlin.test.fail /** @@ -93,3 +94,19 @@ fun assertHappened(timeInMillis: Int = 1000, precision: Int, condition: () -> Bo waitAndAssert(precision * 2) { condition() } } + +fun waitCondition( + durationMillis: Long, + interval: Long = 500, + condition: () -> Boolean +): Boolean { + val endTime = System.currentTimeMillis() + durationMillis + while (System.currentTimeMillis() < endTime) { + if (condition()) + return true + else { + Thread.sleep(interval) + } + } + return false +} diff --git a/test/ui/UiTests.kt b/test/ui/UiTests.kt index c392c31e7f..89c62378ad 100644 --- a/test/ui/UiTests.kt +++ b/test/ui/UiTests.kt @@ -19,6 +19,7 @@ package ui import com.intellij.remoterobot.fixtures.ComponentFixture +import com.intellij.remoterobot.fixtures.ContainerFixture import com.intellij.remoterobot.search.locators.byXpath import com.intellij.remoterobot.stepsProcessing.step import com.intellij.remoterobot.utils.keyboard @@ -27,6 +28,7 @@ import org.assertj.swing.core.MouseButton import org.intellij.examples.simple.plugin.steps.JavaExampleSteps import org.junit.Ignore import org.junit.Test +import ui.pages.Editor import ui.pages.actionMenu import ui.pages.actionMenuItem import ui.pages.dialog @@ -36,6 +38,7 @@ import ui.pages.idea import ui.pages.welcomeFrame import ui.utils.StepsLogger import ui.utils.uiTest +import ui.utils.vimExit import java.awt.event.KeyEvent import kotlin.test.assertEquals @@ -80,21 +83,51 @@ class UiTests { enterText("i") enterText( """ - |One - |Two - |Three + |One Two + |Three Four + |Five """.trimMargin() ) escape() } } } - gutter() { - findText("2").click() - } - assertEquals("Two\n", editor.selectedText) + testClickOnWord(editor) + testGutterClick(editor) } } -} \ No newline at end of file + + private fun ContainerFixture.testClickOnWord(editor: Editor) { + editor.findText("One").doubleClick(MouseButton.LEFT_BUTTON) + + assertEquals("One", editor.selectedText) + assertEquals(2, editor.caretOffset) + + keyboard { enterText("h") } + + assertEquals("On", editor.selectedText) + assertEquals(1, editor.caretOffset) + + vimExit() + } + + private fun ContainerFixture.testGutterClick(editor: Editor) { + gutter { + findText("2").click() + } + + assertEquals("Three Four\n", editor.selectedText) + assertEquals(8, editor.caretOffset) + + keyboard { + enterText("k") + } + + assertEquals("One Two\nThree Four\n", editor.selectedText) + assertEquals(0, editor.caretOffset) + + vimExit() + } +} diff --git a/test/ui/utils/VimActions.kt b/test/ui/utils/VimActions.kt new file mode 100644 index 0000000000..5d5c481acc --- /dev/null +++ b/test/ui/utils/VimActions.kt @@ -0,0 +1,36 @@ +/* + * IdeaVim - Vim emulator for IDEs based on the IntelliJ platform + * Copyright (C) 2003-2020 The IdeaVim authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ui.utils + +import com.intellij.remoterobot.fixtures.Fixture +import com.intellij.remoterobot.utils.keyboard + + + +fun Fixture.insertMode() { + type("i") +} + +fun Fixture.vimExit() { + keyboard { escape() } +} + +fun Fixture.type(keys: String) { + keyboard { enterText(keys) } +}