mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-223845 Search Everywhere: update Goto tests to make them more similar to real usecases
GitOrigin-RevId: e85dba21ed5f14afad7bc2d98a8685a8da13eb95
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8ad0129429
commit
2db21e7843
@@ -0,0 +1,60 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.navigation
|
||||
|
||||
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributor
|
||||
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereManagerImpl
|
||||
import com.intellij.ide.actions.searcheverywhere.SearchEverywhereUI
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.junit.Assert
|
||||
|
||||
import java.util.concurrent.Future
|
||||
|
||||
class SearchEverywhereTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
SearchEverywhereUI mySearchUI
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (mySearchUI != null) {
|
||||
Disposer.dispose(mySearchUI)
|
||||
mySearchUI = null
|
||||
}
|
||||
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
void "test switch to external files when nothing is found"() {
|
||||
def strBuffer = myFixture.addClass("class StrBuffer{ }")
|
||||
def stringBuffer = myFixture.findClass("java.lang.StringBuffer")
|
||||
|
||||
def ui = createTestUI([ChooseByNameTest.createClassContributor(project)])
|
||||
|
||||
def future = ui.findElementsForPattern("StrBuffer")
|
||||
if (!waitFor(future)) Assert.fail("Search haven't finished")
|
||||
assert future.get() == [strBuffer]
|
||||
|
||||
future = ui.findElementsForPattern("StringBuffer")
|
||||
if (!waitFor(future)) Assert.fail("Search haven't finished")
|
||||
assert future.get() == [stringBuffer]
|
||||
}
|
||||
|
||||
private static boolean waitFor(Future<?> future, long timeout = 30000) {
|
||||
def start = System.currentTimeMillis()
|
||||
while (!future.isDone()) {
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
if (System.currentTimeMillis() - start > timeout) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
private SearchEverywhereUI createTestUI(List<SearchEverywhereContributor<Object>> contributors) {
|
||||
if (mySearchUI != null) Disposer.dispose(mySearchUI)
|
||||
|
||||
mySearchUI = new SearchEverywhereUI(project, contributors)
|
||||
mySearchUI.switchToContributor(SearchEverywhereManagerImpl.ALL_CONTRIBUTORS_GROUP_ID)
|
||||
return mySearchUI
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -16,6 +16,7 @@ import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
|
||||
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
|
||||
import com.intellij.openapi.actionSystem.impl.ActionButtonWithText;
|
||||
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
@@ -267,7 +268,9 @@ public abstract class AbstractGotoSEContributor implements WeightedSearchEverywh
|
||||
}
|
||||
};
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
|
||||
Application application = ApplicationManager.getApplication();
|
||||
if (application.isUnitTestMode() && application.isDispatchThread()) {
|
||||
fetchRunnable.run();
|
||||
}
|
||||
else {
|
||||
|
||||
+21
@@ -65,6 +65,7 @@ import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
@@ -73,6 +74,8 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -952,6 +955,16 @@ public class SearchEverywhereUI extends BigPopupUI implements DataProvider, Quic
|
||||
return isAllTabSelected() ? getAllTabContributors() : Collections.singleton(mySelectedTab.getContributor().get());
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
private CompletableFuture<List<Object>> testResultsFuture;
|
||||
|
||||
@TestOnly
|
||||
public Future<List<Object>> findElementsForPattern(String pattern) {
|
||||
testResultsFuture = new CompletableFuture<>();
|
||||
mySearchField.setText(pattern);
|
||||
return testResultsFuture;
|
||||
}
|
||||
|
||||
private class CompositeCellRenderer implements ListCellRenderer<Object> {
|
||||
|
||||
@Override
|
||||
@@ -1618,6 +1631,14 @@ public class SearchEverywhereUI extends BigPopupUI implements DataProvider, Quic
|
||||
hasMoreContributors.forEach(myListModel::setHasMore);
|
||||
|
||||
mySelectionTracker.resetSelectionIfNeeded();
|
||||
|
||||
//noinspection TestOnlyProblems
|
||||
if (testResultsFuture != null) {
|
||||
//noinspection TestOnlyProblems
|
||||
testResultsFuture.complete(myListModel.getItems());
|
||||
//noinspection TestOnlyProblems
|
||||
testResultsFuture = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user