UNPKG

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

179 lines (161 loc) 6.95 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>robot TextBox onInput and _processInput 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; function nop(){} 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(function(){ d.resolve(); }, 0); }); setTimeout(function(){ widget.focus(); }, 1); // return d before calling focus return d; } }, { name: "space", timeout: 2000, runTest: function(){ var d = new doh.Deferred(); 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){ widget.onInput = nop; 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(){ widget.onInput = nop; }), 100); // wait to see if an extra onInput event arrives } }); 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(); 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)){ widget.onInput = nop; 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); })(); } }); 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; } }, { name: "advanced", timeout: 2000, runTest: function(){ var d = new doh.Deferred(); // note: using robot.sequence() to give time for final SPACE key in above test to process robot.sequence(d.getTestErrback(function(){ widget.set("value", ""); widget.focus(); // Test that when onInput is overridden and returns false, the character is canceled. // "a" should be ignored and only "b" will appear in the <input> and to // trigger the call to _processInput() widget.onInput = function(evt1){ if(evt1.charOrCode == "a"){ return false; } }; // Test that _processInput(evt) is called with the event object after the character has // appeared in the <input> var handle = aspect.after(widget, "_processInput", d.getTestCallback(function(res, args){ var evt2 = args[0]; handle.remove(); doh.is("b", evt2.charOrCode, "charOrCode"); doh.is("b", widget.focusNode.value, "widget.focusNode.value"); })); }), 100); robot.keyPress("a", 100, {}); robot.sequence(d.getTestErrback(function(){ doh.is("", widget.focusNode.value, "widget.focusNode.value"); }), 100); robot.keyPress("b", 100, {}); return d; } } ]); doh.run(); }); </script> </head> </html>