Test for FindUIHelper

This commit is contained in:
Vassiliy.Kudryashov
2017-07-04 18:19:19 +03:00
parent 48c34329ae
commit d5d38e8a70
3 changed files with 69 additions and 3 deletions
@@ -383,6 +383,7 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider {
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabled(myHelper.getModel().isOpenInNewTabEnabled());
e.getPresentation().setVisible(myHelper.getModel().isOpenInNewTabVisible());
}
});
tabResultsContextGroup.setPopup(true);
@@ -177,9 +177,8 @@ public class FindUIHelper implements Disposable {
}
void setUseSeparateView(boolean separateView) {
if (myModel.isOpenInNewTabEnabled()) {
myModel.setOpenInNewTab(separateView);
}
if (!myModel.isOpenInNewTabEnabled()) throw new IllegalStateException("'Open in new Tab' is not enabled");
myModel.setOpenInNewTab(separateView);
FindSettings.getInstance().setShowResultsInSeparateView(separateView);
}
@@ -0,0 +1,66 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.find.impl;
import com.intellij.find.FindManager;
import com.intellij.find.FindModel;
import com.intellij.testFramework.LightPlatformTestCase;
public class FindUIHelperTest extends LightPlatformTestCase {
private static final Runnable STUB = () -> {
};
private FindUIHelper myHelper;
private FindManagerImpl myFindManager;
@Override
protected void setUp() throws Exception {
super.setUp();
myFindManager = ((FindManagerImpl)FindManager.getInstance(getProject()));
FindModel findModel = FindManager.getInstance(getProject()).getFindInProjectModel();
myHelper = new FindUIHelper(getProject(), findModel, STUB);
}
public void testBasic() {
assertFalse(myHelper.getModel().isOpenInNewTabEnabled());
boolean initialSeparateViewState = myHelper.isUseSeparateView();
try {
myHelper.setUseSeparateView(!initialSeparateViewState);
fail("There should be an exception");
}
catch (IllegalStateException e) {
//it's ok
myHelper.getModel().setOpenInNewTabEnabled(true);
myHelper.setUseSeparateView(!initialSeparateViewState);
}
assertNotSame(initialSeparateViewState, myHelper.isUseSeparateView());
myHelper.setUseSeparateView(initialSeparateViewState);
assertSame(initialSeparateViewState, myHelper.isUseSeparateView());
boolean initialSkipResultsWithOneUsage = myHelper.isSkipResultsWithOneUsage();
myHelper.setSkipResultsWithOneUsage(!initialSkipResultsWithOneUsage);
assertNotSame(initialSeparateViewState, myHelper.isSkipResultsWithOneUsage());
myHelper.setSkipResultsWithOneUsage(initialSkipResultsWithOneUsage);
assertSame(initialSeparateViewState, myHelper.isSkipResultsWithOneUsage());
myFindManager.changeGlobalSettings(myHelper.getModel());
FindModel findModel = FindManager.getInstance(getProject()).getFindInProjectModel();
myHelper = new FindUIHelper(getProject(), findModel, STUB);
assertSame(initialSeparateViewState, myHelper.isUseSeparateView());
assertSame(initialSeparateViewState, myHelper.isSkipResultsWithOneUsage());
}
}