sample skeleton application with dojo toolkit & arcgis js api v 4.30
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

549 lines
19 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>doh.robot Editor/EnterKeyHandling Plugin Test</title>
<style>
@import "../../../../util/doh/robot/robot.css";
</style>
<script type="text/javascript" src="../../../../dojo/dojo.js"></script>
<script type="text/javascript">
require([
"doh/runner", "dojo/robotx",
"dojo/dom", "dojo/keys", "dojo/_base/lang", "dojo/sniff", "dojo/window",
"dijit/_editor/range", "dijit/tests/helpers", "dojo/domReady!"
], function(doh, robot, dom, keys, lang, has, winUtils, range, helpers){
function dom2string(root){
// summary:
// Simple dump of the HTML inside an editor, skipping
// attributes altogether. Similar to `dijit._editor.getNodeHtml`
// (maybe want to switch to using that).
var out = [];
function recurse(children){
var i=0, node = children[i++];
while(node){
switch(node.nodeType){
case 1: // normal node
if(node.childNodes.length){
out.push("<" + node.tagName.toLowerCase() + ">");
recurse(node.childNodes);
out.push("</" + node.tagName.toLowerCase() + ">");
}else{
out.push("<" + node.tagName.toLowerCase() + "/>");
}
break;
case 3: // text
var text = lang.trim(node.textContent || node.data).
replace('\u00a0', "&nbsp;");
if(text){
out.push(text);
}
break;
}
node = children[i++];
}
}
recurse(root.childNodes);
return out.join("");
}
robot.initRobot('../EnterKeyHandling.html');
var metaKey = has("mac")? {meta: true} : {ctrl: true};
var registry;
doh.register("setup", [
{
name: "wait for editors to load",
timeout: 5000,
runTest: helpers.waitForLoad
},
function setVars(){
registry = robot.window.require("dijit/registry");
}
]);
// Tests for BR mode
doh.register("blockNodeForEnter=BR", [
{
name: "wait for editors to load",
timeout: 5000,
runTest: function(){
return helpers.waitForLoad
}
},
{
name: "type in some text",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var br = registry.byId("br");
br.set("value", "");
br.focus();
robot.mouseMoveAt(br.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
// tab to the MenuBar... then focus should automatically shift to "File" menu,
for(var i=0; i<4; i++){
robot.typeKeys("ab345", 500);
robot.keyPress(keys.ENTER, 500, {});
}
robot.sequence(d.getTestCallback(function(){
// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
// paragraphs.
var value = br.get('value');
value = value.replace(/&nbsp;/g, "");
value = value.replace(/ /g, "");
value = value.replace(/\xA0/g, "");
doh.is('ab345<br/>ab345<br/>ab345<br/>ab345',
value,
"get('value')");
}), 1000);
return d;
}
},
{
name: "copy and paste",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var br = registry.byId("br");
br.set("value", "");
br.focus();
robot.mouseMoveAt(br.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
robot.typeKeys("testingCopyAndPaste", 500);
robot.keyPress("a", 500, metaKey); // select all
robot.keyPress("c", 500, metaKey); // copy
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress(keys.ENTER, 500, {shift: false});
robot.sequence(d.getTestCallback(function(){
// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
// paragraphs.
var value = br.get('value');
value = value.replace(/ /g, "");
value = value.replace(/\xA0/g, "");
if(has("webkit") && !has("mac")){
// Work around webkit bug:
// http://code.google.com/p/chromium/issues/detail?id=106551
// Should hopefully be fixed in Chrome 19.
value = value.replace(/\n/g, "");
value = value.replace(/\r\f/g, "");
}
doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste',
value,
"get('value')");
}), 1000);
return d;
}
},
{
name: "copy and paste split",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var br = registry.byId("br");
br.set("value", "");
br.focus();
robot.mouseMoveAt(br.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
robot.typeKeys("testingCopyAndPaste", 500);
robot.keyPress("a", 500, metaKey); // select all
robot.keyPress("c", 500, metaKey); // copy
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.ENTER, 500, {});
robot.sequence(d.getTestCallback(function(){
// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
// paragraphs.
var value = br.get('value');
value = value.replace(/ /g, "");
if(has("webkit") && !has("mac")){
// Work around webkit bug:
// http://code.google.com/p/chromium/issues/detail?id=106551
// Should hopefully be fixed in Chrome 19.
value = value.replace(/\n/g, "");
value = value.replace(/\r\f/g, "");
}
// Safari may end with a trailing/extra br, so we need to remove it.
if(/aste<br\/>$/.test(value)){
value = value.substring(0, value.length - 5);
}
doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndP<br/>aste',
value,
"get('value')");
}), 1000);
return d;
}
}
]);
doh.register("Split tests", [
{
name: "Test div line split",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
// The initial input was a div with a line of text with a bold tag in the middle.
// we want to focus on the bold and enter there, splitting it.
var editor = registry.byId("div2");
winUtils.scrollIntoView(editor.iframe);
var node = dom.byId("boldLine0", editor.document);
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.sequence(d.getTestErrback(function(){
editor.selection.selectElementChildren(node);
}), 500);
// Keyboard kill the selection and shift position between I and S.
if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
robot.keyPress(keys.LEFT_ARROW, 100, {});
robot.keyPress(keys.ENTER, 500);
robot.sequence(d.getTestCallback(function(){
// Do tests here.
var val = editor.get("value");
// Check that it split the is into two and that the bold and div were properly split.
doh.t(val.indexOf("It <b id=\"boldLine0\">I</b></div>") > 0, "start");
doh.t(val.indexOf("<div><b>S</b>") > 0, "end");
}), 500);
return d;
}
},
{
name: "Test div line split style clone",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
// The initial input was a div with a line of text with a bold tag in the middle.
// we want to focus on the bold and enter there, splitting it.
var editor = registry.byId("div3");
winUtils.scrollIntoView(editor.iframe);
var node = dom.byId("boldLine1", editor.document);
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.sequence(d.getTestErrback(function(){
editor.selection.selectElementChildren(node);
}), 500);
// Keyboard kill the selection and shift position between I and S.
if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
robot.keyPress(keys.LEFT_ARROW, 100, {});
robot.keyPress(keys.ENTER, 500);
robot.sequence(d.getTestCallback(function(){
// Do tests here.
var val = editor.get("value");
// Check that it split the is into two and that the bold and div were properly split.
val = val.toLowerCase();
doh.t(/it <b\s+id="boldline1"\s+style\s*=\s*"\s*font-size:\s*4em;?\s*">i<\/b><\/div>/.test(val), "start");
doh.t(/<div><b\s+style\s*=\s*"\s*font-size:\s*4em;?\s*">s<\/b>/.test(val), "end");
}), 500);
return d;
}
},
{
name: "Test div line split font clone",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
// The initial input was a div with a line of text with a font tag in the middle.
// we want to focus on the font and enter there, splitting it.
var editor = registry.byId("div4");
winUtils.scrollIntoView(editor.iframe);
var node = dom.byId("fontLine1", editor.document);
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.sequence(d.getTestErrback(function(){
editor.selection.selectElementChildren(node);
}), 500);
// Keyboard kill the selection and shift position between I and S.
if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
robot.keyPress(keys.LEFT_ARROW, 100, {});
robot.keyPress(keys.ENTER, 500);
robot.sequence(d.getTestCallback(function(){
// Do tests here.
var val = editor.get("value");
// Check that it split the is into two and that the bold and div were properly split.
val = val.toLowerCase();
doh.t(/it <font\s+id="fontline1"\s+size\s*=\s*"\s*5?\s*">i<\/font><\/div>/.test(val),"font not set on first line");
doh.t(/<div><font\s+size\s*=\s*"\s*5?\s*">s<\/font>/.test(val),"font not set on split line");
}), 500);
return d;
}
},
{
name: "copy and paste DIV",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var editor = registry.byId("div3");
winUtils.scrollIntoView(editor.iframe);
editor.set("value", "");
editor.focus();
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
robot.typeKeys("testingCopyAndPaste", 500);
robot.keyPress("a", 500, metaKey); // select all
robot.keyPress("c", 500, metaKey); // copy
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress(keys.ENTER, 500, {});
robot.sequence(d.getTestCallback(function(){
var value = editor.get('value');
value = value.replace(/\xA0/g, "");
if(has("webkit") && !has("mac")){
// Work around webkit bug:
// http://code.google.com/p/chromium/issues/detail?id=106551
// Should hopefully be fixed in Chrome 19.
value = value.replace(/\n/g, "");
value = value.replace(/\r\f/g, "");
}
doh.is('<div>testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste</div>',
value,
"get('value')");
}), 1000);
return d;
}
},
{
name: "copy and paste DIV split",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var editor = registry.byId("div3");
winUtils.scrollIntoView(editor.iframe);
editor.set("value", "");
editor.focus();
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
robot.typeKeys("testingCopyAndPaste", 500);
robot.keyPress("a", 500, metaKey); // select all
robot.keyPress("c", 500, metaKey); // copy
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.ENTER, 500, {});
robot.sequence(d.getTestCallback(function(){
// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
// paragraphs.
var value = editor.get('value');
value = value.replace(/\xA0/g, "");
if(has("webkit") && !has("mac")){
// Work around webkit bug:
// http://code.google.com/p/chromium/issues/detail?id=106551
// Should hopefully be fixed in Chrome 19.
value = value.replace(/\n/g, "");
value = value.replace(/\r\f/g, "");
}
doh.is('<div>testingCopyAndPastetestingCopyAndPastetestingCopyAndP</div><div>aste</div>',
value,
"get('value')");
}), 1000);
return d;
}
},
{
name: "Test p line split",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
// The initial input was a div with a line of text with a bold tag in the middle.
// we want to focus on the bold and enter there, splitting it.
var editor = registry.byId("p2");
winUtils.scrollIntoView(editor.iframe);
var node = dom.byId("boldLine2", editor.document);
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.sequence(d.getTestErrback(function(){
editor.selection.selectElementChildren(node);
}), 500);
// Keyboard kill the selection and shift position between I and S.
if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
robot.keyPress(keys.LEFT_ARROW, 100, {});
robot.keyPress(keys.ENTER, 500);
robot.sequence(d.getTestCallback(function(){
// Do tests here.
var val = editor.get("value");
// Check that it split the is into two and that the bold and div were properly split.
doh.t(val.indexOf("It <b id=\"boldLine2\">I</b></p>") > 0, "start");
doh.t(val.indexOf("<p><b>S</b>") > 0, "end");
}), 500);
return d;
}
},
{
name: "shift enter to replace all content in p",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var editor = registry.byId("p2");
editor.set('value','<p>ab</p>');
var selection = range.getSelection(editor.window);
selection.removeAllRanges();
var r = range.create(editor.window);
r.setStart(editor.editNode.firstChild, 0);
r.setEnd(editor.editNode.firstChild, 1);
selection.addRange(r);
robot.keyPress(keys.ENTER, 500, {shift: true});
robot.sequence(d.getTestCallback(function(){
var val = editor.get("value");
doh.is(val, '<p><br /></p>');
}), 1000);
return d;
}
},
{
name: "copy and paste P",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var editor = registry.byId("p2");
winUtils.scrollIntoView(editor.iframe);
editor.set("value", "");
editor.focus();
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
robot.typeKeys("testingCopyAndPaste", 500);
robot.keyPress("a", 500, metaKey); // select all
robot.keyPress("c", 500, metaKey); // copy
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress(keys.ENTER, 500, {});
robot.sequence(d.getTestCallback(function(){
var value = editor.get('value');
value = value.replace(/\xA0/g, "");
if(has("webkit") && !has("mac")){
// Work around webkit bug:
// http://code.google.com/p/chromium/issues/detail?id=106551
// Should hopefully be fixed in Chrome 19.
value = value.replace(/\n/g, "");
value = value.replace(/\r\f/g, "");
}
doh.is('<p>testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste</p>',
value,
"get('value')");
}), 1000);
return d;
}
},
{
name: "copy and paste P split",
timeout: 10000,
runTest: function(){
var d = new doh.Deferred();
var editor = registry.byId("p2");
winUtils.scrollIntoView(editor.iframe);
editor.set("value", "");
editor.focus();
robot.mouseMoveAt(editor.iframe, 500);
robot.mouseClick({left:true}, 500);
robot.keyPress(keys.BACKSPACE, 500, {});
robot.typeKeys("testingCopyAndPaste", 500);
robot.keyPress("a", 500, metaKey); // select all
robot.keyPress("c", 500, metaKey); // copy
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress("v", 500, metaKey); // paste
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.LEFT_ARROW, 500, {});
robot.keyPress(keys.ENTER, 500, {});
robot.sequence(d.getTestCallback(function(){
// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
// paragraphs.
var value = editor.get('value');
value = value.replace(/\xA0/g, "");
if(has("webkit") && !has("mac")){
// Work around webkit bug:
// http://code.google.com/p/chromium/issues/detail?id=106551
// Should hopefully be fixed in Chrome 19.
value = value.replace(/\n/g, "");
value = value.replace(/\r\f/g, "");
}
doh.is('<p>testingCopyAndPastetestingCopyAndPastetestingCopyAndP</p><p>aste</p>',
value,
"get('value')");
}), 1000);
return d;
}
}
]);
doh.run();
});
</script>
</head>
</html>