You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2015/12/04 15:36:51 UTC

svn commit: r1717971 - /sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ui/sightly/SightlyAutocompletionTest.java

Author: rombert
Date: Fri Dec  4 14:36:51 2015
New Revision: 1717971

URL: http://svn.apache.org/viewvc?rev=1717971&view=rev
Log:
SLING-5140 - Add tests for Sightly editor auto-completion 

Add a test for autocompleting attributes.

Modified:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ui/sightly/SightlyAutocompletionTest.java

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ui/sightly/SightlyAutocompletionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ui/sightly/SightlyAutocompletionTest.java?rev=1717971&r1=1717970&r2=1717971&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ui/sightly/SightlyAutocompletionTest.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ui/sightly/SightlyAutocompletionTest.java Fri Dec  4 14:36:51 2015
@@ -21,6 +21,7 @@ import static org.hamcrest.MatcherAssert
 
 import java.io.ByteArrayInputStream;
 import java.util.List;
+import java.util.concurrent.Callable;
 
 import org.apache.sling.ide.test.impl.helpers.ProjectAdapter;
 import org.apache.sling.ide.test.impl.helpers.TemporaryProject;
@@ -55,38 +56,85 @@ public class SightlyAutocompletionTest {
     @Test
     public void tagNameAutocompletion() throws Exception {
         
-        // create faceted project
-        IProject contentProject = projectRule.getProject();
-
-        ProjectAdapter project = new ProjectAdapter(contentProject);
-        project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
-
-        // install facets
-        project.installFacet("sling.content", "1.0");
-        project.installFacet("sightly", "1.1");
-        
-        // create basic html file
-        project.createOrUpdateFile(Path.fromOSString("jcr_root/index.html"), new ByteArrayInputStream("".getBytes()));
-        Thread.sleep(1000); // TODO - wait for project to be registered in the UI
-        
-        // ensure that we get the tree from the project explorer
-        bot.viewByTitle("Project Explorer").setFocus();
-        
-        // open editor
-        SWTBotTreeItem projectItem = bot.tree().expandNode(contentProject.getName());
-        // it seems that two 'jcr_root' nodes confuse SWTBot so we expand and navigate manually
-        SWTBotTreeItem folderNode = projectItem.getItems()[0].expand();
-        folderNode.getItems()[0].select().doubleClick();
+        List<String> proposals = new AutocompletionCallable() {
+            @Override
+            protected void prepareEditor(SWTBotEclipseEditor editor) {
+                editor.insertText("<html>\n\n</html>");
+                editor.navigateTo(1, 0);
+            }
+        }.call();
         
-        // generate auto-completion proposals
-        SWTBotEclipseEditor editor = bot.editorByTitle("index.html").toTextEditor();
-        editor.insertText("<html>\n\n</html>");
-        editor.navigateTo(1, 0);
-        List<String> proposals = editor.getAutoCompleteProposals("");
-        editor.saveAndClose();
 
         // validate auto-completion proposals
         assertThat("proposal list does not contain 'sly'", proposals, hasItem("sly"));
     }
+    
+    @Test
+    public void attributeAutocompletion() throws Exception {
+        
+        List<String> proposals = new AutocompletionCallable() {
+            @Override
+            protected void prepareEditor(SWTBotEclipseEditor editor) {
+                editor.insertText("<html>\n<div  ></div>\n</html>");
+                editor.navigateTo(1, 5);
+            }
+        }.call();
+
+        // validate auto-completion proposals
+        assertThat("proposal list does not contain 'data-sly-test'", proposals, hasItem("data-sly-test"));
+    }
+    
+    abstract class AutocompletionCallable implements Callable<List<String>> {
+        
+        @Override
+        public List<String> call() throws Exception {
+            
+            // create faceted project
+            IProject contentProject = projectRule.getProject();
+
+            ProjectAdapter project = new ProjectAdapter(contentProject);
+            project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
+
+            // install facets
+            project.installFacet("sling.content", "1.0");
+            project.installFacet("sightly", "1.1");
+            
+            // create basic html file
+            project.createOrUpdateFile(Path.fromOSString("jcr_root/index.html"), new ByteArrayInputStream("".getBytes()));
+            Thread.sleep(1000); // TODO - wait for project to be registered in the UI
+            
+            // ensure that we get the tree from the project explorer
+            bot.viewByTitle("Project Explorer").setFocus();
+            
+            // open editor
+            SWTBotTreeItem projectItem = bot.tree().expandNode(contentProject.getName());
+            // it seems that two 'jcr_root' nodes confuse SWTBot so we expand and navigate manually
+            SWTBotTreeItem folderNode = projectItem.getItems()[0].expand();
+            folderNode.getItems()[0].select().doubleClick();
+            
+            // generate auto-completion proposals
+            SWTBotEclipseEditor editor = bot.editorByTitle("index.html").toTextEditor();
+            prepareEditor(editor);
+
+            // gather proposals
+            List<String> proposals = editor.getAutoCompleteProposals("");
+            
+            // close editor, otherwise cleanup can hang due to the dialog
+            editor.saveAndClose();
+
+            return proposals;
+        }
+
+        /**
+         * Prepare the editor by adding text and positioning the cursor
+         * 
+         * <p>After this method is executed the editor must be ready to generate
+         * the autocompletions expected by the test</p>
+         * 
+         * @param editor the editor instance, never <code>null</code>
+         */
+        protected abstract void prepareEditor(SWTBotEclipseEditor editor);
+        
+    }
 
 }