Merge pull request #11 from ibolmo/fake-xhr
[mootools.git] / 1.3base / Fx / Fx.js
blob3548385a4ac2fe893d75c3506540a197b47f0dfe
1 /*
2 ---
3 name: Fx Specs
4 description: n/a
5 requires: [Core/Fx]
6 provides: [Fx.Specs]
7 ...
8 */
9 describe('Fx', function(){
11         Object.each(Fx.Transitions, function(value, transition){
12                 if (transition == 'extend') return;
14                 it('should start a Fx and call the onComplete event with ' + transition + ' as timing function', function(){
16                         var onComplete = jasmine.createSpy('complete'),
17                                 onStart = jasmine.createSpy('start');
19                         var fx = new Fx({
20                                 duration: 50,
21                                 transition: Fx.Transitions[transition],
22                                 onComplete: onComplete,
23                                 onStart: onStart
24                         });
26                         expect(onStart).not.toHaveBeenCalled();
28                         fx.start(10, 20);
30                         expect(onStart).toHaveBeenCalled();
31                         expect(onComplete).not.toHaveBeenCalled();
33                         waitsFor(300, function(){
34                                 return onComplete.wasCalled;
35                         });
37                         runs(function(){
38                                 expect(onComplete).toHaveBeenCalled();
39                         });
41                 });
42         });
44         it('should cancel a Fx', function(){
46                 var onCancel = jasmine.createSpy();
48                 var fx = new Fx({
49                         duration: 50,
50                         transition: 'sine:in:out',
51                         onCancel: onCancel
52                 });
54                 fx.start();
56                 expect(onCancel).not.toHaveBeenCalled();
58                 fx.cancel();
60                 expect(onCancel).toHaveBeenCalled();
62         });
64         it('should set the computed value', function(){
66                 var FxLog = new Class({
67                         Extends: Fx,
68                         set: function(current){
69                                 this.foo = current;
70                         }
71                 });
73                 var fx = new FxLog({
74                         duration: 100
75                 }).start(0, 10);
77                 waits(200);
79                 runs(function(){
80                         expect(fx.foo).toEqual(10);
81                 });
83         });
85         it('should pause and resume', function(){
87                 var FxLog = new Class({
88                         Extends: Fx,
89                         set: function(current){
90                                 this.foo = current;
91                         }
92                 });
94                 var fx = new FxLog({
95                         duration: 200
96                 }).start(0, 1);
98                 waits(100);
100                 var value;
102                 runs(function(){
103                         fx.pause();
104                         value = fx.foo;
105                         expect(fx.foo).toBeGreaterThan(0);
106                         expect(fx.foo).toBeLessThan(1);
107                 });
109                 waits(100);
111                 runs(function(){
112                         expect(fx.foo).toEqual(value);
113                         fx.resume();
114                 });
116                 waits(200);
118                 runs(function(){
119                         expect(fx.foo).toEqual(1);
120                 });
122         });
124         it('should chain the Fx', function(){
126                 var counter = 0;
127                 var fx = new Fx({
128                         duration: 50,
129                         onComplete: function(){
130                                 counter++;
131                         },
132                         link: 'chain'
133                 });
135                 fx.start().start();
137                 waits(210);
139                 runs(function(){
140                         expect(counter).toEqual(2);
141                 });
142         });
144         it('should cancel the Fx after a new Fx:start with the link = cancel option', function(){
146                 var onCancel = jasmine.createSpy('cancel');
148                 var fx = new Fx({
149                         duration: 50,
150                         onCancel: onCancel,
151                         link: 'cancel'
152                 });
154                 fx.start().start();
156                 expect(onCancel).toHaveBeenCalled();
158         });