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));
}
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();
}
}
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();
}
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);
}
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());
}
}
Aggregations