diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/tray-animator.spec.js | 175 |
1 files changed, 49 insertions, 126 deletions
diff --git a/test/tray-animator.spec.js b/test/tray-animator.spec.js index c6eaea24e6..c07bc6b632 100644 --- a/test/tray-animator.spec.js +++ b/test/tray-animator.spec.js @@ -1,12 +1,11 @@ import { expect } from 'chai'; -import TrayAnimator from '../app/lib/tray-animator'; import TrayAnimation from '../app/lib/tray-animation'; import { nativeImage } from 'electron'; -describe('lib/tray-animator', function() { +describe('lib/tray-animation', function() { this.timeout(1000); - let animation, animator; + let animation; beforeEach(() => { const images = [1, 2, 3, 4, 5].map(() => nativeImage.createEmpty()); @@ -15,188 +14,112 @@ describe('lib/tray-animator', function() { }); afterEach(() => { - if(animator.isStarted) { - animator.stop(); - } - }); - - it('should advance to start', (done) => { - const tray = { - setImage: () => { - expect(animation._currentFrame).to.be.equal(0); - done(); - } - }; - - animator = new TrayAnimator(tray, animation); - animator.advanceToStart(); - }); - - it('should advance to end', (done) => { - const tray = { - setImage: () => { - expect(animation._currentFrame).to.be.equal(4); - done(); - } - }; - - animator = new TrayAnimator(tray, animation); - animator.advanceToEnd(); - }); - - it('should advance to start when in reverse', (done) => { - const tray = { - setImage: () => { - expect(animation._currentFrame).to.be.equal(4); - done(); - } - }; - - animation.reverse = true; - - animator = new TrayAnimator(tray, animation); - animator.advanceToStart(); - }); - - it('should advance to end when in reverse', (done) => { - const tray = { - setImage: () => { - expect(animation._currentFrame).to.be.equal(0); - done(); - } - }; - - animation.reverse = true; - - animator = new TrayAnimator(tray, animation); - animator.advanceToEnd(); + animation.stop(); }); it('should play sequence', (done) => { let seq = []; - const tray = { - setImage: () => { - if(animation.isFinished) { - expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]); - expect(animation._currentFrame).to.be.equal(4); - done(); - } else { - seq.push(animation._currentFrame); - } - } + animation.onFrame = () => { + seq.push(animation._currentFrame); }; - animator = new TrayAnimator(tray, animation); - animator.start(); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]); + expect(animation._currentFrame).to.be.equal(4); + done(); + }; + + animation.play(); }); it('should play sequence in reverse', (done) => { let seq = []; - const tray = { - setImage: () => { - if(animation.isFinished) { - expect(seq).to.be.deep.equal([4, 3, 2, 1, 0]); - expect(animation._currentFrame).to.be.equal(0); - done(); - } else { - seq.push(animation._currentFrame); - } - } + animation.onFrame = () => { + seq.push(animation._currentFrame); + }; + + animation.onFinish = () => { + expect(seq).to.be.deep.equal([4, 3, 2, 1, 0]); + expect(animation._currentFrame).to.be.equal(0); + done(); }; animation.reverse = true; - animator = new TrayAnimator(tray, animation); - animator.start(); + animation.play(); }); it('should play sequence on repeat', (done) => { const expectedFrames = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]; let receivedFrames = []; - const tray = { - setImage: () => { - if(receivedFrames.length === expectedFrames.length) { - expect(receivedFrames).to.be.deep.equal(expectedFrames); - animator.stop(); - done(); - } else { - receivedFrames.push(animation._currentFrame); - } + animation.onFrame = () => { + if(receivedFrames.length === expectedFrames.length) { + expect(receivedFrames).to.be.deep.equal(expectedFrames); + done(); + } else { + receivedFrames.push(animation._currentFrame); } }; animation.repeat = true; - animator = new TrayAnimator(tray, animation); - animator.start(); + animation.play(); }); it('should play sequence on repeat in reverse', (done) => { const expectedFrames = [4, 3, 2, 1, 0, 4, 3, 2, 1, 0]; let receivedFrames = []; - const tray = { - setImage: () => { - if(receivedFrames.length === expectedFrames.length) { - expect(receivedFrames).to.be.deep.equal(expectedFrames); - animator.stop(); - done(); - } else { - receivedFrames.push(animation._currentFrame); - } + animation.onFrame = () => { + if(receivedFrames.length === expectedFrames.length) { + expect(receivedFrames).to.be.deep.equal(expectedFrames); + done(); + } else { + receivedFrames.push(animation._currentFrame); } }; animation.repeat = true; animation.reverse = true; - animator = new TrayAnimator(tray, animation); - animator.start(); + animation.play(); }); it('should alternate sequence', (done) => { const expectedFrames = [0, 1, 2, 3, 4, 3, 2, 1, 0]; let receivedFrames = []; - const tray = { - setImage: () => { - if(receivedFrames.length === expectedFrames.length) { - expect(receivedFrames).to.be.deep.equal(expectedFrames); - animator.stop(); - done(); - } else { - receivedFrames.push(animation._currentFrame); - } + animation.onFrame = () => { + if(receivedFrames.length === expectedFrames.length) { + expect(receivedFrames).to.be.deep.equal(expectedFrames); + done(); + } else { + receivedFrames.push(animation._currentFrame); } }; animation.repeat = true; animation.alternate = true; - animator = new TrayAnimator(tray, animation); - animator.start(); + animation.play(); }); it('should alternate reverse sequence', (done) => { const expectedFrames = [4, 3, 2, 1, 0, 1, 2, 3, 4]; let receivedFrames = []; - const tray = { - setImage: () => { - if(receivedFrames.length === expectedFrames.length) { - expect(receivedFrames).to.be.deep.equal(expectedFrames); - animator.stop(); - done(); - } else { - receivedFrames.push(animation._currentFrame); - } + animation.onFrame = () => { + if(receivedFrames.length === expectedFrames.length) { + expect(receivedFrames).to.be.deep.equal(expectedFrames); + done(); + } else { + receivedFrames.push(animation._currentFrame); } }; animation.repeat = true; animation.reverse = true; animation.alternate = true; - animator = new TrayAnimator(tray, animation); - animator.start(); + animation.play(); }); });
\ No newline at end of file |
