diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-20 13:00:05 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-20 13:00:05 +0000 |
| commit | 0e3e9b765fa90f7beee7b7b89c884ebd7189f4e8 (patch) | |
| tree | a7706f06543e7ba5e6822d950faf4a41719e0a5e /test | |
| parent | 85f0ac9be65b0e81989e9d992e15b1f760b3b28d (diff) | |
| parent | 62b3e2784b8aab2c5a13b3eb0f18f2a158e6bb7f (diff) | |
| download | mullvadvpn-0e3e9b765fa90f7beee7b7b89c884ebd7189f4e8.tar.xz mullvadvpn-0e3e9b765fa90f7beee7b7b89c884ebd7189f4e8.zip | |
Merge branch 'feature/refactor-animations'
Diffstat (limited to 'test')
| -rw-r--r-- | test/keyframe-animation.spec.js | 227 | ||||
| -rw-r--r-- | test/tray-animator.spec.js | 202 |
2 files changed, 227 insertions, 202 deletions
diff --git a/test/keyframe-animation.spec.js b/test/keyframe-animation.spec.js new file mode 100644 index 0000000000..83e74b72c6 --- /dev/null +++ b/test/keyframe-animation.spec.js @@ -0,0 +1,227 @@ +import { expect } from 'chai'; +import KeyframeAnimation from '../app/lib/keyframe-animation'; +import { nativeImage } from 'electron'; + +describe('lib/keyframe-animation', function() { + this.timeout(1000); + + let animation, seq; + + beforeEach(() => { + const images = [1, 2, 3, 4, 5].map(() => nativeImage.createEmpty()); + animation = new KeyframeAnimation(images); + animation.speed = 1; + + seq = []; + }); + + afterEach(() => { + animation.stop(); + }); + + it('should play sequence', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + 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 one frame', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([3]); + expect(animation._currentFrame).to.be.equal(3); + done(); + }; + + animation.play({ startFrame: 3, endFrame: 3 }); + }); + + it('should play sequence with custom frames', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([2, 3, 4]); + expect(animation._currentFrame).to.be.equal(4); + done(); + }; + + animation.play({ + startFrame: 2, + endFrame: 4 + }); + }); + + it('should play sequence with custom frames in reverse', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([4, 3, 2]); + expect(animation._currentFrame).to.be.equal(2); + done(); + }; + + animation.reverse = true; + animation.play({ + startFrame: 4, + endFrame: 2 + }); + }); + + it('should begin from current state starting below range', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]); + expect(animation._currentFrame).to.be.equal(4); + done(); + }; + + animation._currentFrame = 0; + animation._isFirstRun = false; + + animation.play({ + beginFromCurrentState: true, + startFrame: 3, + endFrame: 4 + }); + }); + + it('should begin from current state starting below range reverse', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([0, 1, 2, 3]); + expect(animation._currentFrame).to.be.equal(3); + done(); + }; + + animation._currentFrame = 0; + animation._isFirstRun = false; + animation.reverse = true; + + animation.play({ + beginFromCurrentState: true, + startFrame: 3, + endFrame: 4 + }); + }); + + it('should begin from current state starting above range', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([4, 3, 2]); + expect(animation._currentFrame).to.be.equal(2); + done(); + }; + + animation._currentFrame = 4; + animation._isFirstRun = false; + + animation.play({ + beginFromCurrentState: true, + startFrame: 1, + endFrame: 2 + }); + }); + + it('should begin from current state starting above range reverse', (done) => { + animation.onFrame = () => seq.push(animation._currentFrame); + animation.onFinish = () => { + expect(seq).to.be.deep.equal([4, 3, 2, 1]); + expect(animation._currentFrame).to.be.equal(1); + done(); + }; + + animation._currentFrame = 4; + animation._isFirstRun = false; + animation.reverse = true; + + animation.play({ + beginFromCurrentState: true, + startFrame: 1, + endFrame: 3 + }); + }); + + it('should play sequence in reverse', (done) => { + 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; + animation.play(); + }); + + it('should play sequence on repeat', (done) => { + const expectedFrames = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]; + + animation.onFrame = () => { + if(seq.length === expectedFrames.length) { + expect(seq).to.be.deep.equal(expectedFrames); + done(); + } else { + seq.push(animation._currentFrame); + } + }; + + animation.repeat = true; + animation.play(); + }); + + it('should play sequence on repeat in reverse', (done) => { + const expectedFrames = [4, 3, 2, 1, 0, 4, 3, 2, 1, 0]; + + animation.onFrame = () => { + if(seq.length === expectedFrames.length) { + expect(seq).to.be.deep.equal(expectedFrames); + done(); + } else { + seq.push(animation._currentFrame); + } + }; + + animation.repeat = true; + animation.reverse = true; + animation.play(); + }); + + it('should alternate sequence', (done) => { + const expectedFrames = [0, 1, 2, 3, 4, 3, 2, 1, 0]; + + animation.onFrame = () => { + if(seq.length === expectedFrames.length) { + expect(seq).to.be.deep.equal(expectedFrames); + done(); + } else { + seq.push(animation._currentFrame); + } + }; + + animation.repeat = true; + animation.alternate = true; + animation.play(); + }); + + it('should alternate reverse sequence', (done) => { + const expectedFrames = [4, 3, 2, 1, 0, 1, 2, 3, 4]; + + animation.onFrame = () => { + if(seq.length === expectedFrames.length) { + expect(seq).to.be.deep.equal(expectedFrames); + done(); + } else { + seq.push(animation._currentFrame); + } + }; + + animation.repeat = true; + animation.reverse = true; + animation.alternate = true; + animation.play(); + }); + +});
\ No newline at end of file diff --git a/test/tray-animator.spec.js b/test/tray-animator.spec.js deleted file mode 100644 index c6eaea24e6..0000000000 --- a/test/tray-animator.spec.js +++ /dev/null @@ -1,202 +0,0 @@ -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() { - this.timeout(1000); - - let animation, animator; - - beforeEach(() => { - const images = [1, 2, 3, 4, 5].map(() => nativeImage.createEmpty()); - animation = new TrayAnimation(images); - animation.speed = 1; - }); - - 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(); - }); - - 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); - } - } - }; - - 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(0); - 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 |
