torque/test/animator.js

85 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-08-04 18:32:36 +08:00
var torque = require('../lib/torque');
var sinon = require('sinon');
require('phantomjs-polyfill');
2015-05-04 17:05:48 +08:00
2015-08-04 18:32:36 +08:00
asyncTest('time moves', function(assert) {
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 18:32:36 +08:00
animator.start();
setTimeout(function(){
assert.notEqual(animator._time, 0);
QUnit.start();
}, 100)
animator.pause();
2015-05-04 17:05:48 +08:00
});
2015-08-04 18:32:36 +08:00
test("rescale should resume animation if previously playing", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 18:32:36 +08:00
animator.toggle();
animator.rescale();
assert.ok(animator.running);
animator.pause()
});
2015-08-04 22:30:02 +08:00
test("rescale shouldn't resume animation if previously paused", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 22:30:02 +08:00
animator.pause();
animator.rescale();
assert.notOk(animator.running);
});
2015-08-04 18:32:36 +08:00
asyncTest("onStart runs properly", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 18:32:36 +08:00
animator.options.onStart = function(){
assert.ok(true);
animator.pause();
QUnit.start();
};
2015-08-04 21:45:11 +08:00
animator.start();
2015-08-04 18:32:36 +08:00
});
test("stop should take the pointer to position zero", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 18:32:36 +08:00
animator.stop()
assert.equal(animator._time, 0);
});
test("stop should call onStop", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 18:32:36 +08:00
animator.options.onStop = function(){
assert.ok(true);
animator.pause();
};
animator.stop();
});
2015-08-04 21:45:11 +08:00
test("altering steps should rescale", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 21:45:11 +08:00
sinon.spy(animator, "rescale");
animator.steps(600);
assert.ok(animator.rescale.calledOnce);
});
2015-08-04 18:32:36 +08:00
2015-08-04 21:45:11 +08:00
asyncTest("tick should set time to zero if steps are bigger than range", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 21:45:11 +08:00
animator.start();
setTimeout(function(){
animator._time = 0;
animator.step(800);
assert.ok(animator.step() < 800);
QUnit.start();
}, 200);
animator.pause();
});
2015-08-04 18:32:36 +08:00
2015-08-04 21:45:11 +08:00
QUnit.test("tick should pause animation on end if loop is disabled", function(assert){
2015-08-05 02:40:24 +08:00
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 10});
2015-08-04 21:45:11 +08:00
var done = assert.async();
2015-08-05 01:03:56 +08:00
animator.options.loop = false;
2015-08-04 21:45:11 +08:00
animator.toggle();
2015-08-05 01:03:56 +08:00
animator.step(600);
2015-08-04 21:45:11 +08:00
setTimeout(function(){
2015-08-05 01:03:56 +08:00
assert.equal(animator._time,animator.options.animationDuration);
2015-08-04 21:45:11 +08:00
done();
2015-08-05 01:03:56 +08:00
}, 200);
2015-08-04 21:45:11 +08:00
});