2012-11-14 13:37:28 +08:00
|
|
|
Test.Modules.ANIMATION = {
|
|
|
|
/*
|
|
|
|
* WARNING: make sure that this is the first unit test that uses
|
|
|
|
* animation because it's accessing the global animation object which could
|
|
|
|
* be modified by other unit tests
|
|
|
|
*/
|
2013-05-06 13:09:32 +08:00
|
|
|
'test start and stop': function(containerId) {
|
2012-11-14 13:37:28 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var amplitude = 150;
|
|
|
|
var period = 1000;
|
|
|
|
// in ms
|
|
|
|
var centerX = stage.getWidth() / 2 - 100 / 2;
|
|
|
|
|
2012-11-16 13:30:58 +08:00
|
|
|
var anim = new Kinetic.Animation(function(frame) {
|
|
|
|
rect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
|
|
|
}, layer);
|
2012-11-14 13:37:28 +08:00
|
|
|
var a = Kinetic.Animation;
|
|
|
|
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 0, '1should be no animations running');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
anim.start();
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 1, '2should be 1 animation running');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
anim.stop();
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 0, '3should be no animations running');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
anim.start();
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 1, '4should be 1 animation running');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
anim.start();
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 1, '5should be 1 animation runningg');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
anim.stop();
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 0, '6should be no animations running');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
anim.stop();
|
2013-05-12 07:43:09 +08:00
|
|
|
test(a.animations.length === 0, '7should be no animations running');
|
2013-05-06 13:09:32 +08:00
|
|
|
},
|
|
|
|
'batch draw': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
draws = 0;
|
|
|
|
|
|
|
|
layer.on('draw', function() {
|
|
|
|
console.log('draw')
|
|
|
|
draws++;
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.draw();
|
|
|
|
layer.draw();
|
|
|
|
layer.draw();
|
|
|
|
|
|
|
|
test(draws === 3, 'draw count should be 3');
|
|
|
|
|
|
|
|
layer.batchDraw();
|
|
|
|
layer.batchDraw();
|
|
|
|
layer.batchDraw();
|
|
|
|
|
|
|
|
test(Kinetic.Layer.batchAnim.getLayers().length === 1, 'batch animation should only have one layer');
|
|
|
|
|
2013-05-08 01:19:54 +08:00
|
|
|
test(draws !== 6, 'should not be 6 draws');
|
2012-11-14 13:37:28 +08:00
|
|
|
}
|
|
|
|
};
|