diff --git a/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/ParsingTest.kt b/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/EditingTest.kt similarity index 54% rename from plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/ParsingTest.kt rename to plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/EditingTest.kt index 0341ccc2..626f831a 100644 --- a/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/ParsingTest.kt +++ b/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/EditingTest.kt @@ -4,21 +4,28 @@ import com.github.tarcv.testingteam.surveyoridea.gui.fixtures.idea import com.github.tarcv.testingteam.surveyoridea.gui.fixtures.locateElementToolWindow import com.github.tarcv.testingteam.surveyoridea.hasJavaSupport import com.intellij.remoterobot.client.IdeaSideException +import com.intellij.remoterobot.fixtures.EditorFixture import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitFor import org.apache.commons.text.StringEscapeUtils -import org.junit.jupiter.api.Assumptions import org.junit.jupiter.api.Test import java.awt.Point import java.lang.Thread.sleep import java.time.Duration import kotlin.test.assertEquals -class ParsingTest : BaseTestProjectTests() { +class EditingTest : BaseTestProjectTests() { @Test - fun testDroidSelectorParsing() = with(remoteRobot) { - Assumptions.assumeTrue(hasJavaSupport, "This feature requires an IDE with Java support") + fun testDroidSelectorEditing() { + assertDroidSelectorEditing("""new UiSelector().""", 1) + } + + @Test + fun testDroidSelectorMultilineEditing() { + assertDroidSelectorEditing("""new UiSelector()${'\n'}.index(1).""", 2) + } + private fun assertDroidSelectorEditing(selector: String, expectedLineCount: Int) = with(remoteRobot) { idea { openFileInTestProject(droidAutomatorSnapshotFile, "editorWithSnapshot") @@ -31,8 +38,9 @@ class ParsingTest : BaseTestProjectTests() { locateElementToolWindow { // Escaping is required due to simple concatenation in the text#set implementation editor.apply { - val editorLanguage = callJs( - runInEdt = true, script = """ + if (hasJavaSupport) { + val editorLanguage = callJs( + runInEdt = true, script = """ importPackage(com.intellij.openapi.fileEditor.impl.text) importPackage(com.intellij.openapi.project.ex) importPackage(com.intellij.psi) @@ -42,8 +50,9 @@ class ParsingTest : BaseTestProjectTests() { .getLanguage() .toString() """.trimIndent() - ) - assertEquals("Language: JAVA", editorLanguage) + ) + assertEquals("Language: JAVA", editorLanguage) + } sleep(5_000) click(Point(5, 5)) @@ -54,16 +63,17 @@ class ParsingTest : BaseTestProjectTests() { // Escaping is required due to how enterText is implemented enterText( - StringEscapeUtils.escapeEcmaScript("""new UiSelector().""") + StringEscapeUtils.escapeEcmaScript(selector) .replace("\\\"", "\"") ) } } - val popupItems = waitFor(Duration.ofSeconds(10), functionWithCondition = { - val items: List = try { - editor.callJs( - runInEdt = true, script = """ + if (hasJavaSupport) { + val popupItems = waitFor(Duration.ofSeconds(10), functionWithCondition = { + val items: List = try { + editor.callJs( + runInEdt = true, script = """ importPackage(com.intellij.codeInsight.lookup) const model = LookupManager.getActiveLookup(local.get('editor')).getList().getModel() const listItems = new ArrayList(); @@ -72,24 +82,34 @@ class ParsingTest : BaseTestProjectTests() { } listItems """.trimIndent() - ) - } catch (e: IdeaSideException) { - emptyList() + ) + } catch (e: IdeaSideException) { + emptyList() + } + (items.isNotEmpty() && items.contains("resourceId")) to items + }) + assert(popupItems.contains("index")) { "contains 'index'" } + assert(popupItems.contains("resourceId")) { "contains 'resourceId'" } + assert(popupItems.contains("text")) { "contains 'text'" } + this@idea.jList { + // Check the lookup popup is actually displayed by comparing it with actually found jList + assertEquals(collectItems().size, popupItems.size) } - (items.isNotEmpty() && items.contains("resourceId")) to items - }) - assert(popupItems.contains("index")) { "contains 'index'" } - assert(popupItems.contains("resourceId")) { "contains 'resourceId'" } - assert(popupItems.contains("text")) { "contains 'text'" } - this@idea.jList { - // Check the lookup popup is actually displayed by comparing it with actually found jList - assertEquals(collectItems().size, popupItems.size) + // At this point it can be assumed locator in the editor is correctly highlighted + // (as it has correct language (Java) and has working auto-completion) } - // At this point it can be assumed locator in the editor is correctly highlighted - // (as it has correct language (Java) and has working auto-completion) + assertEquals(expectedLineCount, editor.getLineCount()) } } } -} \ No newline at end of file +} + +private fun EditorFixture.getLineCount(): Int { + return callJs( + runInEdt = true, script = """ + const document = local.get('document') + document.getLineCount() + """.trimIndent()) +} diff --git a/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateActionUiTests.kt b/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateActionUiTests.kt index cc6c0722..80b2eb11 100644 --- a/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateActionUiTests.kt +++ b/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateActionUiTests.kt @@ -12,9 +12,12 @@ import java.awt.Point import java.awt.event.KeyEvent import java.lang.Thread.sleep +private const val singleLineLocator = """new UiSelector().resourceIdMatches(".+/celsiusText")""" +private const val multiLineLocator = """new UiSelector()${'\n'}.resourceIdMatches(${'\n'}".+/celsiusText")""" + class LocateActionUiTests : BaseTestProjectTests() { @Test - fun testLocatingFromKeyboard() = verifyLocatingFrom { + fun testLocatingFromKeyboard() = verifyLocatingFrom(singleLineLocator) { locateElementToolWindow { editor.apply { keyboard { @@ -31,7 +34,7 @@ class LocateActionUiTests : BaseTestProjectTests() { } @Test - fun testLocatingFromMenu() = verifyLocatingFrom { + fun testLocatingFromMenu() = verifyLocatingFrom(singleLineLocator) { locateElementToolWindow { selectInMenuBar( "Edit", @@ -42,13 +45,20 @@ class LocateActionUiTests : BaseTestProjectTests() { } @Test - fun testLocatingFromToolButton() = verifyLocatingFrom { - locateElementToolWindow { - locateButton.click() + fun testLocatingFromToolButton() = assertLocatingFromToolButton(singleLineLocator) + + @Test + fun testLocatingMultilineFromToolButton() = assertLocatingFromToolButton(multiLineLocator) + + private fun assertLocatingFromToolButton(locator: String) { + verifyLocatingFrom(locator) { + locateElementToolWindow { + locateButton.click() + } } } - private fun verifyLocatingFrom(triggerActionWithBlock: IdeaFrame.() -> Unit) = with(remoteRobot) { + private fun verifyLocatingFrom(locator: String, triggerActionWithBlock: IdeaFrame.() -> Unit) = with(remoteRobot) { idea { openFileInTestProject(droidAutomatorSnapshotFile, "editorWithSnapshot") @@ -73,9 +83,13 @@ class LocateActionUiTests : BaseTestProjectTests() { // Escaping is required due to how enterText is implemented enterText( - StringEscapeUtils.escapeEcmaScript("""new UiSelector().resourceIdMatches(".+/celsiusText")""") + StringEscapeUtils.escapeEcmaScript(locator) .replace("\\\"", "\"") ) + + repeat(5) { // make sure there is no extra automagically added braces + key(KeyEvent.VK_DELETE) + } } } } diff --git a/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/fixtures/IdeaFrame.kt b/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/fixtures/IdeaFrame.kt index 0587369c..abcf4334 100644 --- a/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/fixtures/IdeaFrame.kt +++ b/plugin-test/src/test/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/fixtures/IdeaFrame.kt @@ -39,7 +39,7 @@ class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : } fun selectInMenuBar(vararg items: String) { - attempt { + attempt(5) { menuBar.select(*items) } } diff --git a/plugin/src/main/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateToolWindow.kt b/plugin/src/main/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateToolWindow.kt index db89247a..3765c028 100644 --- a/plugin/src/main/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateToolWindow.kt +++ b/plugin/src/main/kotlin/com/github/tarcv/testingteam/surveyoridea/gui/LocateToolWindow.kt @@ -77,6 +77,7 @@ abstract class LocateToolWindow(protected val project: Project) { editorField ) + editorField.setOneLineMode(false) initSelectorField(editorField) project.getService(LocateToolHoldingService::class.java).registerToolWindow(this)