openseadragon/test/modules/spring.js

80 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2017-12-07 04:20:39 +03:00
/* global QUnit, Util, console */
(function () {
var originalNow;
var now;
2017-12-07 04:20:39 +03:00
QUnit.module("spring", {
beforeEach: function () {
now = 0;
originalNow = OpenSeadragon.now;
OpenSeadragon.now = function() {
return now;
};
},
2017-12-07 04:20:39 +03:00
afterEach: function () {
OpenSeadragon.now = originalNow;
}
});
2017-12-07 04:20:39 +03:00
QUnit.test('regular spring', function(assert) {
var done = assert.async();
var spring = new OpenSeadragon.Spring({
initial: 5,
animationTime: 1,
springStiffness: 0.000001
});
2017-12-07 04:20:39 +03:00
assert.equal(spring.current.value, 5, 'initial current value');
assert.equal(spring.target.value, 5, 'initial target value');
spring.springTo(6);
2017-12-07 04:20:39 +03:00
assert.equal(spring.current.value, 5, 'current value after springTo');
assert.equal(spring.target.value, 6, 'target value after springTo');
now = 500;
spring.update();
2017-12-07 04:20:39 +03:00
Util.assessNumericValue(assert, 5.5, spring.current.value, 0.00001, 'current value after first update');
assert.equal(spring.target.value, 6, 'target value after first update');
now = 1000;
spring.update();
2017-12-07 04:20:39 +03:00
assert.equal(spring.current.value, 6, 'current value after second update');
assert.equal(spring.target.value, 6, 'target value after second update');
2017-12-07 04:20:39 +03:00
done();
});
2017-12-07 04:20:39 +03:00
QUnit.test('exponential spring', function(assert) {
var done = assert.async();
var spring = new OpenSeadragon.Spring({
exponential: true,
initial: 1,
animationTime: 1,
springStiffness: 0.000001
});
2017-12-07 04:20:39 +03:00
assert.equal(spring.current.value, 1, 'initial current value');
assert.equal(spring.target.value, 1, 'initial target value');
spring.springTo(2);
2017-12-07 04:20:39 +03:00
assert.equal(spring.current.value, 1, 'current value after springTo');
assert.equal(spring.target.value, 2, 'target value after springTo');
now = 500;
spring.update();
2017-12-07 04:20:39 +03:00
Util.assessNumericValue(assert, 1.41421, spring.current.value, 0.00001, 'current value after first update');
assert.equal(spring.target.value, 2, 'target value after first update');
now = 1000;
spring.update();
2017-12-07 04:20:39 +03:00
assert.equal(spring.current.value, 2, 'current value after second update');
assert.equal(spring.target.value, 2, 'target value after second update');
2017-12-07 04:20:39 +03:00
done();
});
})();