diff options
author | Rémi Tétreault <tetreault.remi@gmail.com> | 2016-10-17 15:17:12 -0400 |
---|---|---|
committer | Rémi Tétreault <tetreault.remi@gmail.com> | 2016-10-17 15:17:12 -0400 |
commit | d29ee51f9f3deaae12410bbfcd4f7827937146ed (patch) | |
tree | e647741604521f5eebea6b375ed1ab955a6dbe3b /spec | |
parent | 91d4934ca6d83792aae8bbebc900e69f9f4df205 (diff) | |
download | svg.js-d29ee51f9f3deaae12410bbfcd4f7827937146ed.tar.gz svg.js-d29ee51f9f3deaae12410bbfcd4f7827937146ed.zip |
Make tests relating to speed easier to understand
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/fx.js | 132 |
1 files changed, 90 insertions, 42 deletions
diff --git a/spec/spec/fx.js b/spec/spec/fx.js index f050a2a..e848862 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -43,10 +43,15 @@ describe('FX', function() { }) it('should take speed into consideration', function() { - fx.speed(4) - expect(fx.timeToPos(fx.situation.start+fx.situation.duration/4/2)).toBe(0.5) - fx.speed(0.5) - expect(fx.timeToPos(fx.situation.start+fx.situation.duration/0.5/4)).toBe(0.25) + var spd + + spd = 4 + fx.speed(spd) + expect(fx.timeToPos(fx.situation.start+(fx.situation.duration/spd)/2)).toBe(0.5) + + spd = 0.5 + fx.speed(spd) + expect(fx.timeToPos(fx.situation.start+(fx.situation.duration/spd)/4)).toBe(0.25) }) }) @@ -56,10 +61,15 @@ describe('FX', function() { }) it('should take speed into consideration', function() { - fx.speed(4) - expect(fx.posToTime(0.5)).toBe(fx.situation.start+fx.situation.duration/4/2) - fx.speed(0.5) - expect(fx.posToTime(0.25)).toBe(fx.situation.start+fx.situation.duration/0.5/4) + var spd + + spd = 4 + fx.speed(spd) + expect(fx.posToTime(0.5)).toBe(fx.situation.start+(fx.situation.duration/spd)/2) + + spd = 0.5 + fx.speed(spd) + expect(fx.posToTime(0.25)).toBe(fx.situation.start+(fx.situation.duration/spd)/4) }) }) @@ -73,14 +83,25 @@ describe('FX', function() { }) it('should take speed into consideration', function() { - fx.speed(4).at(0) - expect(fx.situation.finish-fx.situation.start).toBe(500/4) - fx.speed(5).at(0.75) - expect(fx.situation.finish-fx.situation.start).toBe(500/5) - fx.speed(0.25).at(0.75) - expect(fx.situation.finish-fx.situation.start).toBe(500/0.25) - fx.speed(0.5).at(0.83) - expect(fx.situation.finish-fx.situation.start).toBe(500/0.5) + var dur, spd + + dur = fx.situation.duration + + spd = 4 + fx.speed(spd).at(0) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) + + spd = 5 + fx.speed(spd).at(0.15) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) + + spd = 0.25 + fx.speed(spd).at(0.75) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) + + spd = 0.5 + fx.speed(spd).at(0.83) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) }) }) @@ -96,8 +117,11 @@ describe('FX', function() { }) it('should take speed into consideration', function() { - fx.speed(4).start() - expect(fx.situation.finish-fx.situation.start).toBe(500/4) + var dur = fx.situation.duration + , spd = 4 + + fx.speed(spd).start() + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) }) }) @@ -120,59 +144,83 @@ describe('FX', function() { describe('speed()', function() { it('set the speed of the animation', function(){ - fx.speed(2) - expect(fx.spd).toBe(2) - expect(fx.situation.finish-fx.situation.start).toBe(500/2) + var dur, spd + + dur = fx.situation.duration + + spd = 2 + fx.speed(spd) + expect(fx.spd).toBe(spd) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) - fx.speed(0.5) - expect(fx.spd).toBe(0.5) - expect(fx.situation.finish-fx.situation.start).toBe(500/0.5) + spd = 0.5 + fx.speed(spd) + expect(fx.spd).toBe(spd) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) - fx.at(0.2).speed(2) - expect(fx.spd).toBe(2) - expect(fx.situation.finish-fx.situation.start).toBe(500/2) + spd = 2 + fx.at(0.2).speed(spd) + expect(fx.spd).toBe(spd) + expect(fx.situation.finish-fx.situation.start).toBe(dur/spd) - fx.speed(1) - expect(fx.spd).toBe(1) - expect(fx.situation.finish-fx.situation.start).toBe(500) + spd = 1 + fx.speed(spd) + expect(fx.spd).toBe(spd) + expect(fx.situation.finish-fx.situation.start).toBe(dur) }) it('should not change the position when the animation is run backward', function(){ - expect(fx.at(0.4).reverse(true).speed(2).pos).toBe(0.4) + var pos = 0.4 + + expect(fx.at(pos).reverse(true).speed(2).pos).toBe(pos) }) it('return the current speed with no argument given', function(){ - fx.speed(2) - expect(fx.speed()).toBe(2) + var spd + + spd = 2 + fx.speed(spd) + expect(fx.speed()).toBe(spd) - fx.speed(0.5) - expect(fx.speed()).toBe(0.5) + spd = 0.5 + fx.speed(spd) + expect(fx.speed()).toBe(spd) - fx.speed(1) - expect(fx.speed()).toBe(1) + spd = 1 + fx.speed(spd) + expect(fx.speed()).toBe(spd) }) it('pause the animation when a speed of 0 is passed', function(){ - var currentSpeed = fx.speed() + var spd = fx.speed() expect(fx.speed(0)).toBe(fx) - expect(fx.speed()).toBe(currentSpeed) + expect(fx.speed()).toBe(spd) expect(fx.paused).toBe(true) }) it('should affect all animations in the queue', function(done){ - fx.speed(2).animate(300).start() + fx.speed(2).animate(300) expect(fx.situations.length).not.toBe(0) expect(fx.pos).not.toBe(1) + // At this point, there should be 2 animations in the queue to be played: + // the one of 500ms that is added before every test and the one of 300ms + // we just added. Normally, it would take 800ms before both of these + // animations are done, but because we set the speed to 2, it should + // only take 400ms to do both animations. + fx.start() + + // We expect this timeout to happen while the second animation is running setTimeout(function(){ - expect(fx.active).toBeTruthy() + expect(fx.active).toBe(true) expect(fx.situations.length).toBe(0) expect(fx.pos).not.toBe(1) }, 300) + // Here, we expect that all the animations are done setTimeout(function(){ - expect(fx.active).toBeFalsy() + expect(fx.active).toBe(false) expect(fx.situations.length).toBe(0) expect(fx.pos).toBe(1) done() |