From 926f5dfcfc38b00df72c49e4f06c17fd6c8eee2e Mon Sep 17 00:00:00 2001 From: "vladislav.shishov" Date: Fri, 13 Sep 2024 11:00:56 +0300 Subject: [PATCH] [remote-driver] add SearchEveryWhereUiTest#testCommands and SearchEveryWhereUiTest#testNavigationBetweenTabs GitOrigin-RevId: 166e7fbeb77969c0dde2da742778d412bd08706f --- .../ui/components/SearchEverywherePopupUI.kt | 45 ++++++++++++++++--- .../AccessibleNameCellRendererReader.kt | 13 +++++- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/components/SearchEverywherePopupUI.kt b/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/components/SearchEverywherePopupUI.kt index d030b87ffd46..493aa2fadc3c 100644 --- a/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/components/SearchEverywherePopupUI.kt +++ b/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/components/SearchEverywherePopupUI.kt @@ -1,8 +1,10 @@ package com.intellij.driver.sdk.ui.components +import com.intellij.driver.client.Remote import com.intellij.driver.model.OnDispatcher import com.intellij.driver.sdk.ActionManager import com.intellij.driver.sdk.ActionUtils +import com.intellij.driver.sdk.AnAction import com.intellij.driver.sdk.ui.AccessibleNameCellRendererReader import com.intellij.driver.sdk.ui.Finder import com.intellij.driver.sdk.ui.should @@ -12,10 +14,10 @@ import javax.swing.JList import kotlin.time.Duration.Companion.seconds -fun Finder.searchEverywherePopup(@Language("xpath") xpath: String? = null, block: SearchEverywherePopupUI.() -> Unit = {}) = x(xpath ?: xQuery { componentWithChild(byClass("HeavyWeightWindow"), byClass("SearchEverywhereUI")) }, - SearchEverywherePopupUI::class.java).apply(block) +fun Finder.searchEverywherePopup(@Language("xpath") xpath: String? = null, block: SearchEverywherePopupUI.() -> Unit = {}) = + x(xpath ?: xQuery { componentWithChild(byClass("HeavyWeightWindow"), byClass("SearchEverywhereUI")) }, SearchEverywherePopupUI::class.java).apply(block) -class SearchEverywherePopupUI(data: ComponentData): PopupUiComponent(data) { +class SearchEverywherePopupUI(data: ComponentData) : PopupUiComponent(data) { val resultsList by lazy { x(JListUiComponent::class.java) { byType(JList::class.java) }.apply { replaceCellRendererReader(driver.new(AccessibleNameCellRendererReader::class)) @@ -23,6 +25,7 @@ class SearchEverywherePopupUI(data: ComponentData): PopupUiComponent(data) { } val searchField: JTextFieldUI = textField { byType("com.intellij.ide.actions.BigPopupUI${"$"}SearchField") } val openInFindToolWindowButton: ActionButtonUi = actionButtonByXpath(xQuery { byAccessibleName("Open in Find Tool Window") }) + val searchEverywhereUi = x(SearchEveryWhereUi::class.java) { byType("com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI") } fun invokeSelectAction() { invokeActionWithShortcut("[pressed ENTER]") @@ -32,6 +35,16 @@ class SearchEverywherePopupUI(data: ComponentData): PopupUiComponent(data) { invokeActionWithShortcut("[shift pressed ENTER]") } + fun invokeSwitchToNextTabAction() { + invokeActionWithShortcut("[pressed TAB]") { it.getOrNull(1) } // there are two actions with [tab] shortcut + } + + fun invokeSwitchToPrevTabAction() { + invokeActionWithShortcut("[shift pressed TAB]") + } + + fun getSelectedTab(): SearchEverywhereTab = SearchEverywhereTab.entries.single { it.id == searchEverywhereUi.getSelectedTabID() } + fun searchAndChooseFirst(text: String, exactMatch: Boolean = true) { keyboard { backspace() @@ -43,13 +56,31 @@ class SearchEverywherePopupUI(data: ComponentData): PopupUiComponent(data) { } } - private fun invokeActionWithShortcut(shortcut: String) { - val searchEveryWhereUiComponent = x { byType("com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI") } - val action = driver.utility(ActionUtils::class).getActions(searchEveryWhereUiComponent.component).singleOrNull { + private fun invokeActionWithShortcut(shortcut: String, chooser: (List) -> AnAction? = { it.singleOrNull() }) { + val action = driver.utility(ActionUtils::class).getActions(searchEverywhereUi.component).filter { it.getShortcutSet().getShortcuts().singleOrNull()?.toString() == shortcut - } ?: error("'Action with shortcut '$shortcut' was not found") + }.let(chooser) ?: error("'Action with shortcut '$shortcut' was not found") driver.withContext(OnDispatcher.EDT) { service(ActionManager::class).tryToExecute(action, null, null, null, true) } } + + enum class SearchEverywhereTab(val id: String) { + All("SearchEverywhereContributor.All"), + Classes("ClassSearchEverywhereContributor"), + Files("FileSearchEverywhereContributor"), + Symbols("SymbolSearchEverywhereContributor"), + Actions("ActionSearchEverywhereContributor"), + } + + class SearchEveryWhereUi(data: ComponentData) : UiComponent(data) { + private val searchEverywhereUiComponent get() = driver.cast(component, SearchEverywhereUiComponent::class) + + fun getSelectedTabID(): String = searchEverywhereUiComponent.getSelectedTabID() + } + + @Remote("com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI") + interface SearchEverywhereUiComponent { + fun getSelectedTabID(): String + } } \ No newline at end of file diff --git a/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/AccessibleNameCellRendererReader.kt b/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/AccessibleNameCellRendererReader.kt index ae07c9d09b5c..06f1f1df8921 100644 --- a/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/AccessibleNameCellRendererReader.kt +++ b/plugins/performanceTesting/remote-driver/src/com/jetbrains/performancePlugin/remotedriver/fixtures/AccessibleNameCellRendererReader.kt @@ -1,10 +1,21 @@ package com.jetbrains.performancePlugin.remotedriver.fixtures +import org.assertj.swing.core.BasicComponentFinder import org.assertj.swing.driver.CellRendererReader import java.awt.Component +import java.awt.Container class AccessibleNameCellRendererReader : CellRendererReader { override fun valueFrom(c: Component?): String? { - return c?.accessibleContext?.accessibleName ?: "" + var accessibleName = c?.accessibleContext?.accessibleName + if (accessibleName == null && c is Container) { + accessibleName = findSomeChildComponentAccessibleName(c) + } + return accessibleName ?: "" + } + + private fun findSomeChildComponentAccessibleName(c: Container): String? { + return BasicComponentFinder.finderWithCurrentAwtHierarchy().findAll(c) { c -> c.accessibleContext.accessibleName != null } + .firstOrNull()?.accessibleContext?.accessibleName } } \ No newline at end of file