You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by sb...@apache.org on 2015/05/12 18:35:05 UTC

svn commit: r1678999 - in /sling/trunk/contrib/explorers/resourceeditor: ./ src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/ src/main/resources/SLING-INF/libs/sling/resource-editor/ src/test/javascript/e2e/spec/ src/test/...

Author: sboehme
Date: Tue May 12 16:35:04 2015
New Revision: 1678999

URL: http://svn.apache.org/r1678999
Log:
SLING-4555 Resource Editor: Added initial end to end tests. Now with the actual content. :-)

Modified:
    sling/trunk/contrib/explorers/resourceeditor/README
    sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js
    sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/JSTreeAdapter.js
    sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/TreeController.js
    sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp
    sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js
    sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/spec/resource_editor_spec.js

Modified: sling/trunk/contrib/explorers/resourceeditor/README
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/README?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/README (original)
+++ sling/trunk/contrib/explorers/resourceeditor/README Tue May 12 16:35:04 2015
@@ -14,10 +14,11 @@ o To run the build on your local machine
 o To have the less sources automatically compiled on change call `./grunt watch:less` in the frontend directory. Press Ctrl-Z to stop watching.
 o To have the 'desktop_build' target triggered on changes in the frontend tests, less sources, JavaScript files and JSP sources use `./grunt watch:all` in the frontend directory and also press Ctrl-Z to stop watching.
 o To get the end to end tests triggered by changes use './grunt watch:e2e' in the frontend directory and also press Ctrl-Z to stop watching.
+o If you don't use 'localhost' as server and '8080' as port you can specify your values by using the environment variables 'SLING_SERVER' 'SLING_PORT'.
 
 ++ Debugging the the end to end tests ++
 o You can still use 'console.log()' and JSON.stringify(display) to inspect JSON values of a test spec.
-o You can use 'client.pause([milliseconds]);' in you test spec to pause and also inspect the browser status.
+o You can use 'client.pause([milliseconds]);' in your test spec to pause and also inspect the browser status.
 o To set breakpoints in a test spec you can use a JavaScript IDE like 'Webstorm'
 
 

Modified: sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js Tue May 12 16:35:04 2015
@@ -237,6 +237,7 @@ org.apache.sling.reseditor.AddNodeContro
 		$("#nodeType").select2({
 			placeholder: "Select a node type",
 			allowClear: true,  
+			dropdownCssClass: "node_type_dd_container",
 			selectOnBlur: true,
 			data: function() { 
 			      return { results: thatAddNodeController.nodeTypeObjects } ; // Use the global variable to populate the list
@@ -261,6 +262,7 @@ org.apache.sling.reseditor.AddNodeContro
 			var select2 = $("#resourceType").select2({
 				placeholder: "Enter or select a resource type",
 				allowClear: true, 
+				dropdownCssClass: "resource_type_dd_container",
 				selectOnBlur: true,
 				data: data,
 				createSearchChoice: function(searchTerm){
@@ -268,9 +270,8 @@ org.apache.sling.reseditor.AddNodeContro
 					return {id:searchTerm, text:searchTerm};
 				}
 			}).data("select2");
-			$("#resourceType").on("select2-loaded", function() {
-				$('#addNodeDialog').append('<div class="add-node-finished"></div>');
-			});
+			$('#addNodeDialog').addClass('add-node-finished');
+//			$('#addNodeDialog').append('<div id="add-node-finished"></div>');
 		});
 	}
 	

Modified: sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/JSTreeAdapter.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/JSTreeAdapter.js?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/JSTreeAdapter.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/JSTreeAdapter.js Tue May 12 16:35:04 2015
@@ -122,11 +122,9 @@ $(document).ready(function() {
 		"dnd" : {
 			"drop_finish" : function () {
 				console.log("drop");
-				alert("DROP"); 
 			},
 			"drag_finish" : function (data) {
 				console.log("drag");
-				alert("DRAG OK"); 
 			}
 		},
 		// the `plugins` array allows you to configure the active plugins on this instance
@@ -167,6 +165,10 @@ $(document).ready(function() {
     	treeController.configureKeyListeners(e);
     }).on('select_node.jstree', function (e, data) {
     	;
+    }).on('after_open.jstree', function(e, data){
+    	treeController.afterOpen(data.node);
+    }).on('close_node.jstree', function(e, data){
+    	treeController.beforeClose(data.node);
     });
 });
 

Modified: sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/TreeController.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/TreeController.js?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/TreeController.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/TreeController.js Tue May 12 16:35:04 2015
@@ -81,7 +81,14 @@ org.apache.sling.reseditor.TreeControlle
 		}
 		
 	}
-	
+
+	TreeController.prototype.afterOpen = function(node) {
+		$('#'+node.id).addClass("opened");
+	}
+
+	TreeController.prototype.beforeClose = function(node) {
+		$('#'+node.id).removeClass("opened");
+	}
 
 	TreeController.prototype.openNodeTarget = function(e) {
 		var url = $(e.target).parent().attr("href");

Modified: sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor/html.jsp Tue May 12 16:35:04 2015
@@ -329,7 +329,7 @@ new org.apache.sling.reseditor.JSTreeAda
 					    <label for="nodeType">Node Type - <span class="nt-dependency-description">applicable together with node name</span> (<a class="nt-toggle" href="javascript:void(0)">show generally applicable</a>)</label>
 					    <input name="jcr:primaryType" type="hidden" id="nodeType">
 					  </div>
-					  <div class="form-group">
+					  <div class="form-group resource-type">
 					    <label for="resourceType">Sling Resource Type</label>
 					    <input name="sling:resourceType" type="hidden" id="resourceType">
 					    <span class="resource-type-not-allowed help-block" style="display:none;">The selected node type does not allow the resulting node to have a Sling resource type property.</span>

Modified: sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js Tue May 12 16:35:04 2015
@@ -21,59 +21,204 @@
 
 var assert = require('assert');
 
-describe('A user of the Apache Sling Resource Editor', function() {
-	var homeURL = 'http://localhost:8080/reseditor/.html';
+describe('A user of the Apache Sling Resource Editor', function() { 
+	// see http://stackoverflow.com/questions/29370075/how-to-pass-parameters-from-the-gruntfile-js-to-the-webdriverio-spec
+	var homeURL = 'http://'+process.env.SLING_SERVER+':'+process.env.SLING_PORT+'/reseditor/.html';
 	var client = browser.url(homeURL);
-	// TODO: Find a way to specify the host and the port via grunt. See 
-	// http://stackoverflow.com/questions/29370075/how-to-pass-parameters-from-the-gruntfile-js-to-the-webdriverio-spec
-	client.timeouts("script", 500);
+
+	client.timeouts("script", 1000);
+	client.timeouts("implicit", 1000);
+	client.timeouts("page load", 1000);
 
 	describe('can open the add node dialog with', function() {
 		  it('the icon', function(done) {
-			  client = client.url(homeURL);
-			  client.waitForExist('#last-element', function(err) {
-				  client.click('#root_anchor i.add-icon', function(err, res) {
-					  client.waitForVisible('#addNodeDialog', function(err) {
-			    		  client.getCssProperty('#addNodeDialog', 'display', function(err, display) {
-				    		  assert(typeof err === "undefined" || err === null);
-				    		  assert(display.value === "block");
-				    	  });
-			    	  });
-			      })
+			  client.url(homeURL).waitForExist('#last-element').
+			  click('#root_anchor i.add-icon').waitForVisible('#addNodeDialog', function(err, visible) {
+	    		  assert(typeof err === "undefined" || err === null);
+	    		  assert(true === visible);
 		      })
 		      .call(done);
 		  });
 
 		  it('the shortcut', function(done) {
-			  client = client.url(homeURL);
-			  client.waitForExist('#last-element', function(err) {
-				  client.click('#root_anchor i.add-icon', function(err, res) {
-					  client.keys("a", function(err) {
-						  client.waitForVisible('#addNodeDialog', function(err) {
-				    		  client.getCssProperty('#addNodeDialog', 'display', function(err, display) {
-					    		  assert(typeof err === "undefined" || err === null);
-					    		  assert(display.value === "block");
-					    	  });
-				    	  });
-					  });
-			      })
+			   client.url(homeURL).waitForExist('#last-element')
+			  .click('#root_anchor i.jstree-themeicon')
+			  .keys("c").waitForVisible('#addNodeDialog', function(err, visible) {
+	    		  assert(typeof err === "undefined" || err === null);
+	    		  assert(true === visible);
 		      })
 		      .call(done);
 		  });
 	});
 
+	  it('can login as admin', function(done) {
+		  client.url(homeURL).waitForExist('#last-element')
+		  .click('#login_tab').waitForVisible('#login_submit')
+		  .setValue('#login_form input[name="j_username"]', 'admin')
+		  .setValue('#login_form input[name="j_password"]', 'admin')
+		  .click('#login_submit').waitForExist('#login .logout')
+		  .getText('#login_tab', function(err, text) {
+    		  assert(typeof err === "undefined" || err === null);
+			  assert("Logout admin" === text);
+	      })
+	      .call(done);
+	  });
+	  
 	  it('can add an unstructured node to the root node', function(done) {
+		  client.url(homeURL).waitForExist('#last-element')
+		  .click("#root i.add-icon").waitForVisible('#addNodeDialog.add-node-finished .node_name_dd_container input')
+		  .setValue('.node_name_dd_container input', "aTestNode")
+		  .addValue('.node_name_dd_container input', 'Return') // presses the 'return' key
+		  .click('#addNodeDialog .btn.btn-primary.submit').waitForExist("#root li[nodename=\"aTestNode\"]", function(err, existed) {
+			  assert(typeof err === "undefined" || err === null);
+			  assert(existed === true);
+	      })
+	      .call(done);
+	  });
+	  
+	 it('can add a node with an encoded name on the second level ', function(done) {
+		  client.url(homeURL).waitForExist('#last-element')
+		  .click("#root li[nodename=\"aTestNode\"] i.add-icon").waitForVisible('#addNodeDialog.add-node-finished .node_name_dd_container input')
+		  .setValue('.node_name_dd_container input', "täßt ?<>")
+		  .addValue('.node_name_dd_container input', 'Return') // presses the 'return' key
+		  .click('#addNodeDialog .btn.btn-primary.submit').waitForExist("#root  li[nodename=\"aTestNode\"].opened li[nodename=\"täßt ?&lt;&gt;\"]", function(err, existed) {
+			  assert(typeof err === "undefined" || err === null);
+			  assert(existed === true);
+	      })
+	      .call(done); 
+	  });
+	 
+	  it('can link to a node with an encoded name', function(done) {
+		  var encodedNodeNameSelector = '#root li[nodename="aTestNode"].opened li[nodename="täßt ?&lt;&gt;"]';
+		  var encodedNodeNameOpenSelector = encodedNodeNameSelector +' i.open-icon';
+		  client.url(homeURL).waitForExist('#last-element')
+		  .click("#root li[nodename=\"aTestNode\"] i.jstree-ocl").waitForExist(encodedNodeNameOpenSelector)
+		  .click(encodedNodeNameOpenSelector).waitForExist(encodedNodeNameSelector+' a.jstree-clicked', function(err, existed) {
+			  assert(typeof err === "undefined" || err === null);
+			  assert(existed === true);
+	      })
+	      .call(done);
+	  });
+	  
+
+	  it('can add a node with a specific node type ', function(done) {
+		  client.url(homeURL);
+		  client.waitForExist('#last-element').click("#root li[nodename=\"aTestNode\"] i.add-icon").waitForVisible('#addNodeDialog.add-node-finished .node_name_dd_container', 1000)
+		  .setValue('.node_name_dd_container input', "aFolder")
+		  .addValue('.node_name_dd_container input', 'Return')
+		  .click(".form-group.node-type .select2-chosen").waitForExist('.node_type_dd_container input')
+		  .setValue('.node_type_dd_container input', "sling:Folder")
+		  .addValue('.node_type_dd_container input', 'Return')
+		  .click('#addNodeDialog .btn.btn-primary.submit').waitForExist('#root  li[nodename="aTestNode"] li[nodename="aFolder"][nodetype="sling:Folder"]', function(err, existed) {
+			  assert(typeof err === "undefined" || err === null);
+			  assert(existed === true);
+		  })
+	      .call(done);
+	  });
+	  
+	  it('can add a node with a resource type on the second level ', function(done) {
+		  var nodeName =  "a node with a resource type";
+		  var resourceType =  "test/resource-editor/resource-type";
+		  var resourceTypeSelector = '#root  li[nodename="aTestNode"].opened li[nodename="a node with a resource type"] span.node-type';
+		  client.url(homeURL);
+		  client.waitForExist('#last-element').click("#root li[nodename=\"aTestNode\"] i.add-icon")
+		  .waitForVisible('#addNodeDialog.add-node-finished .node_name_dd_container', 1000)
+		  .setValue('.node_name_dd_container input', nodeName)
+		  .addValue('.node_name_dd_container input', 'Return') // presses the 'return' key
+		  .click(".form-group.resource-type .select2-chosen").waitForExist('.resource_type_dd_container input', 1000)
+		  .setValue('.resource_type_dd_container input', resourceType)
+		  .addValue('.resource_type_dd_container input', 'Return') // presses the 'return' key
+		  .click('#addNodeDialog .btn.btn-primary.submit').waitForExist(resourceTypeSelector, 1000)
+		  .getText(resourceTypeSelector, function(err, text) {
+			  assert(typeof err === "undefined" || err === null);
+			  assert(text === resourceType);
+		  })
+	      .call(done);
+	  });
+	  
+	  it('can rename a node with an encoded name', function(done) {
+		  client = client.url(homeURL);
+		  client.waitForExist('#last-element', function(err) {
+			  client.click("#root li[nodename=\"aTestNode\"] i.jstree-ocl", function(err, res) {
+				  var encodedNodeNameSelector = '#root li[nodename="aTestNode"].opened li[nodename="täßt ?&lt;&gt;"]';
+				  var encodedNodeNameAnchorSelector = encodedNodeNameSelector +' a .node-type';
+// 				  The open node animation will take longer than 500ms thus setting 2000ms as max.
+				  client.waitForExist(encodedNodeNameAnchorSelector, 2000, function(err, existed) {
+					  client.doubleClick(encodedNodeNameAnchorSelector, function(err) {
+						  var encodedNodeNameInputSelector = encodedNodeNameSelector+' input.jstree-rename-input';
+						  client.waitForExist(encodedNodeNameInputSelector, function(err, existed) {
+							  client.setValue(encodedNodeNameInputSelector, 'täßt2& <>');
+							  client.execute(function() {
+								  $('#root li[nodename="aTestNode"] li[nodename="täßt ?&lt;&gt;"] input.jstree-rename-input').blur();
+								  $('#root li[nodename="aTestNode"] li[nodename="täßt ?&lt;&gt;"] input.jstree-rename-input').blur();
+								});
+							  client.waitForExist('#root li[nodename="aTestNode"].opened li[nodename="täßt2&amp; &lt;&gt;"]', 2000, function(err, existed) {
+								  assert(typeof err === "undefined" || err === null);
+								  assert(true === existed);
+								  
+							  });
+						  });
+					  });
+			      })  
+		      })  
+	      })
+	      .call(done);
+	  });
+	  it('can delete nodes via multi selection and shortcut', function(done) {
+		  client = client.url(homeURL);
+		  client
+		  .waitForExist('#last-element').click("#root li[nodename=\"aTestNode\"] i.add-icon")
+		  	.waitForVisible('#addNodeDialog.add-node-finished').click('#addNodeDialog .btn.btn-primary.submit')
+		  	// The open node animation will take longer than 500ms thus setting 2000ms as max.
+		  	.waitForExist('#root li[nodename="aTestNode"].opened', 2000).elements('#root li[nodename="aTestNode"].opened li a .jstree-themeicon', function(err, res) {
+			    client
+		         .moveTo(res.value[0].ELEMENT, 0, 0)
+		         .buttonPress('left')
+		         .keys('Shift')
+		         .moveTo(res.value[1].ELEMENT, 0, 0)
+		         .buttonPress('left');
+
+			    client.keys('Shift'); // release the Shift key
+			    
+			    // On Mac the ctrl key opens the context menu in the browser
+			    // this is why the Cmd key should be used in this case.
+			    if ('darwin' === process.platform){
+			    	client.keys('Command');
+			    } else {
+			    	client.keys('Control');
+			    }
+		        
+			    client.moveTo(res.value[3].ELEMENT, 0, 0)
+		        .buttonPress('left');
+			    client.keys('NULL'); // release all keys
+		  });
+		  var confirmationOkBtn = 'div.bootbox-confirm div.modal-footer button[data-bb-handler="confirm"]';
+		  var openTestNodeIcon = '#root li[nodename=\"aTestNode\"] i.open-icon';
+		  client.keys('Delete')
+		  .waitForVisible(confirmationOkBtn)
+		  .click(confirmationOkBtn)
+		  .waitForVisible(openTestNodeIcon)
+		  .click(openTestNodeIcon)
+		  .waitForExist('#last-element').elements('#root li[nodename="aTestNode"] li a .jstree-themeicon', function(err, res) {
+    		  assert(typeof err === "undefined" || err === null);
+			  assert(1 === res.value.length);
+		  });
+	      client.call(done);
+		  
+	  });
+
+	  it('can delete a node with the icon', function(done) {
 		  client = client.url(homeURL);
 		  client.waitForExist('#last-element', function(err) {
-			  client.click('#root_anchor i.add-icon', function(err, res) {
-				  client.waitForVisible('#addNodeDialog .add-node-finished', function(err) {
-					  client.setValue('.node_name_dd_container input', 'testnode');
-					  client.addValue('.node_name_dd_container input', 'Return'); // presses the 'return' key
-					  client.click('#addNodeDialog .btn.btn-primary.submit', function(err, res) {
-						  client.pause(3000); 
+			  client.click('li[nodetype="rep:root"] li[nodename="aTestNode"] a i.remove-icon', function(err, res) {
+				  client.waitForText('div.bootbox-confirm div.bootbox-body', function(err, result, third, fourth){
+					  client.click('div.bootbox-confirm div.modal-footer button[data-bb-handler="confirm"]', function(err, res) {
+						  client.waitForExist('li[nodetype="rep:root"] li[nodename="aTestNode"]', true/*reverse*/, function(err, existed) {
+							  assert(typeof err === "undefined" || err === null);
+							  assert(existed === false);
+						  });
 					  });
-		    	  });
-				  
+				  });
 		      })  
 	      })
 	      .call(done);

Modified: sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/spec/resource_editor_spec.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/spec/resource_editor_spec.js?rev=1678999&r1=1678998&r2=1678999&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/spec/resource_editor_spec.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/spec/resource_editor_spec.js Tue May 12 16:35:04 2015
@@ -21,9 +21,10 @@ describe('The Resource Editor', function
 
 	it('\'s MainController', function() {
 //		it('can encode a URL', function() {
+			// Mock it!
 //			var ntManager = new de.sandroboehme.NodeTypeManager();
 			var mainControllerSettings = {
-					contextPath: "/",
+					contextPath: "/"//,
 //					nodeTypes: ntManager.getNodeTypeNames() 
 			};
 			var mainController = new org.apache.sling.reseditor.MainController(mainControllerSettings, null);