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 24, 2020
1 parent 23a80a9 commit c1af738
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
41 changes: 39 additions & 2 deletions test/ui/UiTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import ui.pages.gutter
import ui.pages.idea
import ui.pages.welcomeFrame
import ui.utils.StepsLogger
import ui.utils.doubleClickOnRight
import ui.utils.tripleClickOnRight
import ui.utils.uiTest
import ui.utils.vimExit
import java.awt.event.KeyEvent
Expand Down Expand Up @@ -75,9 +77,9 @@ class UiTests {
}
actionMenu("New").click()
actionMenuItem("File").click()
keyboard { enterText("MyDocument.txt"); enter() }
keyboard { enterText("MyDoc.txt"); enter() }
}
val editor = editor("MyDocument.txt") {
val editor = editor("MyDoc.txt") {
step("Write a text") {
keyboard {
enterText("i")
Expand All @@ -93,12 +95,47 @@ class UiTests {
}
}

testTripleClickRightFromLineEnd(editor)
testClickRightFromLineEnd(editor)
testClickOnWord(editor)
testGutterClick(editor)

}
}

private fun ContainerFixture.testTripleClickRightFromLineEnd(editor: Editor) {
editor.findText("Two").tripleClickOnRight(40, editor)

assertEquals("One Two\n", editor.selectedText)
assertEquals(7, editor.caretOffset)

keyboard { enterText("h") }

assertEquals("One Two\n", editor.selectedText)
assertEquals(6, editor.caretOffset)

keyboard { enterText("j") }

assertEquals("One Two\nThree Four\n", editor.selectedText)
assertEquals(14, editor.caretOffset)

vimExit()
}

private fun ContainerFixture.testClickRightFromLineEnd(editor: Editor) {
editor.findText("Two").doubleClickOnRight(40, editor)

assertEquals("Two", editor.selectedText)
assertEquals(6, editor.caretOffset)

keyboard { enterText("h") }

assertEquals("Tw", editor.selectedText)
assertEquals(5, editor.caretOffset)

vimExit()
}

private fun ContainerFixture.testClickOnWord(editor: Editor) {
editor.findText("One").doubleClick(MouseButton.LEFT_BUTTON)

Expand Down
38 changes: 38 additions & 0 deletions test/ui/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.fixtures.dataExtractor.RemoteText
import org.assertj.swing.core.MouseButton
import java.awt.Point

fun RemoteText.doubleClickOnRight(shiftX: Int, fixture: Fixture, button: MouseButton = MouseButton.LEFT_BUTTON) {
val updatedPoint = Point(this.point.x + shiftX, this.point.y)
fixture.remoteRobot.execute(fixture) {
robot.click(component, updatedPoint, button, 2)
}
}

fun RemoteText.tripleClickOnRight(shiftX: Int, fixture: Fixture, button: MouseButton = MouseButton.LEFT_BUTTON) {
val updatedPoint = Point(this.point.x + shiftX, this.point.y)
fixture.remoteRobot.execute(fixture) {
robot.click(component, updatedPoint, button, 3)
}
}

0 comments on commit c1af738

Please sign in to comment.