From 348e2574b65423b2ac5bddc2401b803b91719382 Mon Sep 17 00:00:00 2001 From: Arian Date: Thu, 9 Sep 2010 01:17:45 +0200 Subject: [PATCH] Add Specs for Fx --- 1.3base/Fx/Fx.js | 136 +++++++++++++++++++++++++++++++++++++++ 1.3client/Fx/Fx.Morph.js | 45 +++++++++++++ 1.3client/Fx/Fx.Tween.js | 62 ++++++++++++++++++ Configuration.js | 22 ++++--- 4 files changed, 256 insertions(+), 9 deletions(-) create mode 100644 1.3base/Fx/Fx.js create mode 100644 1.3client/Fx/Fx.Morph.js create mode 100644 1.3client/Fx/Fx.Tween.js diff --git a/1.3base/Fx/Fx.js b/1.3base/Fx/Fx.js new file mode 100644 index 0000000..eee56ea --- /dev/null +++ b/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(); + + }); + +}); + diff --git a/1.3client/Fx/Fx.Morph.js b/1.3client/Fx/Fx.Morph.js new file mode 100644 index 0000000..afdba0a --- /dev/null +++ b/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); + + + }); + +}); diff --git a/1.3client/Fx/Fx.Tween.js b/1.3client/Fx/Fx.Tween.js new file mode 100644 index 0000000..1482583 --- /dev/null +++ b/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); + + + }); + +}); diff --git a/Configuration.js b/Configuration.js index 69c3a27..bb20e9b 100644 --- a/Configuration.js +++ b/Configuration.js @@ -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'] } }; @@ -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: [ @@ -58,7 +59,9 @@ Configuration.sets = { 'Element/Element', 'Element/NewElement', 'Element/Element.Event', - 'Request/Request' + 'Request/Request', + 'Fx/Fx.Tween', + 'Fx/Fx.Morph' ] } }; @@ -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: [ @@ -141,7 +146,6 @@ Configuration.source = { 'Utilities/Cookie', 'Utilities/Swiff', - 'Fx/Fx', 'Fx/Fx.CSS', 'Fx/Fx.Tween', 'Fx/Fx.Morph',