From 8cb9c99ec064fd95567118d29bfa4a19b8613ab3 Mon Sep 17 00:00:00 2001 From: Pedro Del Gallego Date: Wed, 29 Aug 2012 15:39:34 +0200 Subject: [PATCH] feat(scenario): add dblclick method to the ngScenario dsl --- src/ngScenario/dsl.js | 16 ++++++++++++++++ test/ngScenario/dslSpec.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/ngScenario/dsl.js b/src/ngScenario/dsl.js index 7939735d0f1f..f660c3181993 100644 --- a/src/ngScenario/dsl.js +++ b/src/ngScenario/dsl.js @@ -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); diff --git a/test/ngScenario/dslSpec.js b/test/ngScenario/dslSpec.js index eef8c907c5f9..9c7893fdf3c2 100644 --- a/test/ngScenario/dslSpec.js +++ b/test/ngScenario/dslSpec.js @@ -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(''); + 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(''); + $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(''); + + 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(''); $root.dsl.element('span').count();