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

Commit 629fb37

Browse files
andimarekpetebacondarwin
authored andcommitted
feat(scenario): adds mousedown and mouseup event triggers to scenario
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.
1 parent 908821e commit 629fb37

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/ngScenario/Scenario.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function callerFile(offset) {
236236
(function(fn){
237237
var parentTrigger = fn.trigger;
238238
fn.trigger = function(type) {
239-
if (/(click|change|keydown|blur|input)/.test(type)) {
239+
if (/(click|change|keydown|blur|input|mousedown|mouseup)/.test(type)) {
240240
var processDefaults = [];
241241
this.each(function(index, node) {
242242
processDefaults.push(browserTrigger(node, type));

src/ngScenario/dsl.js

+18
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ angular.scenario.dsl('select', function() {
328328
* element(selector, label).count() get the number of elements that match selector
329329
* element(selector, label).click() clicks an element
330330
* element(selector, label).mouseover() mouseover an element
331+
* element(selector, label).mousedown() mousedown an element
332+
* element(selector, label).mouseup() mouseup an element
331333
* element(selector, label).query(fn) executes fn(selectedElements, done)
332334
* element(selector, label).{method}() gets the value (as defined by jQuery, ex. val)
333335
* element(selector, label).{method}(value) sets the value (as defined by jQuery, ex. val)
@@ -392,6 +394,22 @@ angular.scenario.dsl('element', function() {
392394
});
393395
};
394396

397+
chain.mousedown = function() {
398+
return this.addFutureAction("element '" + this.label + "' mousedown", function($window, $document, done) {
399+
var elements = $document.elements();
400+
elements.trigger('mousedown');
401+
done();
402+
});
403+
};
404+
405+
chain.mouseup = function() {
406+
return this.addFutureAction("element '" + this.label + "' mouseup", function($window, $document, done) {
407+
var elements = $document.elements();
408+
elements.trigger('mouseup');
409+
done();
410+
});
411+
};
412+
395413
chain.query = function(fn) {
396414
return this.addFutureAction('element ' + this.label + ' custom query', function($window, $document, done) {
397415
fn.call(this, $document.elements(), done);

test/ngScenario/dslSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,46 @@ describe("angular.scenario.dsl", function() {
367367
expect(mousedOver).toBe(true);
368368
});
369369

370+
it('should execute mousedown', function() {
371+
var mousedDown;
372+
doc.append('<div></div>');
373+
doc.find('div').mousedown(function() {
374+
mousedDown = true;
375+
});
376+
$root.dsl.element('div').mousedown();
377+
expect(mousedDown).toBe(true);
378+
});
379+
380+
it('should bubble up the mousedown event', function() {
381+
var mousedDown;
382+
doc.append('<div id="outer"><div id="inner"></div></div>');
383+
doc.find('#outer').mousedown(function() {
384+
mousedDown = true;
385+
});
386+
$root.dsl.element('#inner').mousedown();
387+
expect(mousedDown).toBe(true);
388+
});
389+
390+
it('should execute mouseup', function() {
391+
var mousedUp;
392+
doc.append('<div></div>');
393+
doc.find('div').mouseup(function() {
394+
mousedUp = true;
395+
});
396+
$root.dsl.element('div').mouseup();
397+
expect(mousedUp).toBe(true);
398+
});
399+
400+
it('should bubble up the mouseup event', function() {
401+
var mousedUp;
402+
doc.append('<div id="outer"><div id="inner"></div></div>');
403+
doc.find('#outer').mouseup(function() {
404+
mousedUp = true;
405+
});
406+
$root.dsl.element('#inner').mouseup();
407+
expect(mousedUp).toBe(true);
408+
});
409+
370410
it('should count matching elements', function() {
371411
doc.append('<span></span><span></span>');
372412
$root.dsl.element('span').count();

0 commit comments

Comments
 (0)