Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 9 deletions.
136 changes: 136 additions & 0 deletions 1.3base/Fx/Fx.js
@@ -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();

});

});

45 changes: 45 additions & 0 deletions 1.3client/Fx/Fx.Morph.js
@@ -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);


});

});
62 changes: 62 additions & 0 deletions 1.3client/Fx/Fx.Tween.js
@@ -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);


});

});
22 changes: 13 additions & 9 deletions Configuration.js
Expand Up @@ -19,7 +19,7 @@ Configuration.presets = {
},
'core-1.3 + core-1.2': {
sets: ['1.2', 'core-1.3-base', 'core-1.3-client'],
source: ['core-1.3-base', 'core-1.3-client']
source: ['core-1.3-base', 'core-1.3-client']
}
};

Expand All @@ -40,16 +40,17 @@ Configuration.sets = {
'Element/Element', 'Element/Element.Style', 'Element/Element.Dimensions'
]
},

'core-1.3-base': {
path: '1.3base/',
files: [
files: [
'Core/Core',
'Types/Array', 'Types/Function', 'Types/Object',
'Class/Class'
'Class/Class',
'Fx/Fx'
]
},

'core-1.3-client': {
path: '1.3client/',
files: [
Expand All @@ -58,7 +59,9 @@ Configuration.sets = {
'Element/Element',
'Element/NewElement',
'Element/Element.Event',
'Request/Request'
'Request/Request',
'Fx/Fx.Tween',
'Fx/Fx.Morph'
]
}
};
Expand Down Expand Up @@ -117,10 +120,12 @@ Configuration.source = {
'Types/Object',

'Class/Class',
'Class/Class.Extras'
'Class/Class.Extras',

'Fx/Fx'
]
},

'core-1.3-client': {
path: '../Source/',
files: [
Expand All @@ -141,7 +146,6 @@ Configuration.source = {
'Utilities/Cookie',
'Utilities/Swiff',

'Fx/Fx',
'Fx/Fx.CSS',
'Fx/Fx.Tween',
'Fx/Fx.Morph',
Expand Down

0 comments on commit 348e257

Please sign in to comment.