mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-22 01:10:23 +00:00
fix(scenario): do not navigate if click event was cancelled
This is jQuery incompatible hack.
But we were doing monkey patching there anyway...
`$(...).trigger('click')` returns an array of return values, so that scenario
runner knows, whether the event default action was cancelled.
Without this fix, scenario runner was doing navigation even if JS code called
`event.preventDefault()`.
Note, this does not work in FF6
This commit is contained in:
parent
8fa79066e2
commit
66dec77555
3 changed files with 24 additions and 4 deletions
|
|
@ -298,9 +298,14 @@ function browserTrigger(element, type) {
|
|||
var parentTrigger = fn.trigger;
|
||||
fn.trigger = function(type) {
|
||||
if (/(click|change|keydown)/.test(type)) {
|
||||
return this.each(function(index, node) {
|
||||
browserTrigger(node, type);
|
||||
var processDefaults = [];
|
||||
this.each(function(index, node) {
|
||||
processDefaults.push(browserTrigger(node, type));
|
||||
});
|
||||
|
||||
// this is not compatible with jQuery - we return an array of returned values,
|
||||
// so that scenario runner know whether JS code has preventDefault() of the event or not...
|
||||
return processDefaults;
|
||||
}
|
||||
return parentTrigger.apply(this, arguments);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -323,8 +323,9 @@ angular.scenario.dsl('element', function() {
|
|||
return this.addFutureAction("element '" + this.label + "' click", function($window, $document, done) {
|
||||
var elements = $document.elements();
|
||||
var href = elements.attr('href');
|
||||
elements.trigger('click');
|
||||
if (href && elements[0].nodeName.toUpperCase() === 'A') {
|
||||
var eventProcessDefault = elements.trigger('click')[0];
|
||||
|
||||
if (href && elements[0].nodeName.toUpperCase() === 'A' && eventProcessDefault) {
|
||||
this.application.navigateTo(href, function() {
|
||||
done();
|
||||
}, done);
|
||||
|
|
|
|||
|
|
@ -250,6 +250,20 @@ describe("angular.scenario.dsl", function() {
|
|||
expect($window.location).toMatch(/#foo$/);
|
||||
});
|
||||
|
||||
it('should not navigate if click event was cancelled', function() {
|
||||
var initLocation = $window.location,
|
||||
elm = jqLite('<a href="#foo"></a>');
|
||||
|
||||
doc.append(elm);
|
||||
elm.bind('click', function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
$root.dsl.element('a').click();
|
||||
expect($window.location).toBe(initLocation);
|
||||
dealoc(elm);
|
||||
});
|
||||
|
||||
it('should count matching elements', function() {
|
||||
doc.append('<span></span><span></span>');
|
||||
$root.dsl.element('span').count();
|
||||
|
|
|
|||
Loading…
Reference in a new issue