Search in sources :

Example 6 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class ReformatOnlyVcsChangedTextTest method testOptimizeImportsInModule.

public void testOptimizeImportsInModule() throws IOException {
    ChangedFilesStructure fs = new ChangedFilesStructure(myWorkingDirectory);
    String initialFile = "initial file";
    PsiFile toModify = fs.createFile("Modified.txt", initialFile, initialFile + " + unused import");
    PsiFile toModify2 = fs.createFile("Modified2.txt", initialFile, initialFile + " + another unused import");
    PsiFile toKeep = fs.createFile("NonModified.txt", initialFile, initialFile);
    PsiFile toKeep2 = fs.createFile("NonModified2.txt", initialFile, initialFile);
    OptimizeImportsAction optimizeImports = new OptimizeImportsAction();
    OptimizeImportsAction.setProcessVcsChangedFilesInTests(true);
    try {
        optimizeImports.actionPerformed(new TestActionEvent(dataId -> {
            if (CommonDataKeys.PROJECT.is(dataId)) {
                return getProject();
            }
            if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
                return getModule();
            }
            return null;
        }));
    } finally {
        OptimizeImportsAction.setProcessVcsChangedFilesInTests(false);
    }
    assertTrue(isImportsOptimized(toModify));
    assertTrue(isImportsOptimized(toModify2));
    assertTrue(!isImportsOptimized(toKeep));
    assertTrue(!isImportsOptimized(toKeep2));
}
Also used : Arrays(java.util.Arrays) Change(com.intellij.openapi.vcs.changes.Change) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) MockChangeListManager(com.intellij.testFramework.vcs.MockChangeListManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) VcsContextFactory(com.intellij.openapi.vcs.actions.VcsContextFactory) SimpleContentRevision(com.intellij.openapi.vcs.changes.SimpleContentRevision) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) LightPlatformTestCase(com.intellij.testFramework.LightPlatformTestCase) MockVcsContextFactory(com.intellij.testFramework.vcs.MockVcsContextFactory) FilePath(com.intellij.openapi.vcs.FilePath) VcsUtil(com.intellij.vcsUtil.VcsUtil) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) IOException(java.io.IOException) LanguageImportStatements(com.intellij.lang.LanguageImportStatements) TestActionEvent(com.intellij.testFramework.TestActionEvent) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) MutablePicoContainer(org.picocontainer.MutablePicoContainer) LanguageFormatting(com.intellij.lang.LanguageFormatting) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiDirectory(com.intellij.psi.PsiDirectory) ComponentManagerImpl(com.intellij.openapi.components.impl.ComponentManagerImpl) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) PsiFile(com.intellij.psi.PsiFile) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 7 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class TaskUiTest method testTaskComboVisible.

public void testTaskComboVisible() throws Exception {
    SwitchTaskAction combo = null;
    ActionGroup group = (ActionGroup) CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
    ActionToolbarImpl toolbar = (ActionToolbarImpl) ActionManager.getInstance().createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
    AnAction[] children = group.getChildren(new TestActionEvent());
    for (AnAction child : children) {
        if (child instanceof ActionGroup) {
            AnAction[] actions = ((ActionGroup) child).getChildren(new TestActionEvent());
            for (AnAction action : actions) {
                if (action instanceof SwitchTaskAction) {
                    combo = (SwitchTaskAction) action;
                }
            }
        }
    }
    TaskManager manager = TaskManager.getManager(getProject());
    LocalTask defaultTask = manager.getActiveTask();
    assertTrue(defaultTask.isDefault());
    assertEquals(defaultTask.getCreated(), defaultTask.getUpdated());
    Presentation presentation = doTest(combo, toolbar);
    assertFalse(presentation.isVisible());
    try {
        TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO = true;
        presentation = doTest(combo, toolbar);
        assertTrue(presentation.isVisible());
    } finally {
        TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO = false;
    }
    LocalTask task = manager.createLocalTask("test");
    manager.activateTask(task, false);
    presentation = doTest(combo, toolbar);
    assertTrue(presentation.isVisible());
    manager.activateTask(defaultTask, false);
    task = manager.getActiveTask();
    assertTrue(task.isDefault());
    presentation = doTest(combo, toolbar);
    if (!presentation.isVisible()) {
        LocalTask activeTask = manager.getActiveTask();
        System.out.println(activeTask);
        System.out.println(activeTask.getCreated());
        System.out.println(activeTask.getUpdated());
        fail();
    }
}
Also used : SwitchTaskAction(com.intellij.tasks.actions.SwitchTaskAction) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 8 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class TaskUiTest method doTest.

private static Presentation doTest(AnAction action, ActionToolbarImpl toolbar) {
    TestActionEvent event = new TestActionEvent(toolbar.getPresentation(action));
    action.update(event);
    return event.getPresentation();
}
Also used : TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 9 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class CCShowPreviewTest method getActionEvent.

TestActionEvent getActionEvent(AnAction action, PsiFile psiFile) {
    MapDataContext context = new MapDataContext();
    context.put(CommonDataKeys.PSI_FILE, psiFile);
    context.put(CommonDataKeys.PROJECT, getProject());
    context.put(LangDataKeys.MODULE, myFixture.getModule());
    return new TestActionEvent(context, action);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 10 with TestActionEvent

use of com.intellij.testFramework.TestActionEvent in project intellij-community by JetBrains.

the class CCShowPreviewTest method testPreviewUnavailable.

public void testPreviewUnavailable() {
    VirtualFile file = configureByTaskFile("noplaceholders.txt");
    CCShowPreview action = new CCShowPreview();
    TestActionEvent e = getActionEvent(action, PsiManager.getInstance(getProject()).findFile(file));
    action.beforeActionPerformedUpdate(e);
    assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
    try {
        action.actionPerformed(e);
        assertTrue("No message shown", false);
    } catch (RuntimeException ex) {
        assertEquals(CCShowPreview.NO_PREVIEW_MESSAGE, ex.getMessage());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Aggregations

TestActionEvent (com.intellij.testFramework.TestActionEvent)16 AnAction (com.intellij.openapi.actionSystem.AnAction)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 CreateFromTemplateGroup (com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup)2 FileTemplateManagerImpl (com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 RenameElementAction (com.intellij.refactoring.actions.RenameElementAction)2 MapDataContext (com.intellij.testFramework.MapDataContext)2 TestDataProvider (com.intellij.testFramework.TestDataProvider)2 Arrays (java.util.Arrays)2 List (java.util.List)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 IdeBundle (com.intellij.ide.IdeBundle)1 GotoRelatedSymbolAction (com.intellij.ide.actions.GotoRelatedSymbolAction)1 CreateFromTemplateAction (com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction)1 BrowseTypeHierarchyAction (com.intellij.ide.hierarchy.actions.BrowseTypeHierarchyAction)1 LanguageFormatting (com.intellij.lang.LanguageFormatting)1 LanguageImportStatements (com.intellij.lang.LanguageImportStatements)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1