diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-16 16:15:51 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-16 16:15:51 +0000 |
| commit | aae420a41c54d405e7e72aacfea043751714debc (patch) | |
| tree | 3533728cd20d065c31764af49e5f34ae1c3562d7 /test | |
| parent | 0cec8e39b8d5bdbfbda046212fa822b79f2f276b (diff) | |
| download | mullvadvpn-aae420a41c54d405e7e72aacfea043751714debc.tar.xz mullvadvpn-aae420a41c54d405e7e72aacfea043751714debc.zip | |
Add tests for tray-animator
Diffstat (limited to 'test')
| -rw-r--r-- | test/tray-animator.spec.js | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/test/tray-animator.spec.js b/test/tray-animator.spec.js new file mode 100644 index 0000000000..ed7b3bff7c --- /dev/null +++ b/test/tray-animator.spec.js @@ -0,0 +1,149 @@ +import { expect } from 'chai'; +import { TrayAnimator, TrayAnimation } from '../app/lib/tray-animator'; +import { nativeImage } from 'electron'; + +describe('lib/tray-animator', function() { + this.timeout(1000); + + let animation, animator; + + beforeEach(() => { + const images = (new Array(5)).map(() => nativeImage.createEmpty()); + animation = new TrayAnimation(images); + animation.speed = 1; + }); + + afterEach(() => { + if(animator.isStarted) { + animator.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(0); + done(); + } else { + seq.push(animation._currentFrame); + } + } + }; + + animator = new TrayAnimator(tray, animation); + animator.start(); + }); + + 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(4); + done(); + } else { + seq.push(animation._currentFrame); + } + } + }; + + animation.reverse = true; + animator = new TrayAnimator(tray, animation); + animator.start(); + }); + + 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.repeat = true; + animator = new TrayAnimator(tray, animation); + animator.start(); + }); + + 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.repeat = true; + animation.reverse = true; + animator = new TrayAnimator(tray, animation); + animator.start(); + }); + + 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.repeat = true; + animation.alternate = true; + animator = new TrayAnimator(tray, animation); + animator.start(); + }); + + 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.repeat = true; + animation.reverse = true; + animation.alternate = true; + animator = new TrayAnimator(tray, animation); + animator.start(); + }); + +});
\ No newline at end of file |
