diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt index 4a78f2986657..b587ba37a313 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/FocusIssuesUtil.kt @@ -2,27 +2,63 @@ package com.intellij.testGuiFramework.tests.community.focus import com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI +import com.intellij.testGuiFramework.framework.GuiTestUtil.defaultTimeout +import com.intellij.testGuiFramework.framework.GuiTestUtil.textfield import com.intellij.testGuiFramework.impl.GuiRobotHolder +import com.intellij.testGuiFramework.impl.GuiTestUtilKt import com.intellij.ui.components.fields.ExtendableTextField import org.fest.swing.exception.ComponentLookupException import org.junit.Assert import java.awt.Container +import java.awt.Window +import javax.swing.JLabel object FocusIssuesUtil { - fun checkSearchEverywhereUI(expectedString: String) { - val searchEverywhereUI = try { - findSearchEverywhereUI() + fun checkSearchEnteredText(expectedString: String) { + val actualString = try { + val searchEverywhereUI = findSearchUiWithWaitingIdle() + val extendableTextField: ExtendableTextField = GuiRobotHolder.robot.finder().find( + searchEverywhereUI) { it is ExtendableTextField } as ExtendableTextField + extendableTextField.text + } catch (cle: ComponentLookupException) { + //if search dialog appeared as a HeavyWeightWindow + textfield("", findSearchEverywhereWindowWithWaitingIdle(), defaultTimeout).text() + } + Assert.assertEquals(expectedString, actualString) + } + + private fun findSearchEverywhereWindowWithWaitingIdle(): Container { + return try { + findSearchEverywhereWindow() } catch (cle: ComponentLookupException) { + GuiRobotHolder.robot.waitForIdle() + findSearchEverywhereWindow() + } + } + + private fun findSearchEverywhereWindow(): Container { + fun checkWindowContainsEnterClassName(it: Window) + = GuiTestUtilKt.findAllWithBFS(it, JLabel::class.java) + .firstOrNull { it.text?.contains("Search Everywhere:") == true || it.text?.contains("Enter class name:") == true} != null + return Window.getWindows() + .filterNotNull() + .firstOrNull { checkWindowContainsEnterClassName(it) } ?: throw ComponentLookupException( + "Unable to find search window") + } + + private fun findSearchUiWithWaitingIdle(): Container { + return try { + findSearchEverywhereUI() + } catch (cle: ComponentLookupException) { GuiRobotHolder.robot.waitForIdle() findSearchEverywhereUI() } - val extendableTextField: ExtendableTextField = GuiRobotHolder.robot.finder().find(searchEverywhereUI) { it is ExtendableTextField } as ExtendableTextField - Assert.assertEquals(expectedString, extendableTextField.text) } private fun findSearchEverywhereUI(): Container { return GuiRobotHolder.robot.finder().find { it is SearchEverywhereUI } as SearchEverywhereUI } + } \ No newline at end of file diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt index 5ef558b73f18..ead26cf3fe0f 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassFocusTest.kt @@ -7,7 +7,7 @@ import com.intellij.testGuiFramework.fixtures.IdeFrameFixture import com.intellij.testGuiFramework.impl.GuiRobotHolder import com.intellij.testGuiFramework.impl.GuiTestCase import com.intellij.testGuiFramework.tests.community.CommunityProjectCreator -import com.intellij.testGuiFramework.tests.community.focus.FocusIssuesUtil.checkSearchEverywhereUI +import com.intellij.testGuiFramework.tests.community.focus.FocusIssuesUtil.checkSearchEnteredText import com.intellij.testGuiFramework.util.Key.ESCAPE import org.fest.swing.core.SmartWaitRobot import org.fest.swing.timing.Pause @@ -68,7 +68,7 @@ class GoToClassFocusTest : GuiTestCase() { val smartRobot = GuiRobotHolder.robot as SmartWaitRobot smartRobot.shortcutAndTypeString(actionKeyStroke, typedString, 100) Pause.pause(500) - checkSearchEverywhereUI(typedString) + checkSearchEnteredText(typedString) shortcut(ESCAPE) } diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt index a729e64a04b0..ac8617a04275 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/GoToClassTwiceFocusTest.kt @@ -82,7 +82,7 @@ class GoToClassTwiceFocusTest : GuiTestCase() { smartRobot.shortcut(actionKeyStroke) smartRobot.shortcutAndTypeString(actionKeyStroke, typedString, 100) Pause.pause(500) - FocusIssuesUtil.checkSearchEverywhereUI(typedString) + FocusIssuesUtil.checkSearchEnteredText(typedString) shortcut(ESCAPE) } diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt index 39ce8e321146..149e4d9667ca 100644 --- a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt @@ -23,7 +23,7 @@ class SearchEverywhereFocusTest : GuiTestCase() { doubleShift(50) fastType(typedString) Pause.pause(500) - FocusIssuesUtil.checkSearchEverywhereUI(typedString) + FocusIssuesUtil.checkSearchEnteredText(typedString) shortcut(ESCAPE) focusOnEditor() }