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

Commit 8cb9c99

Browse files
pedrodelgallegomhevery
authored andcommitted
feat(scenario): add dblclick method to the ngScenario dsl
1 parent 9473780 commit 8cb9c99

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/ngScenario/dsl.js

+16
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,22 @@ angular.scenario.dsl('element', function() {
365365
});
366366
};
367367

368+
chain.dblclick = function() {
369+
return this.addFutureAction("element '" + this.label + "' dblclick", function($window, $document, done) {
370+
var elements = $document.elements();
371+
var href = elements.attr('href');
372+
var eventProcessDefault = elements.trigger('dblclick')[0];
373+
374+
if (href && elements[0].nodeName.toUpperCase() === 'A' && eventProcessDefault) {
375+
this.application.navigateTo(href, function() {
376+
done();
377+
}, done);
378+
} else {
379+
done();
380+
}
381+
});
382+
};
383+
368384
chain.query = function(fn) {
369385
return this.addFutureAction('element ' + this.label + ' custom query', function($window, $document, done) {
370386
fn.call(this, $document.elements(), done);

test/ngScenario/dslSpec.js

+32
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,38 @@ describe("angular.scenario.dsl", function() {
280280
dealoc(elm);
281281
});
282282

283+
it('should execute dblclick', function() {
284+
var clicked;
285+
// Hash is important, otherwise we actually
286+
// go to a different page and break the runner
287+
doc.append('<a href="#"></a>');
288+
doc.find('a').dblclick(function() {
289+
clicked = true;
290+
});
291+
$root.dsl.element('a').dblclick();
292+
});
293+
294+
it('should navigate page if dblclick on anchor', function() {
295+
expect($window.location).not.toEqual('#foo');
296+
doc.append('<a href="#foo"></a>');
297+
$root.dsl.element('a').dblclick();
298+
expect($window.location).toMatch(/#foo$/);
299+
});
300+
301+
it('should not navigate if dblclick event was cancelled', function() {
302+
var initLocation = $window.location,
303+
elm = jqLite('<a href="#foo"></a>');
304+
305+
doc.append(elm);
306+
elm.bind('dblclick', function(event) {
307+
event.preventDefault();
308+
});
309+
310+
$root.dsl.element('a').dblclick();
311+
expect($window.location).toBe(initLocation);
312+
dealoc(elm);
313+
});
314+
283315
it('should count matching elements', function() {
284316
doc.append('<span></span><span></span>');
285317
$root.dsl.element('span').count();

0 commit comments

Comments
 (0)