Skip to content

Commit

Permalink
Add another ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Nov 20, 2020
1 parent c8be6c2 commit d9d92f7
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 8 deletions.
17 changes: 17 additions & 0 deletions test/org/jetbrains/plugins/ideavim/TestHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
}
49 changes: 41 additions & 8 deletions test/ui/UiTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)

}
}
}

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()
}
}
36 changes: 36 additions & 0 deletions test/ui/utils/VimActions.kt
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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) }
}

0 comments on commit d9d92f7

Please sign in to comment.