diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2015-12-20 15:43:40 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2015-12-20 15:43:40 +0100 |
commit | b40238cdffb15259196c3a9be5c477418a111542 (patch) | |
tree | 1da7a47552db6b3d9b6d91fe1d6469a17ec349e2 /spec | |
parent | 5cb2010246154e3a5dfa753f14fb081cef5c2579 (diff) | |
download | svg.js-b40238cdffb15259196c3a9be5c477418a111542.tar.gz svg.js-b40238cdffb15259196c3a9be5c477418a111542.zip |
new specs, reverse, initAnimation, after, during, comments
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/event.js | 42 | ||||
-rw-r--r-- | spec/spec/fx.js | 179 |
2 files changed, 144 insertions, 77 deletions
diff --git a/spec/spec/event.js b/spec/spec/event.js index 9c945d0..b806d65 100644 --- a/spec/spec/event.js +++ b/spec/spec/event.js @@ -297,30 +297,30 @@ describe('Event', function() { }) it('attaches multiple handlers on different element', function() { var listenerCnt = SVG.listeners.length - + var rect2 = draw.rect(100,100); var rect3 = draw.rect(100,100); - + rect.on('event', action) rect2.on('event', action) rect3.on('event', function(){ butter = 'melting' }) rect3.on('event', action) - + expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['*']).length).toBe(1) // 1 listener on rect expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect3.node)]['event']['*']).length).toBe(2) // 2 listener on rect3 expect(SVG.listeners.length).toBe(listenerCnt + 3) // added listeners on 3 different elements }) if('attaches a handler to a namespaced event', function(){ var listenerCnt = SVG.listeners.length - + var rect2 = draw.rect(100,100); var rect3 = draw.rect(100,100); - + rect.on('event.namespace1', action) rect2.on('event.namespace2', action) rect3.on('event.namespace3', function(){ butter = 'melting' }) rect3.on('event', action) - + expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['*'])).toBeUndefined() // no global listener on rect expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['namespace1']).length).toBe( 1) // 1 namespaced listener on rect expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect2.node)]['event']['namespace2']).length).toBe(1) // 1 namespaced listener on rect @@ -355,47 +355,47 @@ describe('Event', function() { it('detaches a specific event listener, all other still working', function() { rect2 = draw.rect(100,100); rect3 = draw.rect(100,100); - + rect.on('event', action) rect2.on('event', action) rect3.on('event', function(){ butter = 'melting' }) - + rect.off('event', action) - + expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['*']).length).toBe(0) - + dispatchEvent(rect, 'event') expect(toast).toBeNull() - + dispatchEvent(rect2, 'event') expect(toast).toBe('ready') - + dispatchEvent(rect3, 'event') expect(butter).toBe('melting') - + expect(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['*'][action]).toBeUndefined() }) it('detaches a specific namespaced event listener, all other still working', function() { rect2 = draw.rect(100,100); rect3 = draw.rect(100,100); - + rect.on('event.namespace', action) rect2.on('event.namespace', action) rect3.on('event.namespace', function(){ butter = 'melting' }) - + rect.off('event.namespace', action) - + expect(Object.keys(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['namespace']).length).toBe(0) - + dispatchEvent(rect, 'event') expect(toast).toBeNull() - + dispatchEvent(rect2, 'event') expect(toast).toBe('ready') - + dispatchEvent(rect3, 'event') expect(butter).toBe('melting') - + expect(SVG.listeners[SVG.handlerMap.indexOf(rect.node)]['event']['namespace'][action]).toBeUndefined() }) it('detaches all listeners for a specific namespace', function() { @@ -459,7 +459,7 @@ describe('Event', function() { expect(toast).toBe('ready') }) }) - + }) diff --git a/spec/spec/fx.js b/spec/spec/fx.js index d076209..d9a07ac 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -4,98 +4,165 @@ describe('FX', function() { beforeEach(function() { rect = draw.rect(100,100).move(100,100) fx = rect.animate(500) + fx2 = fx.enqueue() }) - it('creates an instance of SVG.FX', function() { + it('creates an instance of SVG.FX and sets parameter', function() { expect(fx instanceof SVG.FX).toBe(true) + expect(fx.target).toBe(rect) + expect(fx.pos).toBe(0) + expect(fx.paused).toBe(false) + expect(fx.finished).toBe(false) + expect(fx.active).toBe(false) + expect(fx.shared.current).toBe(fx) + expect(fx._next).toBe(fx2) + expect(fx._prev).toBe(null) + expect(fx._duration).toBe(500) + }) - - it('creates a new queue and pushes one animation into it', function() { - expect(fx._queue.length).toBe(1) - expect(fx._queue[0] instance of SVG.Situation).toBe(true) + + describe('current()', function(){ + it('returns the current fx object', function(){ + expect(fx.current()).toBe(fx.shared.current) + }) }) - - describe('queue()', function() { - it('returns the queue of this animation instance', function() { - expect(fx.queue() instanceof Array).toBe(true) + + describe('first()', function(){ + it('returns the first fx object in the queue', function(){ + expect(fx.first()).toBe(fx) }) }) - - describe('enqueue()', function() { - it('pushes one item to the animation queue', function() { - expect(fx.enqueue(500).queue().length).toBe(2) + + describe('last()', function(){ + it('returns the last fx object in the queue', function(){ + expect(fx.last()).toBe(fx2) }) }) - - describe('reverse()', function() { - it('sets the direction of the animation to -1', function() { - expect(fx.reverse()._direction).toBe(-1) + + describe('next()', function(){ + it('returns the next fx object in the queue', function(){ + expect(fx.next()).toBe(fx2) + }) + it('returns null when it hits the end of the queue', function(){ + expect(fx2.next()).toBe(null) }) }) - - describe('play()', function() { - it('sets the direction of the animation to 1', function() { - expect(fx.play()._direction).toBe(1) + + describe('prev()', function(){ + it('returns the previous fx object in the queue', function(){ + expect(fx2.prev()).toBe(fx) + }) + it('returns null whn it hits the start of the queue', function(){ + expect(fx.prev()).toBe(null) + }) + }) + + describe('share()', function() { + it('sets a new shared object', function() { + var newObj = {} + var ret = fx.share(newObj) + + expect(fx.shared).toBe(newObj) + expect(ret).toBe(fx) + + // reset the value + fx.share({current:fx}) }) }) - - describe('get()', function() { - it('gets the specified situation object from the queue', function() { - expect(fx.get(0)).toBe(fx.queue()[0]) + + describe('timeToPos()', function() { + it('converts a timestamp to a progress', function() { + expect(fx.timeToPos(fx._start+fx._duration/2)).toBe(0.5) }) }) - + + describe('posToTime()', function() { + it('converts a progress to a timestamp', function() { + expect(fx.posToTime(0.5)).toBe(fx._start+fx._duration/2) + }) + }) + describe('seek()', function() { - it('sets the position of the whole animation queue to the specified position', function() { - expect(fx.seek(0.5)._pos).toBe(0.5) + it('sets the progress to the specified position', function() { + var start = fx._start + expect(fx.seek(0.5).pos).toBe(0.5) + // time is running so we cant compare it directly + expect(fx._start).toBeLessThan(start - fx._duration * 0.5 + 1) + expect(fx._start).toBeGreaterThan(start - fx._duration * 0.5 - 10) }) }) - - describe('get(0).seek()', function() { - it('sets the position of a certain animation in the queue to the specified position', function() { - expect(fx.get(0).seek(0.5)._pos).toBe(0.5) + + describe('start()', function(){ + it('starts the animation if it is the current', function(done) { + fx.start() + expect(fx.active).toBe(true) + expect(fx.timeout).not.toBe(0) + setTimeout(function(){ + expect(fx.pos).toBeGreaterThan(0) + done() + }, 200) }) }) - - describe('stop()', function() { - it('sets the direction of the animation to 0', function() { - expect(fx.stop()._direction).toBe(0) + + describe('pause()', function() { + it('starts the animation if it is the current', function() { + expect(fx.pause().paused).toBe(true) }) }) - - describe('finish()', function() { - it('sets the position of the whole animation queue to 1', function() { - expect(fx.finish()._pos).toBe(1) + + describe('play()', function() { + it('unpause the animation', function(done) { + var start = fx.start().pause()._start + setTimeout(function(){ + expect(fx.play().paused).toBe(false) + expect(fx._start).not.toBe(start) + done() + }, 200) }) }) - - describe('get(0).finish()', function() { - it('sets the position of a certain animation in the queue to 1', function() { - expect(fx.get(0).finish(1)._pos).toBe(1) + + describe('speed()', function() { + it('speeds up the animation by the given factor', function(){ + //console.log(fx.pos) + expect(fx.speed(2)._duration).toBe(250) + expect(fx.speed(0.5)._duration).toBe(500) + expect(fx.seek(0.2).speed(2)._duration).toBe(0.2 * 500 + 0.8 * 500 / 2) }) }) + /*describe('reverse()', function() { + it('sets the direction of the animation to -1', function() { + expect(fx.reverse()._direction).toBe(-1) + }) + }) + + describe('finish()', function() { + it('sets the position of the whole animation queue to 1', function() { + expect(fx.finish()._pos).toBe(1) + }) + })*/ + it('animates the x/y-attr', function(done) { - + fx.move(200,200).after(function(){ - + expect(rect.x()).toBe(200) expect(rect.y()).toBe(200) done() - + }); - + setTimeout(function(){ expect(rect.x()).toBeGreaterThan(100) expect(rect.y()).toBeGreaterThan(100) }, 250) }) - + it('animates matrix', function(done) { - + fx.transform({a:0.8, b:0.4, c:-0.15, d:0.7, e: 90.3, f: 27.07}).after(function(){ - + var ctm = rect.ctm() expect(ctm.a).toBeCloseTo(0.8) expect(ctm.b).toBeCloseTo(0.4) @@ -103,13 +170,13 @@ describe('FX', function() { expect(ctm.d).toBeCloseTo(0.7) expect(ctm.e).toBeCloseTo(90.3) expect(ctm.f).toBeCloseTo(27.07) - + done() - + }) - + setTimeout(function(){ - + var ctm = rect.ctm(); expect(ctm.a).toBeLessThan(1) expect(ctm.b).toBeGreaterThan(0) @@ -118,7 +185,7 @@ describe('FX', function() { expect(ctm.e).toBeGreaterThan(0) expect(ctm.f).toBeGreaterThan(0) }, 250) - + }) })
\ No newline at end of file |