mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 19:07:59 +08:00
fixed up functional tests
This commit is contained in:
13
src/Stage.js
13
src/Stage.js
@@ -416,7 +416,9 @@
|
|||||||
|
|
||||||
// always call preventDefault for desktop events because some browsers
|
// always call preventDefault for desktop events because some browsers
|
||||||
// try to drag and drop the canvas element
|
// try to drag and drop the canvas element
|
||||||
|
if (evt.preventDefault) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_mousedown: function(evt) {
|
_mousedown: function(evt) {
|
||||||
this._setPointerPosition(evt);
|
this._setPointerPosition(evt);
|
||||||
@@ -430,7 +432,9 @@
|
|||||||
|
|
||||||
// always call preventDefault for desktop events because some browsers
|
// always call preventDefault for desktop events because some browsers
|
||||||
// try to drag and drop the canvas element
|
// try to drag and drop the canvas element
|
||||||
|
if (evt.preventDefault) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_mouseup: function(evt) {
|
_mouseup: function(evt) {
|
||||||
this._setPointerPosition(evt);
|
this._setPointerPosition(evt);
|
||||||
@@ -447,6 +451,7 @@
|
|||||||
* if dragging and dropping, or if click doesn't map to
|
* if dragging and dropping, or if click doesn't map to
|
||||||
* the correct shape, don't fire click or dbl click event
|
* the correct shape, don't fire click or dbl click event
|
||||||
*/
|
*/
|
||||||
|
console.log(go.isDragging());
|
||||||
if(!go.isDragging() && shape._id === this.clickStartShape._id) {
|
if(!go.isDragging() && shape._id === this.clickStartShape._id) {
|
||||||
shape._fireAndBubble(CLICK, evt);
|
shape._fireAndBubble(CLICK, evt);
|
||||||
|
|
||||||
@@ -464,7 +469,9 @@
|
|||||||
|
|
||||||
// always call preventDefault for desktop events because some browsers
|
// always call preventDefault for desktop events because some browsers
|
||||||
// try to drag and drop the canvas element
|
// try to drag and drop the canvas element
|
||||||
|
if (evt.preventDefault) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_touchstart: function(evt) {
|
_touchstart: function(evt) {
|
||||||
this._setPointerPosition(evt);
|
this._setPointerPosition(evt);
|
||||||
@@ -477,7 +484,7 @@
|
|||||||
shape._fireAndBubble(TOUCHSTART, evt);
|
shape._fireAndBubble(TOUCHSTART, evt);
|
||||||
|
|
||||||
// only call preventDefault if the shape is listening for events
|
// only call preventDefault if the shape is listening for events
|
||||||
if (shape.isListening()) {
|
if (shape.isListening() && evt.preventDefault) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -512,7 +519,7 @@
|
|||||||
this.tapStart = false;
|
this.tapStart = false;
|
||||||
|
|
||||||
// only call preventDefault if the shape is listening for events
|
// only call preventDefault if the shape is listening for events
|
||||||
if (shape.isListening()) {
|
if (shape.isListening() && evt.preventDefault) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -530,7 +537,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only call preventDefault if the shape is listening for events
|
// only call preventDefault if the shape is listening for events
|
||||||
if (shape.isListening()) {
|
if (shape.isListening() && evt.preventDefault) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -350,6 +350,56 @@ Test.Modules.DD = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
'*click should not occur after drag and drop': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
|
var circle = new Kinetic.Circle({
|
||||||
|
x: 40,
|
||||||
|
y: 40,
|
||||||
|
radius: 20,
|
||||||
|
strokeWidth: 4,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var top = stage.content.getBoundingClientRect().top,
|
||||||
|
clicked = false;
|
||||||
|
|
||||||
|
circle.on('click', function() {
|
||||||
|
console.log('click');
|
||||||
|
clicked = true;
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
stage._mousedown({
|
||||||
|
clientX: 40,
|
||||||
|
clientY: 40 + top
|
||||||
|
});
|
||||||
|
|
||||||
|
stage._mousemove({
|
||||||
|
clientX: 100,
|
||||||
|
clientY: 100 + top
|
||||||
|
});
|
||||||
|
|
||||||
|
Kinetic.DD._endDragBefore();
|
||||||
|
stage._mouseup({
|
||||||
|
clientX: 100,
|
||||||
|
clientY: 100 + top
|
||||||
|
});
|
||||||
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
||||||
|
|
||||||
|
test(!clicked, 'click event should not have been fired');*/
|
||||||
|
|
||||||
},
|
},
|
||||||
'cancel drag and drop by setting draggable to false': function(containerId) {
|
'cancel drag and drop by setting draggable to false': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
@@ -504,39 +554,32 @@ Test.Modules.EVENT = {
|
|||||||
fill: 'red'
|
fill: 'red'
|
||||||
});
|
});
|
||||||
|
|
||||||
var eventNodes = [];
|
var events = [];
|
||||||
var savedEvt;
|
|
||||||
var order = [];
|
|
||||||
|
|
||||||
layer.on('draw', function(evt) {
|
layer.on('draw', function(evt) {
|
||||||
savedEvt = evt;
|
events.push('layer-draw');
|
||||||
eventNodes.push(this.getType());
|
|
||||||
order.push('layer draw');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
stage.on('draw', function(evt) {
|
stage.on('draw', function(evt) {
|
||||||
eventNodes.push(this.getType());
|
events.push('stage-draw');
|
||||||
order.push('stage draw');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
layer.on('beforeDraw', function(evt) {
|
layer.on('beforeDraw', function(evt) {
|
||||||
order.push('layer beforeDraw');
|
events.push('layer-beforeDraw');
|
||||||
});
|
});
|
||||||
|
|
||||||
stage.on('beforeDraw', function(evt) {
|
stage.on('beforeDraw', function(evt) {
|
||||||
order.push('stage beforeDraw');
|
events.push('stage-beforeDraw');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
layer.add(circle);
|
layer.add(circle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
// Note: draw events no longer bubble
|
console.log(events.toString())
|
||||||
//test(eventNodes.toString() === 'Layer,Stage', 'layer draw event should have fired followed by stage draw event');
|
|
||||||
|
|
||||||
test(savedEvt.node.getType() === 'Layer', 'event object should contain a node property which is Layer');
|
test(events.toString() === 'layer-beforeDraw,stage-beforeDraw,layer-draw,stage-draw', 'draw event order is incorrect');
|
||||||
|
|
||||||
//test(order.toString() === 'layer beforeDraw,stage beforeDraw,layer draw,stage draw', 'order should be: layer beforeDraw,stage beforeDraw,layer draw,stage draw');
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'click mapping': function(containerId) {
|
'click mapping': function(containerId) {
|
||||||
|
Reference in New Issue
Block a user