Skip to content

Commit

Permalink
Handlebars: cleanup moveUp test
Browse files Browse the repository at this point in the history
  • Loading branch information
zolotov authored and dmarcotte committed Jul 26, 2015
1 parent 840ab79 commit 15f8f49
Showing 1 changed file with 9 additions and 38 deletions.
47 changes: 9 additions & 38 deletions test/src/com/dmarcotte/handlebars/editor/actions/HbMoverTest.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,36 @@
package com.dmarcotte.handlebars.editor.actions;

import com.dmarcotte.handlebars.util.HbTestUtils;
import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementUpAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.io.File;


public class HbMoverTest extends LightPlatformCodeInsightFixtureTestCase {

@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
public HbMoverTest() {
PlatformTestCase.initPlatformLangPrefix();
}

public void testMoveXmlWhenOpenHtmlAsHandlebars() throws Exception {
public void testMoveXmlWhenOpenHtmlAsHandlebars() {
HbTestUtils.setOpenHtmlAsHandlebars(true, getProject(), getTestRootDisposable());
doTest("hbs");
}

public void testMoveHbsTag() throws Exception {
public void testMoveHbsTag() {
doTest("hbs");
}

private void doTest(String ext) throws Exception {
final String baseName = getBasePath() + '/' + getTestName(true);
final String fileName = baseName + "." + ext;

@NonNls String afterFileName = baseName + "_after." + ext;
EditorActionHandler handler = new MoveStatementUpAction().getHandler();
performAction(fileName, handler, afterFileName);
}

private void performAction(final String fileName, final EditorActionHandler handler, final String afterFileName) throws Exception {
myFixture.configureByFile(fileName);
final boolean enabled = handler.isEnabled(myFixture.getEditor(), null);
assertEquals("not enabled for " + afterFileName, new File(getTestDataPath(), afterFileName).exists(), enabled);
if (enabled) {
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
handler.execute(myFixture.getEditor(), null);
}
});
myFixture.checkResultByFile(afterFileName);
}
private void doTest(@NotNull String ext) {
myFixture.configureByFile(getTestName(true) + "." + ext);
myFixture.performEditorAction(IdeActions.ACTION_MOVE_STATEMENT_UP_ACTION);
myFixture.checkResultByFile(getTestName(true) + "_after." + ext);
}

@Override
protected String getBasePath() {
return "mover";
}


@NotNull
@Override
protected String getTestDataPath() {
return HbTestUtils.BASE_TEST_DATA_PATH;
return HbTestUtils.BASE_TEST_DATA_PATH + "/mover";
}
}

0 comments on commit 15f8f49

Please sign in to comment.