mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
added new content events to clean up stage events. added first mocha functional test
This commit is contained in:
133
test/functional/Events-test.js
Normal file
133
test/functional/Events-test.js
Normal file
@@ -0,0 +1,133 @@
|
||||
suite('Events', function() {
|
||||
test('stage content mouse events', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 100,
|
||||
y: 100,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle'
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
var circleMousedown =
|
||||
circleMouseup =
|
||||
stageContentMousedown =
|
||||
stageContentMouseup =
|
||||
stageContentMousemove =
|
||||
stageContentMouseout =
|
||||
stageContentMouseover =
|
||||
stageContentClick =
|
||||
stageContentDblClick =
|
||||
0;
|
||||
|
||||
var top = stage.content.getBoundingClientRect().top;
|
||||
|
||||
|
||||
circle.on('mousedown', function() {
|
||||
circleMousedown++;
|
||||
});
|
||||
|
||||
circle.on('mouseup', function() {
|
||||
circleMouseup++;
|
||||
});
|
||||
|
||||
stage.on('contentMousedown', function() {
|
||||
stageContentMousedown++;
|
||||
});
|
||||
|
||||
stage.on('contentMouseup', function() {
|
||||
stageContentMouseup++;
|
||||
});
|
||||
|
||||
stage.on('contentMousemove', function() {
|
||||
stageContentMousemove++;
|
||||
});
|
||||
|
||||
stage.on('contentMouseout', function() {
|
||||
stageContentMouseout++;
|
||||
});
|
||||
|
||||
stage.on('contentMouseover', function() {
|
||||
stageContentMouseover++;
|
||||
});
|
||||
|
||||
stage.on('contentClick', function() {
|
||||
//console.log('click');
|
||||
stageContentClick++;
|
||||
});
|
||||
|
||||
stage.on('contentDblclick', function() {
|
||||
//console.log('dbl click');
|
||||
stageContentDblClick++;
|
||||
});
|
||||
|
||||
stage._mousedown({
|
||||
clientX: 100,
|
||||
clientY: 100 + top
|
||||
});
|
||||
|
||||
stage._mouseup({
|
||||
clientX: 100,
|
||||
clientY: 100 + top
|
||||
});
|
||||
|
||||
assert.equal(circleMousedown, 1);
|
||||
assert.equal(circleMouseup, 1);
|
||||
assert.equal(stageContentMousedown, 1);
|
||||
assert.equal(stageContentMouseup, 1);
|
||||
assert.equal(stageContentClick, 1);
|
||||
|
||||
stage._mousedown({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
stage._mouseup({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
|
||||
assert.equal(stageContentMousedown, 2);
|
||||
assert.equal(stageContentMouseup, 2);
|
||||
|
||||
// trigger double click
|
||||
stage._mousedown({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
stage._mouseup({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
|
||||
assert.equal(stageContentMousedown, 3);
|
||||
assert.equal(stageContentMouseup, 3);
|
||||
//assert.equal(stageContentDblClick, 1);
|
||||
|
||||
stage._mousemove({
|
||||
clientX: 200,
|
||||
clientY: 1 + top
|
||||
});
|
||||
|
||||
assert.equal(stageContentMousemove, 1);
|
||||
|
||||
stage._mouseout({
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
});
|
||||
|
||||
assert.equal(stageContentMouseout, 1);
|
||||
|
||||
stage._mouseover({
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
});
|
||||
|
||||
assert.equal(stageContentMouseover, 1);
|
||||
});
|
||||
});
|
@@ -37,6 +37,8 @@
|
||||
<script src="assets/tiger.js"></script>
|
||||
<script src="assets/worldMap.js"></script>
|
||||
|
||||
<!--=============== unit tests ================-->
|
||||
|
||||
<!-- core -->
|
||||
<script src="unit/Global-test.js"></script>
|
||||
<script src="unit/Util-test.js"></script>
|
||||
@@ -72,6 +74,10 @@
|
||||
<script src="unit/plugins/Path-test.js"></script>
|
||||
<script src="unit/plugins/TextPath-test.js"></script>
|
||||
|
||||
<!--=============== functional tests ================-->
|
||||
|
||||
<script src="functional/Events-test.js"></script>
|
||||
|
||||
<script>
|
||||
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
|
||||
else { mocha.run(); }
|
||||
|
Reference in New Issue
Block a user