mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 04:14:52 +08:00
added some tween unit tests. all tween methods now return this
This commit is contained in:
14
src/Tween.js
14
src/Tween.js
@@ -71,7 +71,7 @@
|
||||
|
||||
for (key in config) {
|
||||
if (blacklist[key] === undefined) {
|
||||
this._addAttrs(key, config[key]);
|
||||
this._addAttr(key, config[key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
Kinetic.Tween.tweens = {};
|
||||
|
||||
Kinetic.Tween.prototype = {
|
||||
_addAttrs: function(key, end) {
|
||||
_addAttr: function(key, end) {
|
||||
var node = this.node,
|
||||
nodeId = node._id,
|
||||
start, diff, tweenId, n, len, startVal, endVal;
|
||||
@@ -95,7 +95,7 @@
|
||||
}
|
||||
|
||||
// add to tween map
|
||||
start = node['get' + Kinetic.Util._capitalize(key)]();
|
||||
start = node.getAttr(key);
|
||||
|
||||
if (Kinetic.Util._isArray(end)) {
|
||||
end = Kinetic.Util._getPoints(end);
|
||||
@@ -147,7 +147,7 @@
|
||||
newVal = start + (diff * i);
|
||||
}
|
||||
|
||||
node['set' + Kinetic.Util._capitalize(key)](newVal);
|
||||
node.setAttr(key, newVal);
|
||||
}
|
||||
},
|
||||
_addListeners: function() {
|
||||
@@ -178,6 +178,7 @@
|
||||
*/
|
||||
play: function() {
|
||||
this.tween.play();
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* reverse
|
||||
@@ -186,6 +187,7 @@
|
||||
*/
|
||||
reverse: function() {
|
||||
this.tween.reverse();
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* reset
|
||||
@@ -196,6 +198,7 @@
|
||||
var node = this.node;
|
||||
this.tween.reset();
|
||||
(node.getLayer() || node.getLayers()).draw();
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* seek
|
||||
@@ -207,6 +210,7 @@
|
||||
var node = this.node;
|
||||
this.tween.seek(t * 1000);
|
||||
(node.getLayer() || node.getLayers()).draw();
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* pause
|
||||
@@ -215,6 +219,7 @@
|
||||
*/
|
||||
pause: function() {
|
||||
tween.pause();
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* finish
|
||||
@@ -225,6 +230,7 @@
|
||||
var node = this.node;
|
||||
this.tween.finish();
|
||||
(node.getLayer() || node.getLayers()).draw();
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* destroy
|
||||
|
@@ -25,6 +25,19 @@ Test.Modules.TWEEN = {
|
||||
test(++finishCount <= 1, 'finishCount should not exceed 1');
|
||||
}
|
||||
|
||||
var tweens = 0;
|
||||
var attrs = 0;
|
||||
|
||||
for (var key in Kinetic.Tween.tweens) {
|
||||
tweens++;
|
||||
}
|
||||
for (var key in Kinetic.Tween.attrs) {
|
||||
attrs++;
|
||||
}
|
||||
|
||||
test(tweens === 0, 'should be no tweens');
|
||||
test(attrs === 0, 'should be no attrs');
|
||||
|
||||
var tween = new Kinetic.Tween({
|
||||
node: circle,
|
||||
duration: 0.2,
|
||||
@@ -33,5 +46,20 @@ Test.Modules.TWEEN = {
|
||||
onFinish: onFinish
|
||||
}).play();
|
||||
|
||||
var tweens = 0;
|
||||
var attrs = 0;
|
||||
for (var key in Kinetic.Tween.tweens) {
|
||||
tweens++;
|
||||
}
|
||||
for (var key in Kinetic.Tween.attrs[circle._id][tween._id]) {
|
||||
attrs++;
|
||||
}
|
||||
|
||||
test(tweens === 1, 'should one tween');
|
||||
test(attrs === 2, 'should two attrs');
|
||||
|
||||
test(Kinetic.Tween.attrs[circle._id][tween._id].x !== undefined, 'x should not be undefined');
|
||||
test(Kinetic.Tween.attrs[circle._id][tween._id].y !== undefined, 'y should not be undefined');
|
||||
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user