forked from mootools/mootools-core-specs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add Specs for Fx
- Loading branch information
Arian
committed
Sep 8, 2010
1 parent
ef5af15
commit 348e257
Showing
4 changed files
with
256 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
|
||
describe('Fx', function(){ | ||
|
||
it('should start a Fx and call the onComplete event', function(){ | ||
|
||
var onComplete = jasmine.createSpy('complete'), | ||
onStart = jasmine.createSpy('start'); | ||
|
||
var fx = new Fx({ | ||
duration: 100, | ||
onComplete: onComplete, | ||
onStart: onStart | ||
}); | ||
|
||
fx.start(10, 10); | ||
|
||
expect(onStart).toHaveBeenCalled(); | ||
|
||
waits(105); | ||
|
||
runs(function(){ | ||
expect(onComplete).toHaveBeenCalled(); | ||
}); | ||
|
||
}); | ||
|
||
it('should cancel a Fx', function(){ | ||
|
||
onCancel = jasmine.createSpy(); | ||
|
||
var fx = new Fx({ | ||
duration: 50, | ||
onCancel: onCancel | ||
}); | ||
|
||
fx.start(); | ||
fx.cancel(); | ||
|
||
expect(onCancel).toHaveBeenCalled(); | ||
|
||
}); | ||
|
||
it('should set the computed value', function(){ | ||
|
||
var FxLog = new Class({ | ||
Extends: Fx, | ||
set: function(current){ | ||
this.foo = current; | ||
} | ||
}); | ||
|
||
var fx = new FxLog({ | ||
duration: 100 | ||
}).start(0, 10); | ||
|
||
waits(105); | ||
|
||
runs(function(){ | ||
expect(fx.foo).toEqual(10); | ||
}); | ||
|
||
}); | ||
|
||
it('should pause and resume', function(){ | ||
|
||
var FxLog = new Class({ | ||
Extends: Fx, | ||
set: function(current){ | ||
this.foo = current; | ||
} | ||
}); | ||
|
||
var fx = new FxLog({ | ||
duration: 100 | ||
}).start(0, 5); | ||
|
||
waits(50); | ||
|
||
runs(function(){ | ||
fx.pause(); | ||
}); | ||
|
||
waits(10); | ||
|
||
runs(function(){ | ||
fx.resume(); | ||
}); | ||
|
||
waits(70); | ||
|
||
runs(function(){ | ||
// Does not work... fx.foo is the (last-1)th result | ||
expect(fx.foo).toEqual(5); | ||
}); | ||
|
||
}); | ||
|
||
it('should chain the Fx', function(){ | ||
|
||
var counter = 0; | ||
var fx = new Fx({ | ||
duration: 50, | ||
onComplete: function(){ | ||
counter++; | ||
}, | ||
link: 'chain' | ||
}); | ||
|
||
fx.start().start(); | ||
|
||
waits(210); | ||
|
||
runs(function(){ | ||
expect(counter).toEqual(2); | ||
}); | ||
}); | ||
|
||
it('should cancel the Fx after a new Fx:start with the link = cancel option', function(){ | ||
|
||
var onCancel = jasmine.createSpy('cancel'); | ||
|
||
var counter = 0; | ||
var fx = new Fx({ | ||
duration: 50, | ||
onCancel: onCancel, | ||
link: 'cancel' | ||
}); | ||
|
||
fx.start().start(); | ||
|
||
expect(onCancel).toHaveBeenCalled(); | ||
|
||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
describe('Fx.Tween', function(){ | ||
|
||
it('should morph the style of an element', function(){ | ||
|
||
var element = new Element('div', { | ||
styles: { | ||
height: 100, | ||
width: 100 | ||
} | ||
}).inject(document.body); | ||
|
||
var fx = new Fx.Morph(element, { | ||
duration: 100 | ||
}); | ||
|
||
fx.start({ | ||
height: [10, 50], | ||
width: [10, 50] | ||
}); | ||
|
||
waits(130); | ||
|
||
runs(function(){ | ||
expect(element.getStyle('height').toInt()).toEqual(50); | ||
expect(element.getStyle('width').toInt()).toEqual(50); | ||
element.destroy(); | ||
}); | ||
|
||
}); | ||
|
||
it('should set morph options with the element getter en setter', function(){ | ||
|
||
var element = new Element('div'); | ||
|
||
element.set('morph', { | ||
duration: 100 | ||
}); | ||
|
||
expect(element.get('morph').options.duration).toEqual(100); | ||
|
||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
describe('Fx.Tween', function(){ | ||
|
||
it('should tween the style of an element', function(){ | ||
|
||
var element = new Element('div', { | ||
styles: { | ||
height: 100 | ||
} | ||
}).inject(document.body); | ||
|
||
var fx = new Fx.Tween(element, { | ||
duration: 100, | ||
property: 'height' | ||
}); | ||
|
||
fx.start(10, 50); | ||
|
||
waits(130); | ||
|
||
runs(function(){ | ||
expect(element.getStyle('height').toInt()).toEqual(50); | ||
element.destroy(); | ||
}); | ||
|
||
}); | ||
|
||
it('should fade an element', function(){ | ||
|
||
var element = new Element('div', { | ||
styles: { opacity: 0 } | ||
}).inject(document.body); | ||
|
||
element.set('tween', { | ||
duration: 100 | ||
}); | ||
|
||
element.fade('in'); | ||
|
||
waits(130); | ||
|
||
runs(function(){ | ||
expect(element.getStyle('opacity').toInt()).toEqual(1); | ||
element.destroy(); | ||
}); | ||
|
||
}); | ||
|
||
it('should set tween options with the element getter en setter', function(){ | ||
|
||
var element = new Element('div'); | ||
|
||
element.set('tween', { | ||
duration: 100 | ||
}); | ||
|
||
expect(element.get('tween').options.duration).toEqual(100); | ||
|
||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters