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

Commit

Permalink
feat(scenario): adds mousedown and mouseup event triggers to scenario
Browse files Browse the repository at this point in the history
Added mousedown and mouseup event triggers to scenadio dsl 'element' expression.
Added mousedown and mouseup to the custom jquery trigger method to generate real events.
  • Loading branch information
andimarek authored and petebacondarwin committed May 14, 2013
1 parent 908821e commit 629fb37
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ngScenario/Scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function callerFile(offset) {
(function(fn){
var parentTrigger = fn.trigger;
fn.trigger = function(type) {
if (/(click|change|keydown|blur|input)/.test(type)) {
if (/(click|change|keydown|blur|input|mousedown|mouseup)/.test(type)) {
var processDefaults = [];
this.each(function(index, node) {
processDefaults.push(browserTrigger(node, type));
Expand Down
18 changes: 18 additions & 0 deletions src/ngScenario/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ angular.scenario.dsl('select', function() {
* element(selector, label).count() get the number of elements that match selector
* element(selector, label).click() clicks an element
* element(selector, label).mouseover() mouseover an element
* element(selector, label).mousedown() mousedown an element
* element(selector, label).mouseup() mouseup an element
* element(selector, label).query(fn) executes fn(selectedElements, done)
* element(selector, label).{method}() gets the value (as defined by jQuery, ex. val)
* element(selector, label).{method}(value) sets the value (as defined by jQuery, ex. val)
Expand Down Expand Up @@ -392,6 +394,22 @@ angular.scenario.dsl('element', function() {
});
};

chain.mousedown = function() {
return this.addFutureAction("element '" + this.label + "' mousedown", function($window, $document, done) {
var elements = $document.elements();
elements.trigger('mousedown');
done();
});
};

chain.mouseup = function() {
return this.addFutureAction("element '" + this.label + "' mouseup", function($window, $document, done) {
var elements = $document.elements();
elements.trigger('mouseup');
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
40 changes: 40 additions & 0 deletions test/ngScenario/dslSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,46 @@ describe("angular.scenario.dsl", function() {
expect(mousedOver).toBe(true);
});

it('should execute mousedown', function() {
var mousedDown;
doc.append('<div></div>');
doc.find('div').mousedown(function() {
mousedDown = true;
});
$root.dsl.element('div').mousedown();
expect(mousedDown).toBe(true);
});

it('should bubble up the mousedown event', function() {
var mousedDown;
doc.append('<div id="outer"><div id="inner"></div></div>');
doc.find('#outer').mousedown(function() {
mousedDown = true;
});
$root.dsl.element('#inner').mousedown();
expect(mousedDown).toBe(true);
});

it('should execute mouseup', function() {
var mousedUp;
doc.append('<div></div>');
doc.find('div').mouseup(function() {
mousedUp = true;
});
$root.dsl.element('div').mouseup();
expect(mousedUp).toBe(true);
});

it('should bubble up the mouseup event', function() {
var mousedUp;
doc.append('<div id="outer"><div id="inner"></div></div>');
doc.find('#outer').mouseup(function() {
mousedUp = true;
});
$root.dsl.element('#inner').mouseup();
expect(mousedUp).toBe(true);
});

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

0 comments on commit 629fb37

Please sign in to comment.