[terminal] Add test to check terminal completion behavior while up and down actions

(cherry picked from commit 7a82f0dffca6abeb9e9f85f95d5ead6011fbf4dd)

IJ-MR-170869

GitOrigin-RevId: ec6b884863d92ce906ee8fc4bbc98a7df1c88818
This commit is contained in:
Yuliya Karalenka
2025-08-07 16:16:56 +00:00
committed by intellij-monorepo-bot
parent 2c2d95bd92
commit eaf490d7f0
2 changed files with 48 additions and 16 deletions
@@ -54,22 +54,7 @@ class TerminalCompletionFixture(val project: Project, testRootDisposable: Dispos
}
fun callCompletionPopup() {
val actionId = "Terminal.CommandCompletion.Gen2"
val action = ActionManager.getInstance().getAction(actionId)
val context = SimpleDataContext.builder()
.add(CommonDataKeys.PROJECT, project)
.add(CommonDataKeys.EDITOR, view.outputEditor)
.add(TerminalOutputModel.KEY, view.outputModel)
.build()
val event = AnActionEvent.createEvent(action, context, null,
"", ActionUiKind.NONE, null)
ActionUtil.updateAction(action, event)
if (event.presentation.isEnabledAndVisible) {
ActionUtil.performAction(action, event)
}
runActionById("Terminal.CommandCompletion.Gen2")
}
fun isLookupActive(): Boolean {
@@ -82,4 +67,33 @@ class TerminalCompletionFixture(val project: Project, testRootDisposable: Dispos
val activeLookup = lookupManager.activeLookup
return activeLookup?.items ?: emptyList()
}
fun getCurrentItem(): LookupElement? {
val lookupManager = LookupManager.getInstance(project)
val activeLookup = lookupManager.activeLookup
return activeLookup?.currentItem
}
fun downCompletionPopup() {
runActionById("Terminal.DownCommandCompletion")
}
fun upCompletionPopup() {
runActionById("Terminal.UpCommandCompletion")
}
private fun runActionById(actionId: String) {
val action = ActionManager.getInstance().getAction(actionId)
val context = SimpleDataContext.builder()
.add(CommonDataKeys.PROJECT, project)
.add(CommonDataKeys.EDITOR, view.outputEditor)
.add(TerminalOutputModel.KEY, view.outputModel)
.build()
val event = AnActionEvent.createEvent(action, context, null,
"", ActionUiKind.NONE, null)
ActionUtil.updateAction(action, event)
if (event.presentation.isEnabledAndVisible) {
ActionUtil.performAction(action, event)
}
}
}
@@ -1,6 +1,7 @@
package com.intellij.terminal.tests.reworked.frontend
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import org.junit.Assert.assertNotEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -24,4 +25,21 @@ class TerminalCompletionTest : BasePlatformTestCase() {
assertEquals(listOf("stage", "stash", "status"), resultStrings)
}
@Test
fun `test terminal completion up and down`() {
val terminalCompletionFixture = TerminalCompletionFixture(project, testRootDisposable)
terminalCompletionFixture.type("git b")
terminalCompletionFixture.callCompletionPopup()
val startResult = terminalCompletionFixture.getLookupElements()
assertEquals(3, startResult.size)
val firstElement = terminalCompletionFixture.getCurrentItem()
terminalCompletionFixture.downCompletionPopup()
val secondElement = terminalCompletionFixture.getCurrentItem()
terminalCompletionFixture.upCompletionPopup()
val fistAfterElement = terminalCompletionFixture.getCurrentItem()
assertEquals(firstElement, fistAfterElement)
assertNotEquals(secondElement, fistAfterElement)
}
}