mirror of
https://github.com/konvajs/konva.git
synced 2025-11-18 17:17:49 +08:00
refactored attr event change logic a bit. added delete operator in a couple places to fix memory leaks. added better event unit tests.
This commit is contained in:
@@ -6,7 +6,7 @@ function test(condition, message) {
|
||||
throw new Error(message);
|
||||
}
|
||||
numTests++;
|
||||
|
||||
|
||||
testCounter.innerHTML = numTests;
|
||||
}
|
||||
function log(message) {
|
||||
@@ -16,10 +16,7 @@ function log(message) {
|
||||
* Test constructor
|
||||
*/
|
||||
function Test() {
|
||||
//this.testOnly = 'EVENTS - mousedown mouseup mouseover mouseout mousemove click dblclick / touchstart touchend touchmove tap dbltap';
|
||||
this.testOnly = '';
|
||||
this.counter = 0;
|
||||
|
||||
testCounter = document.createElement('div');
|
||||
testCounter.id = 'testCounter';
|
||||
document.getElementsByTagName('body')[0].appendChild(testCounter);
|
||||
@@ -47,8 +44,22 @@ Test.prototype = {
|
||||
run: function() {
|
||||
var tests = this.tests;
|
||||
|
||||
var testOnlySpecial = false;
|
||||
|
||||
/*
|
||||
* if a test key has a star in front of it, then
|
||||
* only run special tests. This lets us easily run
|
||||
* specific tests without running all of them
|
||||
*/
|
||||
for(var key in tests) {
|
||||
if(!this.testOnly || (this.testOnly && this.testOnly == key)) {
|
||||
if(key.charAt(0) === '*') {
|
||||
testOnlySpecial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(var key in tests) {
|
||||
if(!testOnlySpecial || key.charAt(0) === '*') {
|
||||
var obj = this.addTestContainer(key);
|
||||
this.counter++;
|
||||
console.log(this.counter + ") " + key);
|
||||
|
||||
@@ -2925,11 +2925,11 @@ Test.prototype.tests = {
|
||||
var triggered = false;
|
||||
|
||||
rect.on('widthChange', function() {
|
||||
triggered = true;
|
||||
triggered = true;
|
||||
});
|
||||
|
||||
rect.setSize(210);
|
||||
|
||||
|
||||
test(triggered, 'width change event not triggered');
|
||||
},
|
||||
'NODE - test setting shadow offset': function(containerId) {
|
||||
@@ -3614,6 +3614,64 @@ Test.prototype.tests = {
|
||||
|
||||
test(foo === 'bar', 'foo should equal bar');
|
||||
},
|
||||
'EVENTS - add remove event': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle'
|
||||
});
|
||||
|
||||
/*
|
||||
* test regular on and off
|
||||
*/
|
||||
test(circle.eventListeners['click'] === undefined, 'circle should have no click listeners');
|
||||
|
||||
circle.on('click', function() {
|
||||
});
|
||||
test(circle.eventListeners['click'].length === 1, 'circle should have 1 click listener');
|
||||
|
||||
circle.on('click', function() {
|
||||
});
|
||||
test(circle.eventListeners['click'].length === 2, 'circle should have 2 click listeners');
|
||||
|
||||
circle.off('click');
|
||||
test(circle.eventListeners['click'] === undefined, 'circle should have no click listeners');
|
||||
|
||||
/*
|
||||
* test name spacing
|
||||
*/
|
||||
circle.on('click.foo', function() {
|
||||
});
|
||||
test(circle.eventListeners['click'].length === 1, 'circle should have 1 click listener');
|
||||
|
||||
circle.on('click.foo', function() {
|
||||
});
|
||||
test(circle.eventListeners['click'].length === 2, 'circle should have 2 click listeners');
|
||||
circle.on('click.bar', function() {
|
||||
});
|
||||
test(circle.eventListeners['click'].length === 3, 'circle should have 3 click listeners');
|
||||
|
||||
|
||||
circle.off('click.foo');
|
||||
test(circle.eventListeners['click'].length === 1, 'circle should have 1 click listener');
|
||||
|
||||
circle.off('click.bar');
|
||||
test(circle.eventListeners['click'] === undefined, 'circle should have no click listeners');
|
||||
|
||||
stage.add(layer);
|
||||
layer.add(circle);
|
||||
layer.draw();
|
||||
},
|
||||
'NODE - simulate event bubble': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
|
||||
Reference in New Issue
Block a user