Tests/Specs: Use Chai for assertions, instead of Jasmine's assertions.
[mootools.git] / Specs / Fx / Fx.js
blobc3f842895a7b48fa099081e4fc0350df521be1e0
1 /*
2 ---
3 name: Fx
4 requires: ~
5 provides: ~
6 ...
7 */
8 describe('Fx', function(){
10         beforeEach(function(){
11                 this.clock = sinon.useFakeTimers();
12         });
14         afterEach(function(){
15                 this.clock.reset();
16                 this.clock.restore();
17         });
19         Object.each(Fx.Transitions, function(value, transition){
20                 if (transition == 'extend') return;
22                 it('should start a Fx and call the onComplete event with ' + transition + ' as timing function', function(){
24                         var onComplete = sinon.spy(),
25                                 onStart = sinon.spy();
27                         var fx = new Fx({
28                                 duration: 500,
29                                 transition: Fx.Transitions[transition],
30                                 onComplete: onComplete,
31                                 onStart: onStart
32                         });
34                         expect(onStart.called).to.equal(false);
36                         fx.start(10, 20);
38                         this.clock.tick(100);
39                         expect(onStart.called).to.equal(true);
40                         expect(onComplete.called).to.equal(false);
42                         this.clock.tick(1000);
43                         expect(onComplete.called).to.equal(true);
45                 });
46         });
48         it('should cancel a Fx', function(){
50                 var onCancel = sinon.spy();
52                 var fx = new Fx({
53                         duration: 500,
54                         transition: 'sine:in:out',
55                         onCancel: onCancel
56                 });
58                 fx.start();
60                 expect(onCancel.called).to.equal(false);
62                 fx.cancel();
64                 expect(onCancel.called).to.equal(true);
66         });
68         it('should set the computed value', function(){
70                 var FxLog = new Class({
71                         Extends: Fx,
72                         set: function(current){
73                                 this.foo = current;
74                         }
75                 });
77                 var fx = new FxLog({
78                         duration: 1000
79                 }).start(0, 10);
81                 this.clock.tick(2000);
83                 expect(fx.foo).to.equal(10);
85         });
87         it('should pause and resume', function(){
89                 var FxLog = new Class({
90                         Extends: Fx,
91                         set: function(current){
92                                 this.foo = current;
93                         }
94                 });
96                 var fx = new FxLog({
97                         duration: 2000
98                 }).start(0, 1);
100                 this.clock.tick(1000);
102                 var value;
104                 fx.pause();
105                 value = fx.foo;
106                 expect(fx.foo).to.be.greaterThan(0);
107                 expect(fx.foo).to.be.lessThan(1);
109                 this.clock.tick(1000);
111                 expect(fx.foo).to.equal(value);
112                 fx.resume();
114                 this.clock.tick(2000);
116                 expect(fx.foo).to.equal(1);
118         });
120         it('should chain the Fx', function(){
122                 var counter = 0;
123                 var fx = new Fx({
124                         duration: 500,
125                         onComplete: function(){
126                                 counter++;
127                         },
128                         link: 'chain'
129                 });
131                 fx.start().start();
133                 this.clock.tick(1000);
134                 this.clock.tick(1000);
136                 expect(counter).to.equal(2);
137         });
139         it('should cancel the Fx after a new Fx:start with the link = cancel option', function(){
141                 var onCancel = sinon.spy();
143                 var fx = new Fx({
144                         duration: 500,
145                         onCancel: onCancel,
146                         link: 'cancel'
147                 });
149                 fx.start().start();
151                 this.clock.tick(1000);
153                 expect(onCancel.called).to.equal(true);
155         });
159 describe('Fx', function(){
161         beforeEach(function(){
162                 this.clock = sinon.useFakeTimers();
163         });
165         afterEach(function(){
166                 this.clock.reset();
167                 this.clock.restore();
168         });
170         it('should return the paused state', function(){
171                 var fx = new Fx({
172                         duration: 500
173                 }).start();
175                 expect(fx.isPaused()).to.equal(false);
177                 this.clock.tick(300);
178                 fx.pause();
180                 expect(fx.isPaused()).to.equal(true);
182                 fx.resume();
183                 this.clock.tick(600);
184                 expect(fx.isPaused()).to.equal(false);
185         });