Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat(scenario): add dblclick method to the ngScenario dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodelgallego authored and mhevery committed Sep 6, 2012
1 parent 9473780 commit 8cb9c99
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ngScenario/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@ angular.scenario.dsl('element', function() {
});
};

chain.dblclick = function() {
return this.addFutureAction("element '" + this.label + "' dblclick", function($window, $document, done) {
var elements = $document.elements();
var href = elements.attr('href');
var eventProcessDefault = elements.trigger('dblclick')[0];

if (href && elements[0].nodeName.toUpperCase() === 'A' && eventProcessDefault) {
this.application.navigateTo(href, function() {
done();
}, done);
} else {
done();
}
});
};

chain.query = function(fn) {
return this.addFutureAction('element ' + this.label + ' custom query', function($window, $document, done) {
fn.call(this, $document.elements(), done);
Expand Down
32 changes: 32 additions & 0 deletions test/ngScenario/dslSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,38 @@ describe("angular.scenario.dsl", function() {
dealoc(elm);
});

it('should execute dblclick', function() {
var clicked;
// Hash is important, otherwise we actually
// go to a different page and break the runner
doc.append('<a href="#"></a>');
doc.find('a').dblclick(function() {
clicked = true;
});
$root.dsl.element('a').dblclick();
});

it('should navigate page if dblclick on anchor', function() {
expect($window.location).not.toEqual('#foo');
doc.append('<a href="#foo"></a>');
$root.dsl.element('a').dblclick();
expect($window.location).toMatch(/#foo$/);
});

it('should not navigate if dblclick event was cancelled', function() {
var initLocation = $window.location,
elm = jqLite('<a href="#foo"></a>');

doc.append(elm);
elm.bind('dblclick', function(event) {
event.preventDefault();
});

$root.dsl.element('a').dblclick();
expect($window.location).toBe(initLocation);
dealoc(elm);
});

it('should count matching elements', function() {
doc.append('<span></span><span></span>');
$root.dsl.element('span').count();
Expand Down

0 comments on commit 8cb9c99

Please sign in to comment.