tests for task file actions
authorliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 23 Aug 2016 13:34:02 +0000 (16:34 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 23 Aug 2016 13:34:02 +0000 (16:34 +0300)
python/educational-core/course-creator/testData/actions/taskFileActions/nonTaskFile.txt [new file with mode: 0644]
python/educational-core/course-creator/testData/actions/taskFileActions/taskFile.txt [new file with mode: 0644]
python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/CCTestCase.java
python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCTaskFileActionTest.java [new file with mode: 0644]

diff --git a/python/educational-core/course-creator/testData/actions/taskFileActions/nonTaskFile.txt b/python/educational-core/course-creator/testData/actions/taskFileActions/nonTaskFile.txt
new file mode 100644 (file)
index 0000000..57f41b7
--- /dev/null
@@ -0,0 +1 @@
+non task file
\ No newline at end of file
diff --git a/python/educational-core/course-creator/testData/actions/taskFileActions/taskFile.txt b/python/educational-core/course-creator/testData/actions/taskFileActions/taskFile.txt
new file mode 100644 (file)
index 0000000..03f277c
--- /dev/null
@@ -0,0 +1 @@
+test task file with <placeholder>placeholder</placeholder>
\ No newline at end of file
index 4cfa08c913281660c8d0d6805e0e49f48dadc59d..8a16347581ff13483f7cc3d0ad1c77b8f77849d6 100644 (file)
@@ -106,13 +106,16 @@ public abstract class CCTestCase extends CodeInsightFixtureTestCase {
     });
   }
 
     });
   }
 
+  protected VirtualFile copyFileToTask(String name) {
+    return myFixture.copyFileToProject(name, FileUtil.join(getProject().getBasePath(), "lesson1", "task1", name));
+  }
+
   protected VirtualFile configureByTaskFile(String name) {
     Task task = StudyTaskManager.getInstance(getProject()).getCourse().getLessons().get(0).getTaskList().get(0);
     TaskFile taskFile = new TaskFile();
     taskFile.setTask(task);
     task.getTaskFiles().put(name, taskFile);
   protected VirtualFile configureByTaskFile(String name) {
     Task task = StudyTaskManager.getInstance(getProject()).getCourse().getLessons().get(0).getTaskList().get(0);
     TaskFile taskFile = new TaskFile();
     taskFile.setTask(task);
     task.getTaskFiles().put(name, taskFile);
-    VirtualFile file =
-      myFixture.copyFileToProject(name, FileUtil.join(getProject().getBasePath(), "lesson1", "task1", name));
+    VirtualFile file = copyFileToTask(name);
     myFixture.configureFromExistingVirtualFile(file);
     Document document = FileDocumentManager.getInstance().getDocument(file);
     for (AnswerPlaceholder placeholder : getPlaceholders(document, false)) {
     myFixture.configureFromExistingVirtualFile(file);
     Document document = FileDocumentManager.getInstance().getDocument(file);
     for (AnswerPlaceholder placeholder : getPlaceholders(document, false)) {
diff --git a/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCTaskFileActionTest.java b/python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCTaskFileActionTest.java
new file mode 100644 (file)
index 0000000..c8c12a9
--- /dev/null
@@ -0,0 +1,57 @@
+package com.jetbrains.edu.coursecreator.actions;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.command.undo.UndoManager;
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.testFramework.MapDataContext;
+import com.intellij.testFramework.TestActionEvent;
+import com.jetbrains.edu.coursecreator.CCTestCase;
+import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.courseFormat.TaskFile;
+import org.jetbrains.annotations.NotNull;
+
+public class CCTaskFileActionTest extends CCTestCase {
+  public void testHideTaskFile() {
+    VirtualFile virtualFile = configureByTaskFile("taskFile.txt");
+    launchAction(virtualFile, new CCHideFromStudent());
+    assertNull(StudyUtils.getTaskFile(getProject(), virtualFile));
+    UndoManager.getInstance(getProject()).undo(FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile));
+    TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
+    assertNotNull(taskFile);
+    checkHighlighters(taskFile, myFixture.getEditor().getMarkupModel());
+  }
+
+  public void testAddTaskFile() {
+    VirtualFile virtualFile = copyFileToTask("nonTaskFile.txt");
+    myFixture.configureFromExistingVirtualFile(virtualFile);
+    launchAction(virtualFile, new CCAddAsTaskFile());
+    TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
+    assertNotNull(taskFile);
+    FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile);
+    UndoManager.getInstance(getProject()).undo(fileEditor);
+    assertNull(StudyUtils.getTaskFile(getProject(), virtualFile));
+  }
+
+  private void launchAction(VirtualFile virtualFile, AnAction action) {
+    TestActionEvent e = getActionEvent(virtualFile, action);
+    action.beforeActionPerformedUpdate(e);
+    assertTrue(e.getPresentation().isEnabled() && e.getPresentation().isVisible());
+    action.actionPerformed(e);
+  }
+
+  @NotNull
+  private TestActionEvent getActionEvent(VirtualFile virtualFile, AnAction action) {
+    MapDataContext context = new MapDataContext();
+    context.put(CommonDataKeys.VIRTUAL_FILE, virtualFile);
+    context.put(CommonDataKeys.PROJECT, getProject());
+    return new TestActionEvent(context, action);
+  }
+
+  @Override
+  protected String getBasePath() {
+    return super.getBasePath() + "/actions/taskFileActions";
+  }
+}