use another fixture as base class for course creator tests
[idea/community.git] / python / educational-core / course-creator / testSrc / com / jetbrains / edu / coursecreator / actions / CCAnswerPlaceholderActionTest.java
1 package com.jetbrains.edu.coursecreator.actions;
2
3 import com.intellij.openapi.actionSystem.Presentation;
4 import com.intellij.openapi.command.undo.UndoManager;
5 import com.intellij.openapi.fileEditor.FileEditorManager;
6 import com.intellij.openapi.project.Project;
7 import com.intellij.openapi.vfs.VirtualFile;
8 import com.jetbrains.edu.coursecreator.CCTestCase;
9 import com.jetbrains.edu.coursecreator.CCTestsUtil;
10 import com.jetbrains.edu.learning.StudyUtils;
11 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
12 import com.jetbrains.edu.learning.courseFormat.TaskFile;
13 import com.jetbrains.edu.learning.ui.CCCreateAnswerPlaceholderDialog;
14
15 import java.util.Collections;
16 import java.util.List;
17
18 public class CCAnswerPlaceholderActionTest extends CCTestCase {
19   static class CCTestAction extends CCAddAnswerPlaceholder {
20     @Override
21     protected CCCreateAnswerPlaceholderDialog createDialog(Project project, AnswerPlaceholder answerPlaceholder) {
22       return new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder.getTaskText(), answerPlaceholder.getHints()) {
23         @Override
24         public boolean showAndGet() {
25           return true;
26         }
27
28         @Override
29         public String getTaskText() {
30           return "type here";
31         }
32
33         @Override
34         public List<String> getHints() {
35           return Collections.singletonList("Test hint");
36         }
37       };
38     }
39   }
40
41   public void testPlaceholderWithSelection() {
42     doTest("onePlaceholder");
43   }
44
45   public void testPlaceholderWithoutSelection() {
46     doTest("withoutSelection");
47   }
48
49   public void testPlaceholderIntersection() {
50     configureByTaskFile("placeholderIntersection.txt");
51     Presentation presentation = myFixture.testAction(new CCTestAction());
52     assertTrue(presentation.isVisible() && !presentation.isEnabled());
53   }
54
55   public void testPlaceholderDeleted() {
56     doTest("deletePlaceholder");
57   }
58
59   private void doTest(String name) {
60     VirtualFile virtualFile = configureByTaskFile(name + CCTestsUtil.BEFORE_POSTFIX);
61     myFixture.testAction(new CCTestAction());
62     TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
63     checkByFile(taskFile, name + CCTestsUtil.AFTER_POSTFIX, false);
64     checkHighlighters(taskFile, myFixture.getEditor().getMarkupModel());
65     UndoManager.getInstance(getProject()).undo(FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile));
66     checkByFile(taskFile, name + CCTestsUtil.BEFORE_POSTFIX, false);
67   }
68
69   @Override
70   protected String getBasePath() {
71     return super.getBasePath()  + "/actions/addPlaceholder";
72   }
73 }