dijit
Version:
Dijit provides a complete collection of user interface controls based on Dojo, giving you the power to create web applications that are highly optimized for usability, performance, internationalization, accessibility, but above all deliver an incredible u
171 lines (136 loc) • 5.3 kB
HTML
<html>
<head>
<title>robot Editor Mouse Test</title>
<style>
@import "../../../../util/doh/robot/robot.css";
</style>
<script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="async: true"></script>
<script type="text/javascript">
require([
"doh/runner", "dojo/robotx",
"dojo/dom-class", "dojo/keys", "dojo/query", "dojo/sniff",
"dijit/tests/helpers", "dojo/domReady!"
], function(doh, robot, domClass, keys, query, has, helpers){
function normalize(str){
// try to do some normalization to make all browsers look
// the same. Would be nice if we didn't need this, the normalization should
// probably happen as pre and post filters on the editor
return str.
replace(/\s*\/>/g, "/>").
replace(/<br\/>$/, ''). // FF. Because of EnterKeyHandling plugin?
replace(/^<p>/, '').replace(/<\/p>$/, ''). // Safari. Because of EnterKeyHandling plugin?
replace(new RegExp(String.fromCharCode(160), "g"), " "); // Safari: nbsp (char code 160) to normal space (char code 32)
}
robot.initRobot('../test_Editor.html');
// For some reason the meta key (meta-a for selection, meta-b for bold, etc) isn't working
// on mac... use ctrl- instead, just like on windows. (#9553)
var metaKey = {ctrl: true};
var editor0, editor1;
doh.register("setup", [
{
name: "wait for editors to load",
timeout: 5000,
runTest: helpers.waitForLoad
},
function setVars(){
registry = robot.window.require("dijit/registry");
editor0 = registry.byId("editor0");
doh.t(!!editor0, "editor0");
editor1 = registry.byId("editor1");
doh.t(!!editor1, "editor1");
}
]);
doh.register("toolbar buttons", [
{
name: "bold/italic",
timeout: 20000,
runTest: function(){
var d = new doh.Deferred();
var toolbar = editor1.toolbar,
boldButton = toolbar.getChildren()[7],
italicButton = toolbar.getChildren()[8];
// Focus the editor
robot.mouseMoveAt(editor1.editNode, 500, 1);
robot.mouseClick({left: true}, 500);
// select all and erase, by typing something new
robot.keyPress("a", 500, metaKey);
robot.typeKeys("hello ", 1000, 1000);
// turn on bold
robot.mouseMoveAt(boldButton.domNode, 500, 1);
robot.mouseClick({left: true}, 500);
robot.typeKeys("world", 1000, 1000);
// turn off bold
robot.mouseMoveAt(boldButton.domNode, 500, 1);
robot.mouseClick({left: true}, 500);
robot.typeKeys(". ", 1000, 400);
// turn on italic
robot.mouseMoveAt(italicButton.domNode, 500, 1);
robot.mouseClick({left: true}, 500);
robot.typeKeys("how are you", 1000, 2000);
// turn off italic
robot.mouseMoveAt(italicButton.domNode, 500, 1);
robot.mouseClick({left: true}, 500);
robot.typeKeys("?", 1000, 200);
robot.sequence(d.getTestCallback(function(){
// Get the value and try to do some normalization to make all browsers look
// the same. Would be nice if we didn't need this, the normalization should
// probably happen as pre and post filters on the editor
var val = normalize(editor1.get("value"));
doh.is("hello <b>world</b>. <i>how are you</i>?", val);
}), 1000);
return d;
}
},
{
name: "delete bold tag",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// Find the bolded "world" word in the editor
var bold = query('b', editor1.editNode);
if(!bold.length){
bold = query('strong', editor1.editNode)
}
// Double-click "world" to select it
robot.mouseMoveAt(bold[0], 500, 1, 5, 5);
robot.mouseClick({left: true}, 500);
robot.mouseClick({left: true}, 50);
// Delete "world" and the space before it
robot.keyPress(keys.DELETE, 500);
if(!has("safari") && !(has("chrome") && has("mac"))){
// they delete the space too?
robot.keyPress(keys.BACKSPACE, 500);
}
robot.sequence(d.getTestCallback(function(){
doh.is("hello. <i>how are you</i>?", normalize(editor1.get("value")));
}), 500);
return d;
}
}
]);
doh.register("selection", [
{
name: "mouseup but no click event",
timeout: 10000,
runTest: function(){
var cutButton = editor1.toolbar.getChildren()[3].domNode;
doh.t(domClass.contains(cutButton, "dijitButtonDisabled"), "Cut should be disabled " + cutButton.className);
var d = new doh.Deferred();
robot.mouseMoveAt(editor1.editNode, 500, 1);
robot.mousePress({left: true}, 500);
robot.mouseMoveAt(editor1.editNode, 500, 500, -10, 0); // move off of editNode
robot.mouseRelease({left: true}, 500);
robot.sequence(d.getTestCallback(function(){
doh.f(domClass.contains(cutButton, "dijitButtonDisabled"), "Cut should not be disabled " + cutButton.className);
}), 1000);
return d;
}
}
]);
doh.run();
});
</script>
</head>
</html>