diff options
| author | Misko Hevery | 2010-10-19 15:34:58 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-10-19 15:56:53 -0700 |
| commit | 01c7abab35dbdee711c54875424b388f8631a3c0 (patch) | |
| tree | 00a4adee508a9e854881f7ecea5e779fb6d48a80 /src/scenario | |
| parent | e7e894a2e36e042be6d62af56b0f3126f4e4fc77 (diff) | |
| download | angular.js-01c7abab35dbdee711c54875424b388f8631a3c0.tar.bz2 | |
Fix browser triggering in scenario to always do native events.
- Also fixed angular.suffix for scenarios
- refactored click() to browserTrigger()
- Fixed Rakefile with CSS and jQuery
Diffstat (limited to 'src/scenario')
| -rw-r--r-- | src/scenario/Scenario.js | 49 | ||||
| -rw-r--r-- | src/scenario/SpecRunner.js | 34 | ||||
| -rw-r--r-- | src/scenario/angular.prefix | 1 | ||||
| -rw-r--r-- | src/scenario/angular.suffix | 13 | ||||
| -rw-r--r-- | src/scenario/bootstrap.js | 8 |
5 files changed, 64 insertions, 41 deletions
diff --git a/src/scenario/Scenario.js b/src/scenario/Scenario.js index e93f6b2e..ba206632 100644 --- a/src/scenario/Scenario.js +++ b/src/scenario/Scenario.js @@ -1,5 +1,5 @@ /** - * Setup file for the Scenario. + * Setup file for the Scenario. * Must be first in the compilation/bootstrap list. */ @@ -19,7 +19,7 @@ angular.scenario.ui = {}; * functions. * * @param {String} The name of the statement - * @param {Function} Factory function(application), return a function for + * @param {Function} Factory function(application), return a function for * the statement. */ angular.scenario.dsl = function(name, fn) { @@ -50,7 +50,7 @@ angular.scenario.dsl = function(name, fn) { /** * Defines a new matcher for use with the expects() statement. The value - * this.actual (like in Jasmine) is available in your matcher to compare + * this.actual (like in Jasmine) is available in your matcher to compare * against. Your function should return a boolean. The future is automatically * created for you. * @@ -83,7 +83,7 @@ angular.scenario.matcher = function(name, fn) { * * @param {Array} list to iterate over * @param {Function} Callback function(value, continueFunction) - * @param {Function} Callback function(error, result) called when iteration + * @param {Function} Callback function(error, result) called when iteration * finishes or an error occurs. */ function asyncForEach(list, iterator, done) { @@ -101,3 +101,44 @@ function asyncForEach(list, iterator, done) { } loop(); } + + +function browserTrigger(element, type) { + if (!element.nodeName) element = element[0]; + if (!type) { + type = { + 'text': 'change', + 'textarea': 'change', + 'hidden': 'change', + 'password': 'change', + 'button': 'click', + 'submit': 'click', + 'reset': 'click', + 'image': 'click', + 'checkbox': 'click', + 'radio': 'click', + 'select-one': 'change', + 'select-multiple': 'change' + }[element.type] || 'click'; + } + if (lowercase(nodeName(element)) == 'option') { + element.parentNode.value = element.value; + element = element.parentNode; + type = 'change'; + } + if (msie) { + element.fireEvent('on' + type); + } else { + var evnt = document.createEvent('MouseEvents'); + evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, element); + element.dispatchEvent(evnt); + } +} + +_jQuery.fn.trigger = function(type) { + return this.each(function(index, node) { + browserTrigger(node, type); + }); +}; + + diff --git a/src/scenario/SpecRunner.js b/src/scenario/SpecRunner.js index d6cbdcdc..26fa9b91 100644 --- a/src/scenario/SpecRunner.js +++ b/src/scenario/SpecRunner.js @@ -21,7 +21,7 @@ angular.scenario.SpecRunner = function() { */ angular.scenario.SpecRunner.prototype.run = function(ui, spec, specDone) { var specUI = ui.addSpec(spec); - + try { spec.fn.call(this); } catch (e) { @@ -29,9 +29,9 @@ angular.scenario.SpecRunner.prototype.run = function(ui, spec, specDone) { specDone(); return; } - + asyncForEach( - this.futures, + this.futures, function(future, futureDone) { var stepUI = specUI.addStep(future.name); try { @@ -43,10 +43,10 @@ angular.scenario.SpecRunner.prototype.run = function(ui, spec, specDone) { stepUI.error(e); throw e; } - }, + }, function(e) { - specUI.finish(e); - specDone(); + specUI.finish(e); + specDone(); } ); }; @@ -89,29 +89,9 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior) }; } - result.trigger = function(type) { - result.each(function(index, node) { - var element = $window.angular.element(node); - //TODO(esprehn): HACK!!! Something is broken in angular event dispatching - // and if the real jQuery is used we need to set the attribtue after too - if (angular.isDefined(element.selector)) { - if (type === 'click' && node.nodeName.toLowerCase() === 'input') { - element.attr('checked', !element.attr('checked')); - } - } - //TODO(esprehn): HACK!! See above comment. - element.trigger(type); - if (angular.isDefined(element.selector)) { - if (type === 'click' && node.nodeName.toLowerCase() === 'input') { - element.attr('checked', !element.attr('checked')); - } - } - }); - }; - return result; }); - + try { behavior.call(this, $window, $document, done); } catch(e) { diff --git a/src/scenario/angular.prefix b/src/scenario/angular.prefix index a1b4e151..d6660d61 100644 --- a/src/scenario/angular.prefix +++ b/src/scenario/angular.prefix @@ -22,3 +22,4 @@ * THE SOFTWARE. */ (function(window, document, previousOnLoad){ + var _jQuery = window.jQuery.noConflict(true);
\ No newline at end of file diff --git a/src/scenario/angular.suffix b/src/scenario/angular.suffix index 53d99dd2..c38f0ab5 100644 --- a/src/scenario/angular.suffix +++ b/src/scenario/angular.suffix @@ -4,22 +4,19 @@ try { if (previousOnLoad) previousOnLoad(); } catch(e) {} - jQuery(document.body).append( + _jQuery(document.body).append( '<div id="runner"></div>' + '<div id="frame"></div>' ); - var frame = jQuery('#frame'); - var runner = jQuery('#runner'); + var frame = _jQuery('#frame'); + var runner = _jQuery('#runner'); var application = new angular.scenario.Application(frame); var ui = new angular.scenario.ui.Html(runner); - $scenario.run(ui, application, function(error) { + $scenario.run(ui, application, angular.scenario.SpecRunner, function(error) { frame.remove(); if (error) { if (window.console) { - console.log(error); - if (error.stack) { - console.log(error.stack); - } + console.log(error.stack || error); } else { // Do something for IE alert(error); diff --git a/src/scenario/bootstrap.js b/src/scenario/bootstrap.js index 014c636d..4661bfb2 100644 --- a/src/scenario/bootstrap.js +++ b/src/scenario/bootstrap.js @@ -10,7 +10,7 @@ } } })(); - + function addScript(path) { document.write('<script type="text/javascript" src="' + prefix + path + '"></script>'); } @@ -46,6 +46,11 @@ addCSS("../../css/angular-scenario.css"); addScript("../../lib/jquery/jquery-1.4.2.js"); + document.write( + '<script type="text/javascript">' + + 'var _jQuery = jQuery.noConflict(true);' + + '</script>' + ); addScript("../angular-bootstrap.js"); addScript("Scenario.js"); @@ -61,7 +66,6 @@ // Create the runner (which also sets up the global API) document.write( '<script type="text/javascript">' + - 'var _jQuery = jQuery.noConflict(true);' + 'var $scenario = new angular.scenario.Runner(window);' + '</script>' ); |
