test: inline edit tests

This commit is contained in:
Patrick Erichsen 2025-01-21 15:23:16 -08:00
parent 5bf9845613
commit e6c44b1f09
2 changed files with 93 additions and 2 deletions

View file

@ -167,13 +167,13 @@ fun openInlineEdit(project: Project?, editor: Editor) {
val prefix = editor.document.getText(TextRange(0, startOffset))
val highlighted = editor.document.getText(TextRange(startOffset, endOffset))
val suffix = editor.document.getText(TextRange(endOffset, editor.document.textLength))
val lineNumber = max(0, startLineNumber - 1)
val lineNumber = if (startLineNumber == 0) 0 else max(0, startLineNumber - 1)
// Un-highlight the selected text
selectionModel.removeSelection()
// Get indentation width in pixels
val indentationLineNum = lineNumber + 1
val indentationLineNum = if (startLineNumber == 0) 0 else lineNumber + 1
val lineStart = editor.document.getLineStartOffset(indentationLineNum)
val lineEnd = editor.document.getLineEndOffset(indentationLineNum)
val text = editor.document.getText(TextRange(lineStart, lineEnd))

View file

@ -0,0 +1,91 @@
package com.github.continuedev.continueintellijextension.e2e
import com.automation.remarks.junit5.Video
import com.github.continuedev.continueintellijextension.fixtures.dialog
import com.github.continuedev.continueintellijextension.fixtures.idea
import com.github.continuedev.continueintellijextension.fixtures.welcomeFrame
import com.github.continuedev.continueintellijextension.utils.RemoteRobotExtension
import com.github.continuedev.continueintellijextension.utils.StepsLogger
import com.github.continuedev.continueintellijextension.utils.getMetaKey
import com.intellij.remoterobot.RemoteRobot
import com.intellij.remoterobot.fixtures.ComponentFixture
import com.intellij.remoterobot.search.locators.byXpath
import com.intellij.remoterobot.steps.CommonSteps
import com.intellij.remoterobot.utils.keyboard
import com.intellij.remoterobot.utils.waitFor
import com.intellij.remoterobot.utils.waitForIgnoringError
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import java.awt.event.KeyEvent
import java.awt.event.KeyEvent.VK_I
import java.awt.event.KeyEvent.VK_J
import java.time.Duration.ofMinutes
import java.time.Duration.ofSeconds
@ExtendWith(RemoteRobotExtension::class)
class InlineEdit {
init {
StepsLogger.init()
}
@BeforeEach
fun waitForIde(remoteRobot: RemoteRobot) {
waitForIgnoringError(ofMinutes(3)) { remoteRobot.callJs("true") }
}
@AfterEach
fun closeProject(remoteRobot: RemoteRobot) = CommonSteps(remoteRobot).closeProject()
@Test
@Video
fun submitInlineEdit(remoteRobot: RemoteRobot): Unit = with(remoteRobot) {
welcomeFrame {
createNewProjectLink.click()
dialog("New Project") {
findText("Java").click()
checkBox("Add sample code").select()
button("Create").click()
}
}
// Wait for the default "Main.java" tab to load
// Our "continue_tutorial.java.ft" tab loads first, but then "Main.java" takes focus.
waitFor(ofSeconds(20)) {
findAll<ComponentFixture>(
byXpath("//div[@accessiblename='Main.java' and @class='SingleHeightLabel']")
).isNotEmpty()
}
idea {
with(textEditor()) {
val userMsg = "TEST_USER_MESSAGE_0"
editor.insertTextAtLine(0, 0, userMsg)
editor.selectText(userMsg)
keyboard {
hotKey(getMetaKey(), VK_I)
}
val textArea = find<ComponentFixture>(byXpath("//div[@class='CustomTextArea']"))
textArea.hasText("Enter instructions...")
val modelSelect = find<ComponentFixture>(byXpath("//div[@class='JComboBox']"))
modelSelect.hasText("TEST LLM")
keyboard {
enterText("Hello world!")
}
val enterBtn = find<ComponentFixture>(byXpath("//div[@class='CustomButton']"))
enterBtn.click()
find<ComponentFixture>(byXpath("//div[@text='⌥⇧N']")).isShowing
find<ComponentFixture>(byXpath("//div[@text='⌥⇧Y']")).isShowing
find<ComponentFixture>(byXpath("//div[@text='Accept All (⌘⇧⏎)']")).isShowing
find<ComponentFixture>(byXpath("//div[@text='Reject All (⌘⇧⌫)']")).isShowing
}
}
}
}