mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[remote-driver] add SearchEveryWhereUiTest#testCommands and SearchEveryWhereUiTest#testNavigationBetweenTabs
GitOrigin-RevId: 166e7fbeb77969c0dde2da742778d412bd08706f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
24a332b1c3
commit
926f5dfcfc
@@ -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>) -> 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user