Tween = window.mojs.Tween
Timeline = window.mojs.Timeline
tweener = window.mojs.tweener
describe 'Tween ->', ->
beforeEach -> tweener.removeAll()
it 'should have timelines var', ->
t = new Tween
expect(t.timelines.length).toBe 0
expect(t.props.totalTime) .toBe 0
it 'should have initial state flags', ->
t = new Tween
expect(t.state).toBe 'stop'
describe 'add method ->', ->
it 'should add timeline',->
t = new Tween
t.add new Timeline
expect(t.timelines.length).toBe 1
expect(t.timelines[0] instanceof Timeline).toBe true
it 'should work with arrays of tweens',->
t = new Tween
t1 = new Timeline duration: 1000
t2 = new Timeline duration: 1500
t.add [t1, t2, new Tween]
expect(t.timelines.length).toBe 3
expect(t.props.totalTime).toBe 1500
expect(t.timelines[0] instanceof Timeline).toBe true
expect(t.timelines[1] instanceof Timeline).toBe true
expect(t.timelines[2] instanceof Tween) .toBe true
it 'should work with arguments',->
tween = new Tween isIt: true
t1 = new Timeline duration: 500, delay: 200
t2 = new Timeline duration: 500, delay: 500
tween.add t1, t2
expect(tween.props.totalTime) .toBe 1000
expect(tween.timelines.length).toBe 2
it 'should work with mixed arguments',->
t = new Tween
t1 = new Timeline duration: 1000
t2 = new Timeline duration: 1500
t.add [t1, new Timeline, new Tween], t2
expect(t.timelines.length).toBe 4
expect(t.props.totalTime).toBe 1500
expect(t.timelines[0] instanceof Timeline).toBe true
expect(t.timelines[1] instanceof Timeline).toBe true
expect(t.timelines[2] instanceof Tween) .toBe true
expect(t.timelines[3] instanceof Timeline).toBe true
it 'should calc self duration',->
t = new Tween
t.add new Timeline duration: 500, delay: 200
expect(t.props.totalTime).toBe 700
t.add new Timeline duration: 500, delay: 200, repeat: 1
expect(t.props.totalTime).toBe 1400
it 'should work with another tweens',->
t1 = new Tween
t = new Tween
t.add new Timeline duration: 500, delay: 200
t.add new Timeline duration: 500, delay: 200, repeat: 1
t1.add t
expect(t1.props.totalTime).toBe 1400
describe 'pushTimeline method ->', ->
it 'should push timeline to timelines and calc totalTime',->
t = new Tween
t.pushTimeline new Timeline duration: 4000
expect(t.timelines.length).toBe 1
expect(t.timelines[0] instanceof Timeline).toBe true
expect(t.props.totalTime).toBe 4000
describe 'append method ->', ->
it 'should add timeline',->
t = new Tween
t.append new Timeline
expect(t.timelines.length).toBe 1
expect(t.timelines[0] instanceof Timeline).toBe true
it 'should delay the timeline to duration',->
t = new Tween
t.add new Timeline duration: 1000, delay: 200
t.append new Timeline duration: 500, delay: 500
expect(t.timelines[1].o.delay).toBe 1700
it 'should recalc duration',->
t = new Tween
t.add new Timeline duration: 1000, delay: 200
t.append new Timeline duration: 500, delay: 500
expect(t.props.totalTime).toBe 2200
it 'should work with array',->
t = new Tween
t.add new Timeline duration: 1000, delay: 200
tm1 = new Timeline(duration: 500, delay: 500)
tm2 = new Timeline(duration: 500, delay: 700)
t.append [tm1, tm2]
expect(t.timelines.length).toBe 3
expect(t.props.totalTime).toBe 2400
it 'should work with array #2',->
t = new Tween
t.add new Timeline duration: 1000, delay: 200
tm1 = new Timeline(duration: 500, delay: 500)
tm2 = new Timeline(duration: 500, delay: 700)
spyOn t, 'recalcDuration'
t.append [tm1, tm2]
expect(t.recalcDuration).toHaveBeenCalled()
it 'should work with array #2',->
t = new Tween
t.append new Timeline duration: 1000, delay: 200
expect(t.timelines.length).toBe 1
it 'should add element index',->
t = new Tween
t.append new Timeline duration: 1000, delay: 200
t.append new Timeline duration: 1000, delay: 200
expect(t.timelines[0].index).toBe 0
expect(t.timelines[1].index).toBe 1
describe 'remove method ->', ->
it 'should remove timeline',->
t = new Tween
timeline = new Timeline
t.add timeline
t.remove timeline
expect(t.timelines.length).toBe 0
it 'should remove tween',->
t1 = new Tween
t = new Tween
timeline = new Timeline
t.add timeline
t1.add t
t1.remove t
expect(t1.timelines.length).toBe 0
describe 'recalcDuration method ->', ->
it 'should recalculate duration', ->
t = new Tween
timeline = new Timeline duration: 100
timeline2 = new Timeline duration: 1000
t.add timeline
t.timelines.push timeline2
t.recalcDuration()
expect(t.props.totalTime).toBe 1000
describe 'start method ->', ->
it 'should get the start time',->
t = new Tween
t.start()
expect(t.props.startTime).toBeDefined()
expect(t.props.endTime).toBe t.props.startTime + t.props.totalTime
it 'should call the setStartTime method',->
t = new Tween
spyOn t, 'setStartTime'
time = 0
t.start time
expect(t.setStartTime).toHaveBeenCalledWith time
it 'should start every timeline',->
it 'should update the current time on every timeline',->
t = new Tween
t.add new Timeline duration: 500, delay: 200
t.add new Timeline duration: 500, delay: 100
spyOn t.timelines[0], 'start'
spyOn t.timelines[1], 'start'
t.start()
expect(t.timelines[0].start).toHaveBeenCalledWith t.props.startTime
expect(t.timelines[1].start).toHaveBeenCalledWith t.props.startTime
it 'should add itself to tweener',->
t = new Tween
spyOn tweener, 'add'
t.start()
expect(tweener.add).toHaveBeenCalled()
it 'should not add itself to tweener if time was passed',->
t = new Tween
spyOn tweener, 'add'
t.start 10239123
expect(tweener.add).not.toHaveBeenCalled()
it 'should set state to "play"',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add(timeline); t.start()
expect(t.state).toBe 'play'
describe 'removeFromTweener method ->', ->
it 'should call t.remove method with self',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add timeline
t.start()
t.removeFromTweener()
expect(tweener.tweens.length).toBe 0
describe 'pause method ->', ->
it 'should call t.remove method with self',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add timeline
t.start()
spyOn t, 'removeFromTweener'
t.pause()
expect(t.removeFromTweener).toHaveBeenCalled()
it 'should set state to "pause"',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add(timeline); t.start(); t.pause()
expect(t.state).toBe 'pause'
describe 'stop method ->', ->
it 'should call t.removeFromTweener method with self',->
tweener.tweens = []; t = new Tween
timeline = new Timeline duration: 2000
t.add timeline
t.start()
spyOn t, 'removeFromTweener'
t.stop()
expect(t.removeFromTweener).toHaveBeenCalled()
it 'should reset progress to 0',->
tweener.tweens = []; t = new Tween
timeline = new Timeline duration: 2000
t.add timeline
t.start()
spyOn t, 'setProgress'
t.stop()
expect(t.setProgress).toHaveBeenCalledWith 0
it 'should set state to "stop"',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add(timeline); t.start(); t.stop()
expect(t.state).toBe 'stop'
describe 'restart method ->', ->
it 'should call stop method',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add(timeline); t.start()
spyOn t, 'stop'
t.restart()
expect(t.stop).toHaveBeenCalled()
it 'should call start method',->
tweener.tweens = []
t = new Tween
timeline = new Timeline duration: 2000
t.add(timeline); t.start()
spyOn t, 'start'
t.restart()
expect(t.start).toHaveBeenCalled()
probaly no needed for this describe 'resetProgress method ->', -> it 'should call setProgress with 0', -> t = new Tween timeline1 = new Timeline duration: 2000 timeline2 = new Timeline duration: 2000 t.add(timeline1, timeline2) t.setStartTime() spyOn t, 'setProgress' t.resetProgress() expect(t.setProgress).toHaveBeenCalledWith 0 it 'should update every timeline with its initial time', -> t = new Tween tm1 = new Timeline duration: 2000, delay: 500 tm2 = new Timeline duration: 2000, delay: 100 t.add(tm1, tm2) t.setStartTime() spyOn tm1, 'update' spyOn tm2, 'update' t.resetProgress() expect(tm1.update).toHaveBeenCalledWith tm1.props.startTime expect(tm2.update).toHaveBeenCalledWith tm2.props.startTime