mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[terminal] Add test to check terminal completion behavior while left and right actions
(cherry picked from commit c6d9646f9af83073ffcce7ba356bcf9b2e96a2d8) IJ-MR-170869 GitOrigin-RevId: d5edd54ab3cf70cd942e9dbfc57b090a0205a725
This commit is contained in:
committed by
intellij-monorepo-bot
parent
eaf490d7f0
commit
a1189ae31c
+8
-1
@@ -76,6 +76,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.intellij.codeInsight.completion.CompletionPhase.CUSTOM_CODE_COMPLETION_ACTION_ID;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class CompletionProgressIndicator extends ProgressIndicatorBase implements CompletionProcessEx, Disposable {
|
||||
private static final int TEST_COMPLETION_TIMEOUT = 100 * 1000;
|
||||
@@ -843,7 +845,12 @@ public final class CompletionProgressIndicator extends ProgressIndicatorBase imp
|
||||
if (handler.isTestingMode() && !TestModeFlags.is(CompletionAutoPopupHandler.ourTestingAutopopup)) {
|
||||
closeAndFinish(false);
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
new CodeCompletionHandlerBase(myCompletionType, false, false, true).invokeCompletion(getProject(), myEditor, myInvocationCount);
|
||||
String customId = myEditor.getUserData(CUSTOM_CODE_COMPLETION_ACTION_ID);
|
||||
if (customId == null) {
|
||||
customId = "CodeCompletion";
|
||||
}
|
||||
CodeCompletionHandlerBase handler = CodeCompletionHandlerBase.createHandler(myCompletionType, false, false, true, customId);
|
||||
handler.invokeCompletion(getProject(), myEditor, myInvocationCount);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+22
@@ -82,6 +82,28 @@ class TerminalCompletionFixture(val project: Project, testRootDisposable: Dispos
|
||||
runActionById("Terminal.UpCommandCompletion")
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates a key press in the active completion popup.
|
||||
* @param keyCode (VK_LEFT or VK_ENTER)
|
||||
*/
|
||||
fun pressKey(keycode: Int) {
|
||||
if (keycode != KeyEvent.VK_LEFT && keycode != KeyEvent.VK_RIGHT) {
|
||||
throw IllegalArgumentException("keycode must be VK_LEFT or VK_RIGHT")
|
||||
}
|
||||
val keyPressEvent = KeyEvent(
|
||||
view.outputEditor.component,
|
||||
KeyEvent.KEY_PRESSED,
|
||||
System.currentTimeMillis(),
|
||||
0,
|
||||
keycode,
|
||||
KeyEvent.CHAR_UNDEFINED,
|
||||
KeyEvent.KEY_LOCATION_STANDARD
|
||||
)
|
||||
view.outputEditorEventsHandler.keyPressed(TimedKeyEvent(keyPressEvent, TimeSource.Monotonic.markNow()))
|
||||
val commonOffset = view.outputEditor.getCaretModel().offset
|
||||
view.outputModel.updateCursorPosition(view.outputModel.relativeOffset(commonOffset))
|
||||
}
|
||||
|
||||
private fun runActionById(actionId: String) {
|
||||
val action = ActionManager.getInstance().getAction(actionId)
|
||||
val context = SimpleDataContext.builder()
|
||||
|
||||
+41
@@ -5,6 +5,8 @@ import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import java.awt.event.KeyEvent.VK_LEFT
|
||||
import java.awt.event.KeyEvent.VK_RIGHT
|
||||
|
||||
@RunWith(JUnit4::class)
|
||||
class TerminalCompletionTest : BasePlatformTestCase() {
|
||||
@@ -42,4 +44,43 @@ class TerminalCompletionTest : BasePlatformTestCase() {
|
||||
assertEquals(firstElement, fistAfterElement)
|
||||
assertNotEquals(secondElement, fistAfterElement)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test terminal completion with left right`() {
|
||||
val terminalCompletionFixture = TerminalCompletionFixture(project, testRootDisposable)
|
||||
terminalCompletionFixture.type("git ")
|
||||
terminalCompletionFixture.callCompletionPopup()
|
||||
|
||||
terminalCompletionFixture.type("st")
|
||||
val startResult = terminalCompletionFixture.getLookupElements()
|
||||
|
||||
terminalCompletionFixture.pressKey(VK_LEFT)
|
||||
val afterFirstLeftResult = terminalCompletionFixture.getLookupElements()
|
||||
terminalCompletionFixture.pressKey(VK_LEFT)
|
||||
|
||||
val afterSecondLeftResult = terminalCompletionFixture.getLookupElements()
|
||||
assertNotEquals(afterFirstLeftResult.size, afterSecondLeftResult.size)
|
||||
|
||||
terminalCompletionFixture.pressKey(VK_RIGHT)
|
||||
val afterRightResult = terminalCompletionFixture.getLookupElements()
|
||||
assertEquals(afterFirstLeftResult.size, afterRightResult.size)
|
||||
|
||||
terminalCompletionFixture.pressKey(VK_RIGHT)
|
||||
val afterSecondRightResult = terminalCompletionFixture.getLookupElements()
|
||||
assertEquals(startResult.size, afterSecondRightResult.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test terminal completion with left right reopening`() {
|
||||
val terminalCompletionFixture = TerminalCompletionFixture(project, testRootDisposable)
|
||||
terminalCompletionFixture.type("git st")
|
||||
terminalCompletionFixture.callCompletionPopup()
|
||||
|
||||
val startResult = terminalCompletionFixture.getLookupElements()
|
||||
assertEquals(3, startResult.size)
|
||||
terminalCompletionFixture.pressKey(VK_LEFT)
|
||||
val afterLeftResult = terminalCompletionFixture.getLookupElements()
|
||||
assertEquals(6, afterLeftResult.size)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user