in intellij-plugin/educational-core/testSrc/com/jetbrains/edu/learning/testUtils.kt [96:140]
fun testAction(
action: AnAction,
context: DataContext? = null,
shouldBeEnabled: Boolean = true,
shouldBeVisible: Boolean = shouldBeEnabled,
runAction: Boolean = shouldBeEnabled
): Presentation {
val e = if (context != null) TestActionEvent.createTestEvent(action, context) else TestActionEvent.createTestEvent(action)
val project = e.project
if ((action !is DumbAware || action is CheckAction) && project != null) {
// Since 242 tests don't wait when indexes are ready.
// But we don't want to check non-`DumbAware` actions in dumb mode since it doesn't make sense.
// Also, even `CheckAction` is `DumbAware`, we don't want to run it in dumb mode as well
// because the only thing that it does in dumb mode is showing balloon to inform users about dumb mode
IndexingTestUtil.waitUntilIndexesAreReady(project)
}
ActionUtil.updateAction(action, e)
val presentation = e.presentation
if (presentation.isEnabled != shouldBeEnabled) {
val message = if (shouldBeEnabled) {
"`${action.javaClass.name}` action is not enabled as expected"
} else {
"`${action.javaClass.name}` action is not disabled as expected"
}
error(message)
}
if (presentation.isVisible != shouldBeVisible) {
val message = if (shouldBeVisible) {
"`${action.javaClass.name}` action is not visible as expected"
} else {
"`${action.javaClass.name}` action is not invisible as expected"
}
error(message)
}
if (ActionUtil.lastUpdateAndCheckDumb(action, e, true) && runAction) {
ActionUtil.performActionDumbAwareWithCallbacks(action, e)
}
return presentation
}