Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
Added test for the mouseup event and spun the event handler mocking o…
Browse files Browse the repository at this point in the history
…ff into a spec helper
  • Loading branch information
Matthew Ephraim committed Oct 28, 2009
1 parent c9465db commit dcae57b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
4 changes: 4 additions & 0 deletions lib/raphael.draggable.js
Expand Up @@ -75,6 +75,10 @@
lastY = event.clientY;
}
});

element.mouseup(function() {
paper.draggable.clearCurrent();
});
};

DraggableExtension.prototype = {
Expand Down
36 changes: 11 additions & 25 deletions spec/raphael.draggable_spec.js
Expand Up @@ -73,31 +73,9 @@ Screw.Unit(function() {
var paper;
var rect;
before(function() {
// Override Raphael's mousedown so that mousedown can be triggered
Raphael.el.mousedown = function(arg) {
if (typeof arg == 'function') {
this.mousedownHandlers = this.mousedownHandlers || [];
this.mousedownHandlers.push(arg);
}
else {
for(var i = 0; i < this.mousedownHandlers.length; i++) {
this.mousedownHandlers[i].apply(this, arg);
}
}
};

// Override Raphael's mousemove so that mousemove can be triggered
Raphael.el.mousemove = function(arg) {
if (typeof arg == 'function') {
this.mouseMoveHandlers = this.mouseMoveHandlers || [];
this.mouseMoveHandlers.push(arg);
}
else {
for(var i = 0; i < this.mouseMoveHandlers.length; i++) {
this.mouseMoveHandlers[i].apply(this, arg);
}
}
};
overrideEventHandler('mousedown');
overrideEventHandler('mousemove');
overrideEventHandler('mouseup');

paper = Raphael(0, 0, 600, 600).draggable.enable();
rect = paper.rect(1,1,1,1).draggable.enable();
Expand Down Expand Up @@ -167,6 +145,14 @@ Screw.Unit(function() {
expect(translateY).to(equal, moveY - startY);
});
});

describe('mouseup', function() {
it("resets the current draggable", function() {
rect.mousedown([{}]);
rect.mouseup();
expect(paper.draggable.current()).to(equal, null);
});
})
});
});
});
Expand Down
16 changes: 16 additions & 0 deletions spec/spec_helper.js
@@ -0,0 +1,16 @@
// Overrides a built in Raphael event handler so that event handlers can
// be triggered during testing
function overrideEventHandler(handlerName) {
var handlerCollectionName = handlerName + "handlers";
Raphael.el[handlerName] = function(arg) {
if (typeof arg == 'function') {
this[handlerCollectionName] = this[handlerCollectionName] || [];
this[handlerCollectionName].push(arg);
}
else {
for(var i = 0; i < this[handlerCollectionName].length; i++) {
this[handlerCollectionName][i].apply(this, arg);
}
}
};
}
1 change: 1 addition & 0 deletions spec/suite.html
Expand Up @@ -12,6 +12,7 @@
<script src="../vendor/raphael.js"></script>
<script src="../lib/raphael.draggable.js"></script>
<script src="raphael.draggable_spec.js"></script>
<script src="spec_helper.js"></script>

<link rel="stylesheet" href="../vendor/screw.unit/screw.css">
</head>
Expand Down

0 comments on commit dcae57b

Please sign in to comment.