From eaf490d7f0d4d7d66bc6690c3837ec774912e728 Mon Sep 17 00:00:00 2001 From: Yuliya Karalenka Date: Mon, 4 Aug 2025 18:35:10 +0200 Subject: [PATCH] [terminal] Add test to check terminal completion behavior while up and down actions (cherry picked from commit 7a82f0dffca6abeb9e9f85f95d5ead6011fbf4dd) IJ-MR-170869 GitOrigin-RevId: ec6b884863d92ce906ee8fc4bbc98a7df1c88818 --- .../frontend/TerminalCompletionFixture.kt | 46 ++++++++++++------- .../frontend/TerminalCompletionTest.kt | 18 ++++++++ 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionFixture.kt b/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionFixture.kt index 4d68af8c4a2c..93c7dd822a9f 100644 --- a/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionFixture.kt +++ b/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionFixture.kt @@ -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) + } + } } \ No newline at end of file diff --git a/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionTest.kt b/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionTest.kt index 1f0170951c23..1bb60fe3095f 100644 --- a/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionTest.kt +++ b/plugins/terminal/tests/src/com/intellij/terminal/tests/reworked/frontend/TerminalCompletionTest.kt @@ -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) + } } \ No newline at end of file