package jetbrains.mps.lang.editor.menus.extras.tests;

/*Generated by MPS */

import jetbrains.mps.MPSLaunch;
import jetbrains.mps.lang.test.runtime.BaseTransformationTest;
import org.junit.jupiter.api.extension.RegisterExtension;
import jetbrains.mps.lang.test.runtime.TestParametersCacheExtension;
import jetbrains.mps.lang.test.runtime.TestParametersCache;
import org.junit.jupiter.api.Test;
import jetbrains.mps.lang.test.runtime.BaseEditorTestBody;
import jetbrains.mps.lang.test.runtime.TransformationTest;
import org.jetbrains.mps.openapi.module.SRepository;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.testFramework.TestApplicationManager;
import com.intellij.openapi.actionSystem.DataProvider;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.NonNls;
import jetbrains.mps.ide.actions.MPSCommonDataKeys;
import jetbrains.mps.refactoring.framework.IRefactoring;
import jetbrains.mps.smodel.SNodePointer;
import jetbrains.mps.nodeEditor.menus.transformation.DefaultTransformationMenuContext;
import jetbrains.mps.openapi.editor.menus.transformation.ActionItem;
import jetbrains.mps.lang.editor.menus.extras.runtime.RefactoringMenuItemBase;
import org.junit.Assert;

@MPSLaunch
public class RefactoringMenuItemBase_ApplicableRefactoring_CanExecute_Test extends BaseTransformationTest {
  @RegisterExtension
  private static final TestParametersCacheExtension ourParametersCacheExtension = new TestParametersCacheExtension(new TestParametersCache(RefactoringMenuItemBase_ApplicableRefactoring_CanExecute_Test.class, "${mps_home}", "r:a1e8c439-e997-416b-a5dc-df7c3fd41b00(jetbrains.mps.lang.editor.menus.extras.tests@tests)", false));

  public RefactoringMenuItemBase_ApplicableRefactoring_CanExecute_Test() {
    super(ourParametersCacheExtension.getParametersCache());
  }

  @Test
  public void test_RefactoringMenuItemBase_ApplicableRefactoring_CanExecute() throws Throwable {
    new TestBody(this).testMethod();
  }

  /*package*/ static class TestBody extends BaseEditorTestBody {

    /*package*/ TestBody(TransformationTest owner) {
      super(owner);
    }

    @Override
    public void testMethodImpl() throws Exception {
      initEditorComponent("6820996345401023608", "");
      final SRepository repository = getEditorComponent().getEditorContext().getRepository();

      Disposable dd = Disposer.newDisposable();
      TestApplicationManager.getInstance().setDataProvider(new DataProvider() {
        @Nullable
        @Override
        public Object getData(@NotNull @NonNls String key) {
          if (MPSCommonDataKeys.MPS_PROJECT.is(key)) {
            return myProject;
          }
          return null;
        }
      }, dd);
      repository.getModelAccess().runReadAction(() -> {
        IRefactoring refactoring = ActionLookupUtils.getRefactoring(myProject, new SNodePointer("r:2f49f947-e2b6-4dd2-87ae-7938deb42899(jetbrains.mps.lang.editor.menus.extras.testLanguage.refactorings)", "6820996345401025745"));
        DefaultTransformationMenuContext context = DefaultTransformationMenuContext.createInitialContextForCell(getEditorComponent().getSelectedCell(), "irrelevant location");
        ActionItem item = new RefactoringMenuItemBase(context, refactoring);

        Assert.assertTrue(item.canExecute("irrelevant pattern"));
      });
      Disposer.dispose(dd);
    }
  }
}
