summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRémi Tétreault <tetreault.remi@gmail.com>2016-10-30 15:20:25 -0400
committerRémi Tétreault <tetreault.remi@gmail.com>2016-11-03 18:30:48 -0400
commitfb405bd64ff17eb2ce4b6bfdd48132981ee7b55f (patch)
treef3cf19c8fa9c7b6ab6659e35ddadaad8e6a9e520 /spec
parent2b0263d91353a582a27491515406f13036923c32 (diff)
downloadsvg.js-fb405bd64ff17eb2ce4b6bfdd48132981ee7b55f.tar.gz
svg.js-fb405bd64ff17eb2ce4b6bfdd48132981ee7b55f.zip
Fix and improve the dequeue method of the FX module
The first improvement is to stop using setTimeout to perform the delay. It is now performed in a manner similar to the start method. This should be a lot more reliable than using setTimeout and allow some nice goodies like being able to pause it or affect its duration using the speed method. The second improvement is to have the delay method add an empty situation (with its duration set to the duration of the delay) to the queue. This change allows dequeue not to have to treat delay added to the queue as something special, now its just a situation.
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/fx.js60
1 files changed, 58 insertions, 2 deletions
diff --git a/spec/spec/fx.js b/spec/spec/fx.js
index 0bd014e..caf0644 100644
--- a/spec/spec/fx.js
+++ b/spec/spec/fx.js
@@ -487,9 +487,8 @@ describe('FX', function() {
it('starts the animation', function() {
fx.start()
expect(fx.active).toBe(true)
- expect(fx.timeout).not.toBe(0)
- jasmine.clock().tick(201)
+ jasmine.clock().tick(200)
fx.step() // Call step to update the animation
expect(fx.pos).toBeGreaterThan(0)
@@ -523,6 +522,14 @@ describe('FX', function() {
})
})
+ describe('delay()', function() {
+ it('should push an empty situation with its duration attribute set to the duration of the delay', function() {
+ var delay = 8300
+ fx.delay(delay)
+ expect(fx.situations[0].duration).toBe(delay)
+ })
+ })
+
describe('pause()', function() {
it('pause the animation', function() {
@@ -733,7 +740,49 @@ describe('FX', function() {
})
+ describe('queue()', function() {
+ it('can add a situation to the queue', function() {
+ var situation = new SVG.Situation({duration: 1000, delay: 0, ease: SVG.easing['-']})
+
+ fx.queue(situation)
+ expect(fx.situations[0]).toBe(situation)
+ })
+
+ it('can add a function to the queue', function() {
+ var f = function(){}
+
+ fx.queue(f)
+ expect(fx.situations[0]).toBe(f)
+ })
+
+ it('should set the situation attribute before pushing something in the situations queue', function(){
+ var situation = new SVG.Situation({duration: 1000, delay: 0, ease: SVG.easing['-']})
+
+ // Clear the animation that is created before each test
+ fx.stop()
+
+ expect(fx.situation).toBeNull()
+ expect(fx.situations.length).toBe(0)
+ fx.queue(situation)
+ expect(fx.situation).toBe(situation)
+ expect(fx.situations.length).toBe(0)
+ })
+ })
+
+
describe('dequeue()', function() {
+ it('should pull the next situtation from the queue', function() {
+ var situation = new SVG.Situation({duration: 1000, delay: 0, ease: SVG.easing['-']})
+
+ fx.queue(situation)
+ expect(fx.situtation).not.toBe(situation)
+ expect(fx.situations[0]).toBe(situation)
+
+ fx.dequeue()
+ expect(fx.situation).toBe(situation)
+ expect(fx.situations.length).toBe(0)
+ })
+
it('initialize the animation pulled from the queue to its start position', function() {
// When the animation is forward, the start position is 0
fx.animate()
@@ -745,6 +794,13 @@ describe('FX', function() {
fx.pos = 0.5
expect(fx.dequeue().pos).toBe(1)
})
+
+ it('when the first element of the queue is a function, it should execute it', function() {
+ var called = false
+
+ fx.queue(function(){ called=true; expect(this).toBe(fx) }).dequeue()
+ expect(called).toBe(true)
+ })
})