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
138 lines (128 loc) • 5.69 kB
HTML
<html>
<head>
<title>robot TextBox onInput Test</title>
<style>
@import "../../../../util/doh/robot/robot.css";
</style>
<!-- required: dojo.js -->
<script type="text/javascript" src="../../../../dojo/dojo.js"></script>
<script type="text/javascript">
require([
"doh/runner", "dojo/robotx",
"dojo/aspect", "dojo/json", "dojo/keys", "dojo/on",
"dojo/domReady!"
], function(doh, robot, aspect, json, keys, on){
robot.initRobot('../test_validate.html');
var widget, registry
doh.register("onInput", [
function setup(){
// get pointers to singletons loaded on test page
registry = robot.window.require("dijit/registry");
widget = registry.byId('q01');
},
{
name: "focus",
timeout: 2000,
runTest: function(){
var d = new doh.Deferred();
var handler = on.once(widget.focusNode, "focus",
function(){
setTimeout(d.getTestCallback(function(){
doh.t(true);
}), 0);
}
);
setTimeout(function(){
widget.focus();
}, 1); // return d before calling onfocus
return d;
}
},
{
name: "space",
timeout: 2000,
runTest: function(){
var d = new doh.Deferred();
var handler = aspect.after(widget, "onInput", d.getTestErrback(function(e){
var expEvt = expected.shift() || { type: null, charOrCode: null };
if(expEvt.type != e.type || expEvt.charOrCode !== e.charOrCode || expEvt.ctrlKey != e.ctrlKey || expEvt.shiftKey != e.shiftKey || expEvt.altKey != e.altKey){
handler.remove();
d.getTestCallback(function(){
doh.is(expEvt.type, e.type);
doh.is(expEvt.charOrCode, e.charOrCode);
doh.is(expEvt.ctrlKey, e.ctrlKey);
doh.is(expEvt.shiftKey, e.shiftKey);
doh.is(expEvt.altKey, e.altKey);
})(); // fail asap
}else if(expected.length == 0){
setTimeout(d.getTestCallback(function(){
handler.remove();
}), 100); // wait to see if an extra onInput event arrives
}
}), true);
var expected = [
{ type: "keypress", charOrCode: ' ', ctrlKey: false, shiftKey: false, altKey: false }
];
robot.keyPress(keys.SPACE, 100, {});
return d;
}
},
{
name: "test all",
timeout: 9000,
runTest: function(){
var d = new doh.Deferred();
var handler = aspect.after(widget, "onInput", d.getTestErrback(function(e){
var expEvt = expected.shift() || { type: null, charOrCode: null, ctrlKey: false, shiftKey: false, altKey: false };
if(expEvt.charOrCode == ' '/*the end sentinel*/ || (expEvt.type != e.type || expEvt.charOrCode !== e.charOrCode || expEvt.ctrlKey != e.ctrlKey || (expEvt.shiftKey != null && expEvt.shiftKey != e.shiftKey) || expEvt.altKey != e.altKey)){
handler.remove();
d.getTestCallback(function(){
var hint = "Expected: " +
json.stringify({ type: expEvt.type, charOrCode: expEvt.charOrCode, ctrlKey: expEvt.ctrlKey, shiftKey: expEvt.shiftKey, altKey: expEvt.altKey }) +
", Actual " +
json.stringify({ type: e.type, charOrCode: e.charOrCode, ctrlKey: e.ctrlKey, shiftKey: e.shiftKey, altKey: e.altKey });
doh.is(expEvt.type, e.type, hint);
doh.is(expEvt.charOrCode, e.charOrCode, hint);
doh.is(expEvt.ctrlKey, e.ctrlKey, hint);
doh.is(expEvt.altKey, e.altKey, hint);
doh.t(expEvt.shiftKey == null || expEvt.shiftKey == e.shiftKey, hint);
})();
}
}), true);
var expected = [
{ type: "keypress", charOrCode: 'a', ctrlKey: false, shiftKey: false, altKey: false },
{ type: "keypress", charOrCode: 'Z', ctrlKey: false, shiftKey: true, altKey: false },
{ type: "keypress", charOrCode: '0', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '_', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '-', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '+', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '=', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '/', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '*', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: '.', ctrlKey: false, shiftKey: null, altKey: false },
{ type: "keypress", charOrCode: 'Q', ctrlKey: false, shiftKey: true, altKey: false },
{ type: "keydown", charOrCode: 'C', ctrlKey: true, shiftKey: false, altKey: false },
{ type: "keydown", charOrCode: keys.RIGHT_ARROW, ctrlKey: false, shiftKey: false, altKey: false },
{ type: "keydown", charOrCode: keys.ENTER, ctrlKey: true, shiftKey: false, altKey: true },
{ type: "keydown", charOrCode: keys.TAB, ctrlKey: false, shiftKey: false, altKey: false },
{ type: "keypress", charOrCode: ' ', ctrlKey: false, shiftKey: false, altKey: false }
];
robot.typeKeys('aZ0_-+=/*.', 100, 2000);
robot.keyPress('q', 200, { shift: true });
robot.keyPress('c', 200, { ctrl: true });
robot.keyPress(keys.RIGHT_ARROW, 200, {});
robot.keyPress(keys.ENTER, 200, { ctrl: true, shift: false, alt: true });
robot.keyPress(keys.TAB, 200, {});
robot.keyPress(keys.TAB, 500, { shift: true });
robot.keyPress(keys.SPACE, 500, {});
return d;
}
}
]);
doh.run();
});
</script>
</head>
</html>