Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #2134 - Merge branch 'specs' into fix-2134-merge-specs-submodule

Conflicts:
	.gitignore
	.gitmodules
  • Loading branch information...
commit f80ca2065f38bc6e356f30a47a630d2332c8f14f 2 parents fa2a8c8 + 4ebf266
@arian arian authored
Showing with 10,389 additions and 1 deletion.
  1. +3 −1 .gitignore
  2. +4 −0 .gitmodules
  3. +326 −0 Specs/1.2/Class/Class.Extras.js
  4. +247 −0 Specs/1.2/Class/Class.js
  5. +40 −0 Specs/1.2/Core/Browser.js
  6. +418 −0 Specs/1.2/Core/Core.js
  7. +69 −0 Specs/1.2/Core/Native.js
  8. +134 −0 Specs/1.2/Element/Element.Dimensions.js
  9. +87 −0 Specs/1.2/Element/Element.Style.js
  10. +1,568 −0 Specs/1.2/Element/Element.js
  11. +207 −0 Specs/1.2/Native/Array.js
  12. +155 −0 Specs/1.2/Native/Function.js
  13. +203 −0 Specs/1.2/Native/Hash.js
  14. +114 −0 Specs/1.2/Native/Number.js
  15. +158 −0 Specs/1.2/Native/String.js
  16. +17 −0 Specs/1.2/Utilities/Cookie.js
  17. +280 −0 Specs/1.3base/Class/Class.js
  18. +480 −0 Specs/1.3base/Core/Core.js
  19. +159 −0 Specs/1.3base/Fx/Fx.js
  20. +271 −0 Specs/1.3base/Types/Array.js
  21. +201 −0 Specs/1.3base/Types/Function.js
  22. +128 −0 Specs/1.3base/Types/Object.js
  23. +15 −0 Specs/1.3base/package.yml
  24. +20 −0 Specs/1.3client/Browser/Browser.js
  25. +183 −0 Specs/1.3client/Class/Class.Extras.js
  26. +56 −0 Specs/1.3client/Core/Core.js
  27. +86 −0 Specs/1.3client/Element/Element.Dimensions.js
  28. +85 −0 Specs/1.3client/Element/Element.Event.js
  29. +38 −0 Specs/1.3client/Element/Element.Style.js
  30. +360 −0 Specs/1.3client/Element/Element.js
  31. +32 −0 Specs/1.3client/Element/IFrame.js
  32. +128 −0 Specs/1.3client/Element/NewElement.js
  33. +58 −0 Specs/1.3client/Fx/Fx.Morph.js
  34. +127 −0 Specs/1.3client/Fx/Fx.Tween.js
  35. +254 −0 Specs/1.3client/Request/Request.HTML.js
  36. +64 −0 Specs/1.3client/Request/Request.JSON.js
  37. +140 −0 Specs/1.3client/Request/Request.js
  38. +29 −0 Specs/1.3client/Types/Object.js
  39. +25 −0 Specs/1.3client/Utilities/Cookie.js
  40. +33 −0 Specs/1.3client/Utilities/DOMReady.js
  41. +453 −0 Specs/1.3client/Utilities/DOMReady.php
  42. +33 −0 Specs/1.3client/Utilities/JSON.js
  43. +26 −0 Specs/1.3client/package.yml
  44. +29 −0 Specs/1.4base/Types/Array.js
  45. +32 −0 Specs/1.4base/Types/Function-nocompat.js
  46. +268 −0 Specs/1.4client/Element/Element.Delegation.html
  47. +58 −0 Specs/1.4client/Element/Element.Delegation.js
  48. +131 −0 Specs/1.4client/Element/Element.Event.change.html
  49. +85 −0 Specs/1.4client/Element/Element.Event.js
  50. +224 −0 Specs/1.4client/Element/Element.js
  51. +46 −0 Specs/1.4client/Fx/Fx.Tween.js
  52. +10 −0 Specs/1.4client/package.yml
  53. +572 −0 Specs/2.0base/Core/Core.js
  54. +291 −0 Specs/2.0base/Types/Array.js
  55. +232 −0 Specs/2.0base/Types/Function.js
  56. +132 −0 Specs/2.0base/Types/Number.js
  57. +176 −0 Specs/2.0base/Types/Object.js
  58. +149 −0 Specs/2.0base/Types/String.js
  59. +21 −0 Specs/2.0client/Browser/Browser.js
  60. +341 −0 Specs/Configuration.js
  61. +48 −0 Specs/README.md
  62. +1 −0  Specs/Runner
  63. +1 −0  Specs/buildMobile
  64. +28 −0 Specs/index.html
View
4 .gitignore
@@ -1,3 +1,5 @@
mootools-core.js
mootools-core.tmproj
-mootools-core.esproj
+mootools-core.esproj
+mootools-core-mobile.js
+*~
View
4 .gitmodules
@@ -1,3 +1,7 @@
[submodule "Packager"]
path = Packager
url = git://github.com/kamicane/packager.git
+[submodule "Specs/Runner"]
+ path = Specs/Runner
+ url = git://github.com/mootools/mootools-runner.git
+
View
326 Specs/1.2/Class/Class.Extras.js
@@ -0,0 +1,326 @@
+/*
+Script: Class.Extras.js
+ Public specs for Class.Extras.js
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var Local = Local || {};
+
+describe("Chain Class", {
+
+ "before all": function(){
+ Local.Chain = new Class({
+
+ Implements: Chain
+
+ });
+ },
+
+ "callChain should not fail when nothing was added to the chain": function(){
+ var chain = new Local.Chain();
+ chain.callChain();
+ },
+
+ "should pass arguments to the function and return values": function(){
+ var chain = new Local.Chain();
+ var arr = [];
+ chain.chain(function(a, b){
+ var str = "0" + b + a;
+ arr.push(str);
+ return str;
+ });
+ chain.chain(function(a, b){
+ var str = "1" + b + a;
+ arr.push(str);
+ return str;
+ });
+ var ret;
+ expect(arr).toEqual([]);
+ ret = chain.callChain("a", "A");
+ expect(ret).toEqual("0Aa");
+ expect(arr).toEqual(["0Aa"]);
+
+ ret = chain.callChain("b", "B");
+ expect(ret).toEqual("1Bb");
+ expect(arr).toEqual(["0Aa", "1Bb"]);
+
+ ret = chain.callChain();
+ expect(ret).toEqual(false);
+ expect(arr).toEqual(["0Aa", "1Bb"]);
+ },
+
+ "should chain any number of functions": function(){
+ var chain = new Local.Chain();
+ var arr = [];
+
+ chain.chain(function(){
+ arr.push(0);
+ }, function(){
+ arr.push(1);
+ });
+
+ expect(arr).toEqual([]);
+ chain.callChain();
+ expect(arr).toEqual([0]);
+ chain.chain(function(){
+ arr.push(2);
+ });
+ chain.callChain();
+ expect(arr).toEqual([0, 1]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ },
+
+ "should allow an array of functions": function(){
+ var chain = new Local.Chain();
+ var arr = [];
+
+ chain.chain([function(){
+ arr.push(0);
+ }, function(){
+ arr.push(1);
+ }, function(){
+ arr.push(2);
+ }]);
+
+ expect(arr).toEqual([]);
+ chain.callChain();
+ expect(arr).toEqual([0]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ },
+
+ "each instance should have its own chain": function(){
+ var foo = new Local.Chain();
+ var bar = new Local.Chain();
+ foo.val = "F";
+ bar.val = "B";
+ foo.chain(function(){
+ this.val += 'OO';
+ });
+ bar.chain(function(){
+ this.val += 'AR';
+ });
+ expect(foo.val).toEqual('F');
+ expect(bar.val).toEqual('B');
+ foo.callChain();
+ bar.callChain();
+ expect(foo.val).toEqual('FOO');
+ expect(bar.val).toEqual('BAR');
+ },
+
+ "should be able to clear the chain": function(){
+ var called;
+ var fn = function(){
+ called = true;
+ };
+
+ var chain = new Local.Chain();
+ chain.chain(fn, fn, fn, fn);
+
+ chain.callChain();
+ expect(called).toBeTruthy();
+ called = false;
+
+ chain.clearChain();
+
+ chain.callChain();
+ expect(called).toBeFalsy();
+ called = false;
+ },
+
+ "should be able to clear the chain from within": function(){
+ var foo = new Local.Chain();
+
+ var test = 0;
+ foo.chain(function(){
+ test++;
+ foo.clearChain();
+ }).chain(function(){
+ test++;
+ }).callChain();
+
+ expect(test).toEqual(1);
+ }
+
+});
+
+var fire = 'fireEvent';
+
+var runEventSpecs = function(type, create){
+ describe('1.2 Events API: ' + type.capitalize(), {
+
+ 'before each': function(){
+ Local.called = 0;
+ Local.fn = function(){
+ return Local.called++;
+ };
+ },
+
+ 'should add an Event to the Class': function(){
+ var object = create();
+
+ object.addEvent('event', Local.fn)[fire]('event');
+
+ expect(Local.called).toEqual(1);
+ },
+
+ 'should add multiple Events to the Class': function(){
+ create().addEvents({
+ event1: Local.fn,
+ event2: Local.fn
+ })[fire]('event1')[fire]('event2');
+
+ expect(Local.called).toEqual(2);
+ },
+
+ // TODO 2.0only
+ /*'should be able to remove event during firing': function(){
+ create().addEvent('event', Local.fn).addEvent('event', function(){
+ Local.fn();
+ this.removeEvent('event', arguments.callee);
+ }).addEvent('event', function(){ Local.fn(); })[fire]('event')[fire]('event');
+
+ expect(Local.called).toEqual(5);
+ },*/
+
+ 'should remove a specific method for an event': function(){
+ var object = create();
+ var x = 0, fn = function(){ x++; };
+
+ object.addEvent('event', Local.fn).addEvent('event', fn).removeEvent('event', Local.fn)[fire]('event');
+
+ expect(x).toEqual(1);
+ expect(Local.called).toEqual(0);
+ },
+
+ 'should remove an event and its methods': function(){
+ var object = create();
+ var x = 0, fn = function(){ x++; };
+
+ object.addEvent('event', Local.fn).addEvent('event', fn).removeEvents('event')[fire]('event');
+
+ expect(x).toEqual(0);
+ expect(Local.called).toEqual(0);
+ },
+
+ 'should remove all events': function(){
+ var object = create();
+ var x = 0, fn = function(){ x++; };
+
+ object.addEvent('event1', Local.fn).addEvent('event2', fn).removeEvents();
+ object[fire]('event1')[fire]('event2');
+
+ expect(x).toEqual(0);
+ expect(Local.called).toEqual(0);
+ },
+
+ 'should remove events with an object': function(){
+ var object = create();
+ var events = {
+ event1: Local.fn,
+ event2: Local.fn
+ };
+
+ object.addEvent('event1', function(){ Local.fn(); }).addEvents(events)[fire]('event1');
+ expect(Local.called).toEqual(2);
+
+ object.removeEvents(events);
+ object[fire]('event1');
+ expect(Local.called).toEqual(3);
+
+ object[fire]('event2');
+ expect(Local.called).toEqual(3);
+ }
+
+ });
+};
+
+runEventSpecs('mixin', function(){
+ return new Events
+});
+
+runEventSpecs('element', function(){
+ return new Element('div');
+});
+
+describe("Options Class", {
+
+ "before all": function(){
+ Local.OptionsTest = new Class({
+ Implements: [Options, Events],
+
+ options: {
+ a: 1,
+ b: 2
+ },
+
+ initialize: function(options){
+ this.setOptions(options);
+ }
+ });
+ },
+
+ "should set options": function(){
+ var myTest = new Local.OptionsTest({a: 1, b: 3});
+ expect(myTest.options).not.toEqual(undefined);
+ },
+
+ "should override default options": function(){
+ var myTest = new Local.OptionsTest({a: 3, b: 4});
+ expect(myTest.options.a).toEqual(3);
+ expect(myTest.options.b).toEqual(4);
+ }
+
+});
+
+describe("Options Class with Events", {
+
+ "before all": function(){
+ Local.OptionsTest = new Class({
+ Implements: [Options, Events],
+
+ options: {
+ onEvent1: function(){
+ return true;
+ },
+ onEvent2: function(){
+ return false;
+ }
+ },
+
+ initialize: function(options){
+ this.setOptions(options);
+ }
+ });
+ },
+
+ "should add events in the options object if class has implemented the Events class": function(){
+ var myTest = new Local.OptionsTest({
+ onEvent2: function(){
+ return true;
+ },
+
+ onEvent3: function(){
+ return true;
+ }
+ });
+
+ expect(myTest.$events.event1.length).toEqual(1);
+ expect(myTest.$events.event2.length).toEqual(1);
+ expect(myTest.$events.event3.length).toEqual(1);
+ }
+
+});
+
+})();
View
247 Specs/1.2/Class/Class.js
@@ -0,0 +1,247 @@
+/*
+Script: Class.js
+ Specs for Class.js
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var Animal = new Class({
+
+ initialized: false,
+
+ initialize: function(name, sound){
+ this.name = name;
+ this.sound = sound || '';
+ this.initialized = true;
+ },
+
+ eat: function(){
+ return 'animal:eat:' + this.name;
+ },
+
+ say: function(){
+ return 'animal:say:' + this.name;
+ }
+
+});
+
+var Cat = new Class({
+
+ Extends: Animal,
+
+ ferocious: false,
+
+ initialize: function(name, sound){
+ this.parent(name, sound || 'miao');
+ },
+
+ eat: function(){
+ return 'cat:eat:' + this.name;
+ },
+
+ play: function(){
+ return 'cat:play:' + this.name;
+ }
+
+});
+
+var Lion = new Class({
+
+ Extends: Cat,
+
+ ferocious: true,
+
+ initialize: function(name){
+ this.parent(name, 'rarr');
+ },
+
+ eat: function(){
+ return 'lion:eat:' + this.name;
+ }
+
+});
+
+var Actions = new Class({
+
+ jump: function(){
+ return 'actions:jump:' + this.name;
+ },
+
+ sleep: function(){
+ return 'actions:sleep:' + this.name;
+ }
+
+});
+
+var Attributes = new Class({
+
+ color: function(){
+ return 'attributes:color:' + this.name;
+ },
+
+ size: function(){
+ return 'attributes:size:' + this.name;
+ }
+
+});
+
+
+describe('Class creation', {
+
+ "Classes should be of type 'class'": function(){
+ expect($type(Animal)).toEqual('class');
+ expect(Class.type(Animal)).toBeTruthy();
+ },
+
+ "should call initialize upon instantiation": function(){
+ var animal = new Animal('lamina');
+ expect(animal.name).toEqual('lamina');
+ expect(animal.initialized).toBeTruthy();
+ expect(animal.say()).toEqual('animal:say:lamina');
+ },
+
+ "should use 'Extend' property to extend another class": function(){
+ var cat = new Cat('fluffy');
+ expect(cat.name).toEqual('fluffy');
+ expect(cat.sound).toEqual('miao');
+ expect(cat.ferocious).toBeFalsy();
+ expect(cat.say()).toEqual('animal:say:fluffy');
+ expect(cat.eat()).toEqual('cat:eat:fluffy');
+ expect(cat.play()).toEqual('cat:play:fluffy');
+ },
+
+ "should use 'Extend' property to extend an extended class": function(){
+ var leo = new Lion('leo');
+ expect(leo.name).toEqual('leo');
+ expect(leo.sound).toEqual('rarr');
+ expect(leo.ferocious).toBeTruthy();
+ expect(leo.say()).toEqual('animal:say:leo');
+ expect(leo.eat()).toEqual('lion:eat:leo');
+ expect(leo.play()).toEqual('cat:play:leo');
+ },
+
+ "should use 'Implements' property to implement another class": function(){
+ var Dog = new Class({
+ Implements: Animal
+ });
+
+ var rover = new Dog('rover');
+ expect(rover.name).toEqual('rover');
+ expect(rover.initialized).toBeTruthy();
+ expect(rover.eat()).toEqual('animal:eat:rover');
+ },
+
+ "should use 'Implements' property to implement any number of classes": function(){
+ var Dog = new Class({
+ Extends: Animal,
+ Implements: [Actions, Attributes]
+ });
+
+ var rover = new Dog('rover');
+ expect(rover.initialized).toBeTruthy();
+ expect(rover.eat()).toEqual('animal:eat:rover');
+ expect(rover.say()).toEqual('animal:say:rover');
+ expect(rover.jump()).toEqual('actions:jump:rover');
+ expect(rover.sleep()).toEqual('actions:sleep:rover');
+ expect(rover.size()).toEqual('attributes:size:rover');
+ expect(rover.color()).toEqual('attributes:color:rover');
+ },
+
+ "should alter the Class's prototype when implementing new methods": function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ var rover = new Dog('rover');
+
+ Dog.implement({
+ jump: function(){
+ return 'dog:jump:' + this.name;
+ }
+ });
+
+ var spot = new Dog('spot');
+
+ expect(spot.jump()).toEqual('dog:jump:spot');
+ expect(rover.jump()).toEqual('dog:jump:rover');
+ },
+
+ "should alter the Class's prototype when implementing new methods into the super class": function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ var rover = new Dog('rover');
+
+ Animal.implement({
+ jump: function(){
+ return 'animal:jump:' + this.name;
+ }
+ });
+
+ var spot = new Dog('spot');
+
+ expect(spot.jump()).toEqual('animal:jump:spot');
+ expect(rover.jump()).toEqual('animal:jump:rover');
+ },
+
+ "should alter the Class's prototype when overwriting methods in the super class": function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ var rover = new Dog('rover');
+ expect(rover.say()).toEqual('animal:say:rover');
+
+ Animal.implement({
+ say: function(){
+ return 'NEW:animal:say:' + this.name;
+ }
+ });
+
+ var spot = new Dog('spot');
+
+ expect(spot.say()).toEqual('NEW:animal:say:spot');
+ expect(rover.say()).toEqual('NEW:animal:say:rover');
+ }
+
+});
+
+describe('Class::implement', {
+
+ 'should implement an object': function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ Dog.implement(new Actions);
+
+ var rover = new Dog('rover');
+
+ expect(rover.name).toEqual('rover');
+ expect(rover.jump()).toEqual('actions:jump:rover');
+ expect(rover.sleep()).toEqual('actions:sleep:rover');
+ },
+
+ 'should implement any number of objects': function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ Dog.implement(new Actions).implement(new Attributes);
+
+ var rover = new Dog('rover');
+
+ expect(rover.name).toEqual('rover');
+ expect(rover.jump()).toEqual('actions:jump:rover');
+ expect(rover.sleep()).toEqual('actions:sleep:rover');
+ expect(rover.size()).toEqual('attributes:size:rover');
+ expect(rover.color()).toEqual('attributes:color:rover');
+ }
+
+});
+
+})();
View
40 Specs/1.2/Core/Browser.js
@@ -0,0 +1,40 @@
+/*
+Script: Browser.js
+ Public Specs for Browser.js 1.2
+
+License:
+ MIT-style license.
+*/
+
+describe('$exec', {
+
+ 'should evaluate on global scope': function(){
+ $exec.call($exec, 'var execSpec = 42');
+ expect(window.execSpec).toEqual(42);
+ },
+
+ 'should return the evaluated script': function(){
+ expect($exec('$empty();')).toEqual('$empty();');
+ }
+
+});
+
+describe('Document', {
+
+ 'should hold the parent window': function(){
+ expect(document.window).toEqual(window);
+ },
+
+ 'should hold the head element': function(){
+ expect(document.head.tagName.toLowerCase()).toEqual('head');
+ }
+
+});
+
+describe('Window', {
+
+ 'should set the Element prototype': function(){
+ expect($defined(window.Element.prototype)).toBeTruthy();
+ }
+
+});
View
418 Specs/1.2/Core/Core.js
@@ -0,0 +1,418 @@
+/*
+Script: Core.js
+ Public Specs for Core.js 1.2
+
+License:
+ MIT-style license.
+*/
+
+describe('$A', {
+
+ 'should return a copy for an array': function(){
+ var arr1 = [1,2,3];
+ var arr2 = $A(arr1);
+ expect(arr1 !== arr2).toBeTruthy();
+ },
+
+ 'should return an array for an Elements collection': function(){
+ var div1 = document.createElement('div');
+ var div2 = document.createElement('div');
+ var div3 = document.createElement('div');
+
+ div1.appendChild(div2);
+ div1.appendChild(div3);
+
+ var array = $A(div1.getElementsByTagName('*'));
+ expect(Array.type(array)).toBeTruthy();
+ },
+
+ 'should return an array for arguments': function(){
+ var fnTest = function(){
+ return $A(arguments);
+ };
+ var arr = fnTest(1,2,3);
+ expect(Array.type(arr)).toBeTruthy();
+ expect(arr.length).toEqual(3);
+ }
+
+});
+
+describe('$arguments', {
+
+ 'should return the argument passed according to the index': function(){
+ expect($arguments(0)('a','b','c','d')).toEqual('a');
+ expect($arguments(1)('a','b','c','d')).toEqual('b');
+ expect($arguments(2)('a','b','c','d')).toEqual('c');
+ expect($arguments(3)('a','b','c','d')).toEqual('d');
+ }
+
+});
+
+describe('$chk', {
+
+ 'should return false on false': function(){
+ expect($chk(false)).toBeFalsy();
+ },
+
+ 'should return false on null': function(){
+ expect($chk(null)).toBeFalsy();
+ },
+
+ 'should return false on undefined': function(){
+ expect($chk(undefined)).toBeFalsy();
+ },
+
+ 'should return true on 0': function(){
+ expect($chk(0)).toBeTruthy();
+ },
+
+ 'should return true for any truthsie': function(){
+ expect($chk(1)).toBeTruthy();
+ expect($chk({})).toBeTruthy();
+ expect($chk(true)).toBeTruthy();
+ }
+
+});
+
+describe('$clear', {
+
+ 'should clear timeouts': function(){
+ var timeout = setTimeout(function(){}, 100);
+ expect($clear(timeout)).toBeNull();
+ },
+
+ 'should clear intervals': function(){
+ var interval = setInterval(function(){}, 100);
+ expect($clear(interval)).toBeNull();
+ }
+
+});
+
+describe('$defined', {
+
+ 'should return true on 0': function(){
+ expect($defined(0)).toBeTruthy();
+ },
+
+ 'should return true on false': function(){
+ expect($defined(false)).toBeTruthy();
+ },
+
+ 'should return false on null': function(){
+ expect($defined(null)).toBeFalsy();
+ },
+
+ 'should return false on undefined': function(){
+ expect($defined(undefined)).toBeFalsy();
+ }
+
+});
+
+describe('$each', {
+
+ 'should call the function for each item in Function arguments': function(){
+ var daysArr = [];
+ (function(){
+ $each(arguments, function(value, key){
+ daysArr[key] = value;
+ });
+ })('Sun','Mon','Tue');
+
+ expect(daysArr).toEqual(['Sun','Mon','Tue']);
+ },
+
+ 'should call the function for each item in the array': function(){
+ var daysArr = [];
+ $each(['Sun','Mon','Tue'], function(value, key){
+ daysArr[key] = value;
+ });
+
+ expect(daysArr).toEqual(['Sun','Mon','Tue']);
+ },
+
+ 'should call the function for each item in the object': function(){
+ var daysObj = {};
+ $each({first: "Sunday", second: "Monday", third: "Tuesday"}, function(value, key){
+ daysObj[key] = value;
+ });
+
+ expect(daysObj).toEqual({first: 'Sunday', second: 'Monday', third: 'Tuesday'});
+ }
+
+});
+
+describe('$extend', {
+
+ 'should extend two objects': function(){
+ var obj1 = {a: 1, b: 2};
+ var obj2 = {b: 3, c: 4};
+ $extend(obj1, obj2);
+ expect(obj1).toEqual({a: 1, b: 3, c: 4});
+ },
+
+ 'should overwrite properties': function(){
+ var obj1 = {a: 1, b: 2};
+ var obj2 = {b: 3, c: 4, a: 5};
+ $extend(obj1, obj2);
+ expect(obj1).toEqual({a: 5, b: 3, c: 4});
+ },
+
+ 'should not extend with null argument': function(){
+ var obj1 = {a: 1, b: 2};
+ $extend(obj1);
+ expect(obj1).toEqual({a: 1, b: 2});
+ }
+
+});
+
+describe('$lambda', {
+
+ 'if a function is passed in that function should be returned': function(){
+ var fn = function(a,b){ return a; };
+ expect($lambda(fn)).toEqual(fn);
+ },
+
+ 'should return a function that returns the value passed when called': function(){
+ expect($lambda('hello world!')()).toEqual('hello world!');
+ }
+
+});
+
+describe('$merge', {
+
+ 'should dereference objects': function(){
+ var obj1 = {a: 1, b: 2};
+ var obj2 = $merge(obj1);
+ expect(obj1 === obj2).toBeFalsy();
+ },
+
+ 'should merge any arbitrary number of nested objects': function(){
+ var obj1 = {a: {a: 1, b: 2, c: 3}, b: 2};
+ var obj2 = {a: {a: 2, b: 8, c: 3, d: 8}, b: 3, c: 4};
+ var obj3 = {a: {a: 3}, b: 3, c: false};
+ expect($merge(obj1, obj2, obj3)).toEqual({a: {a: 3, b: 8, c: 3, d: 8}, b: 3, c: false});
+ }
+
+});
+
+describe('$pick', {
+
+ 'should return the first false argument': function(){
+ var picked1 = $pick(null, undefined, false, [1,2,3], {});
+ expect(picked1).toBeFalsy();
+ },
+
+ 'should return the first defined argument': function(){
+ var picked1 = $pick(null, undefined, null, [1,2,3], {});
+ expect(picked1).toEqual([1,2,3]);
+ }
+
+});
+
+describe('$random', {
+
+ 'should return a number between two numbers specified': function(){
+ var rand = $random(1, 3);
+ expect((rand <= 3 && rand >= 1)).toBeTruthy();
+ }
+
+});
+
+describe('$splat', {
+
+ 'should transform a non array into an array': function(){
+ expect($splat(1)).toEqual([1]);
+ },
+
+ 'should transforum an undefined or null into an empty array': function(){
+ expect($splat(null)).toEqual([]);
+ expect($splat(undefined)).toEqual([]);
+ },
+
+ 'should ignore and return an array': function(){
+ expect($splat([1,2,3])).toEqual([1,2,3]);
+ }
+
+});
+
+describe('$time', {
+
+ 'should return a timestamp': function(){
+ expect(Number.type($time())).toBeTruthy();
+ },
+
+ 'should be within a reasonable range': function(){
+ expect($time() < 1e13 && $time() > 1e12).toBeTruthy();
+ }
+
+});
+
+describe('$try', {
+
+ 'should return the result of the first successful function without executing successive functions': function(){
+ var calls = 0;
+ var attempt = $try(function(){
+ calls++;
+ throw new Exception();
+ }, function(){
+ calls++;
+ return 'success';
+ }, function(){
+ calls++;
+ return 'moo';
+ });
+ expect(calls).toEqual(2);
+ expect(attempt).toEqual('success');
+ },
+
+ 'should return null when no function succeeded': function(){
+ var calls = 0;
+ var attempt = $try(function(){
+ calls++;
+ return I_invented_this();
+ }, function(){
+ calls++;
+ return uninstall_ie();
+ });
+ expect(calls).toEqual(2);
+ expect(attempt).toBeNull();
+ }
+
+});
+
+describe('$type', {
+
+ "should return 'array' for Array objects": function(){
+ expect($type([1,2])).toEqual('array');
+ },
+
+ "should return 'string' for String objects": function(){
+ expect($type('ciao')).toEqual('string');
+ },
+
+ "should return 'regexp' for RegExp objects": function(){
+ expect($type(/_/)).toEqual('regexp');
+ },
+
+ "should return 'function' for Function objects": function(){
+ expect($type(function(){})).toEqual('function');
+ },
+
+ "should return 'number' for Number objects": function(){
+ expect($type(10)).toEqual('number');
+ expect($type(NaN)).not.toEqual('number');
+ },
+
+ "should return 'boolean' for Boolean objects": function(){
+ expect($type(true)).toEqual('boolean');
+ expect($type(false)).toEqual('boolean');
+ },
+
+ "should return 'object' for Object objects": function(){
+ expect($type({a:2})).toEqual('object');
+ },
+
+ "should return 'arguments' for Function arguments": function(){
+ if (window.opera){ // Seems like the Opera guys can't decide on this
+ var type = $type(arguments);
+ expect(type == 'array' || type == 'arguments').toBeTruthy();
+ return;
+ }
+
+ expect($type(arguments)).toEqual('arguments');
+ },
+
+ "should return false for null objects": function(){
+ expect($type(null)).toBeFalsy();
+ },
+
+ "should return false for undefined objects": function(){
+ expect($type(undefined)).toBeFalsy();
+ },
+
+ "should return 'collection' for HTMLElements collections": function(){
+ expect($type(document.getElementsByTagName('*'))).toEqual('collection');
+ },
+
+ "should return 'element' for an Element": function(){
+ var div = document.createElement('div');
+ expect($type(div)).toEqual('element');
+ },
+
+ "should return 'array' for Elements": function(){
+ expect($type(new Elements)).toEqual('array');
+ },
+
+ "should return 'window' for the window object": function(){
+ expect($type(window)).toEqual('window');
+ },
+
+ "should return 'document' for the document object": function(){
+ expect($type(document)).toEqual('document');
+ }
+
+});
+
+describe('$unlink', {
+
+ "should unlink an object recursivly": function(){
+ var inner = {b: 2};
+ var obj = {a: 1, inner: inner};
+ var copy = $unlink(obj);
+ obj.a = 10;
+ inner.b = 20;
+
+ expect(obj.a).toEqual(10);
+ expect(obj.inner.b).toEqual(20);
+ expect($type(obj)).toEqual('object');
+
+ expect(copy.a).toEqual(1);
+ expect(copy.inner.b).toEqual(2);
+ expect($type(copy)).toEqual('object');
+ },
+
+ "should unlink an Hash": function(){
+ var hash = new Hash({a: 'one'});
+ var copy = $unlink(hash);
+
+ expect($type(hash)).toEqual('hash');
+ expect($type(copy)).toEqual('hash');
+
+ copy.set('a', 'two');
+
+ expect(hash.get('a')).toEqual('one');
+ expect(copy.get('a')).toEqual('two');
+ }
+
+});
+
+describe('Hash.getLength', {
+
+ "should return the number of items in it": function(){
+ var hash = new Hash({});
+ expect(hash.getLength()).toEqual(0);
+ hash.set('mootools', 'awesome');
+ hash.milk = 'yummy';
+ expect(hash.getLength()).toEqual(2);
+ },
+
+ "should not fail when length is set": function(){
+ var hash = new Hash({'length': 10});
+ expect(hash.getLength()).toEqual(1);
+ },
+
+ "should work as a generic on objects": function(){
+ expect(Hash.getLength({})).toEqual(0);
+ expect(Hash.getLength({'': '', '0': '0', 'length': 99})).toEqual(3);
+ }
+
+});
+
+describe('$H', {
+
+ "should create a new hash": function(){
+ var hash = $H({});
+ expect($type(hash)).toEqual('hash');
+ }
+
+});
View
69 Specs/1.2/Core/Native.js
@@ -0,0 +1,69 @@
+/*
+Script: Core.js
+ Private Specs for Core.js 1.2
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var Instrument = new Native({
+
+ name: 'instrument',
+
+ initialize: function(name){
+ this.name = name;
+ }
+
+});
+
+Instrument.implement({
+
+ method: function(){
+ return this.property + ' ' + this.name;
+ },
+
+ property: 'stuff'
+
+});
+
+var Car = new Native({
+
+ name: 'car',
+
+ initialize: function(name){
+ this.name = name;
+ }
+
+});
+
+Car.implement({
+
+ property: 'stuff',
+
+ method: function(){
+ return this.name + '_' + this.property;
+ }
+
+});
+
+describe('Native (private)', {
+
+ 'should allow implementation over existing methods when browser option is not set': function(){
+ Instrument.implement({ property: 'staff' });
+ var myInstrument = new Instrument('xeelophone');
+ expect(myInstrument.method()).toEqual('staff xeelophone');
+ },
+
+ 'should allow generic calls': function(){
+ expect(Car.method({name: 'ciccio', property: 'bello'})).toEqual('ciccio_bello');
+ },
+
+ "should have a 'native' type": function(){
+ expect(Native.type(Car)).toBeTruthy();
+ }
+
+});
+
+})();
View
134 Specs/1.2/Element/Element.Dimensions.js
@@ -0,0 +1,134 @@
+/*
+Script: Element.Dimensions.js
+ Specs for Element.Dimensions.js
+
+License:
+ MIT-style license.
+*/
+
+describe('Element.Dimensions', function(){
+
+ var div, relDiv, absDiv, scrollDiv, tallDiv;
+
+ beforeEach(function(){
+ div = new Element('div', {
+ id: 'ElementDimensionsTest',
+ styles: {
+ width: 100,
+ height: 100,
+ margin: 2,
+ padding: 3,
+ border: '1px solid black',
+ visibility: 'hidden',
+ display: 'block',
+ position: 'absolute',
+ top: 100,
+ left: 100,
+ overflow: 'hidden',
+ zIndex: 1
+ }
+ }).inject($(document.body));
+
+ relDiv = new Element('div', {
+ styles: {
+ width: 50,
+ height: 50,
+ margin: 5,
+ padding: 5,
+ border: '1px solid green',
+ visibility: 'hidden',
+ position: 'relative',
+ overflow: 'hidden',
+ 'float': 'left',
+ 'display': 'inline'
+ }
+ }).inject(div);
+
+ absDiv = new Element('div', {
+ styles: {
+ width: 10,
+ height: 10,
+ margin: 5,
+ padding: 5,
+ border: '1px solid red',
+ visibility: 'hidden',
+ position: 'absolute',
+ top: 10,
+ left: 10,
+ overflow: 'hidden'
+ }
+ }).inject(relDiv);
+
+ scrollDiv = new Element('div', {
+ styles: {
+ width: 100,
+ height: 100,
+ overflow: 'scroll',
+ visibility: 'hidden',
+ position: 'absolute',
+ top: 0,
+ left: 0
+ }
+ }).inject($(document.body));
+
+ tallDiv = new Element('div', {
+ styles: {
+ width: 200,
+ height: 200,
+ visibility: 'hidden'
+ }
+ }).inject(scrollDiv);
+ });
+
+ describe('Element.getSize', function(){
+
+ it('should measure the width and height of the element', function(){
+ expect(div.getSize().x).toEqual(108);
+ expect(div.getSize().y).toEqual(108);
+ });
+
+ });
+
+ describe('Element.getPosition', function(){
+
+ it('should measure the x and y position of the element', function(){
+ expect(div.getPosition()).toEqual({x: 102, y: 102});
+ });
+
+ it('should measure the x and y position of the element relative to another', function(){
+ expect(relDiv.getPosition(div)).toEqual({x: 8, y: 8});
+ });
+
+ });
+
+ describe('Element.getCoordinates', function(){
+
+ it('should return the coordinates relative to parent', function(){
+ expect(absDiv.getCoordinates(relDiv)).toEqual({left:15, top:15, width:22, height:22, right:37, bottom:37});
+ });
+
+ });
+
+ describe('Element.getScrollSize', function(){
+
+ it('should return the scrollSize', function(){
+ expect(scrollDiv.getScrollSize()).toEqual({x:200, y:200});
+ });
+
+ });
+
+ describe('Element.scrollTo', function(){
+
+ it('should scroll the element', function(){
+ expect(scrollDiv.scrollTo(20, 20).getScroll()).toEqual({x:20, y:20});
+ });
+
+ });
+
+ afterEach(function(){
+ [div, relDiv, absDiv, scrollDiv, tallDiv].each(function(el){
+ $(el).destroy();
+ });
+ });
+
+});
View
87 Specs/1.2/Element/Element.Style.js
@@ -0,0 +1,87 @@
+/*
+Script: Element.Style.js
+ Specification Examples of Element.Style.js.
+
+License:
+ MIT-style license.
+*/
+
+describe('Element.set `opacity`', {
+
+ 'should set the opacity of an Element': function() {
+ var el = new Element('div').set('opacity', 0.4);
+ if (document.html.style.opacity != null)
+ expect(el.style.opacity == 0.4).toBeTruthy();
+ else if (document.html.style.filter != null)
+ expect(el.style.filter).toEqual('alpha(opacity=40)');
+ else
+ expect(el.getStyle('opacity')).toEqual(0.4);
+ },
+
+ 'should return the opacity of an Element': function() {
+ var div = new Element('div').set('opacity', 0.4);
+ expect(div.get('opacity') == 0.4).toBeTruthy();
+ div.set('opacity', 0);
+ expect(div.get('opacity') == 0).toBeTruthy();
+ }
+
+});
+
+
+
+describe('Element.getStyle', {
+
+ 'should get a six digit hex code from a three digit hex code': function() {
+ var el = new Element('div').set('html', '<div style="color:#00ff00"></div>');
+ expect(el.getElement('div').getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should getStyle a six digit hex code from an RGB value': function() {
+ var el = new Element('div').set('html', '<div style="color:rgb(0, 255, 0)"></div>');
+ expect(el.getElement('div').getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should `getStyle` with a dash in it': function() {
+ var el = new Element('div').set('html', '<div style="list-style-type:square"></div>');
+ expect(el.getElement('div').getStyle('list-style-type')).toEqual('square');
+ },
+
+ 'should `getStyle` padding': function() {
+ var el = new Element('div').set('html', '<div style="padding:20px"></div>');
+ expect(el.getElement('div').getStyle('padding-left')).toEqual('20px');
+ }
+
+});
+
+describe('Element.setStyle', {
+
+ 'should set the `styles` property on an Element using the Element constructor': function() {
+ expect(new Element('div', {styles:{'color':'#00ff00'}}).getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should `setStyle` on an Element': function() {
+ expect(new Element('div').setStyle('color','#00ff00').getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should properly `setStyle` for a property with a dash in it': function() {
+ expect(new Element('div').setStyle('list-style-type', 'square').getStyle('list-style-type')).toEqual('square');
+ }
+
+});
+
+describe('Element.getStyles', {
+
+ 'should return multiple styles': function() {
+ var el = new Element('div').set('html', '<div style="color:#00ff00;list-style-type:square"></div>');
+ expect(el.getElement('div').getStyles('color', 'list-style-type')).toEqual({color:'#00ff00', 'list-style-type':'square'});
+ }
+
+});
+
+describe('Element.setStyles', {
+
+ 'should set multiple styles': function() {
+ expect(new Element('div').setStyles({'list-style-type':'square', 'color':'#00ff00'}).getStyles('list-style-type', 'color')).toEqual({'list-style-type':'square', color:'#00ff00'});
+ }
+
+});
View
1,568 Specs/1.2/Element/Element.js
@@ -0,0 +1,1568 @@
+/*
+Script: Element.js
+ Specs for Element.js
+
+License:
+ MIT-style license.
+*/
+
+describe('Element constructor', {
+
+ "should return an Element with the correct tag": function(){
+ var element = new Element('div');
+ expect($type(element)).toEqual('element');
+ expect($defined(element.addEvent)).toBeTruthy();
+ expect(element.tagName.toLowerCase()).toEqual('div');
+ },
+
+ 'should return an Element with various attributes': function(){
+ var element = new Element('div', { 'id': 'divID', 'title': 'divTitle' });
+ expect(element.id).toEqual('divID');
+ expect(element.title).toEqual('divTitle');
+ },
+
+ 'should return an Element with for attribute': function(){
+ var label = new Element('label', { 'for': 'myId' });
+ expect(label.htmlFor).toEqual('myId');
+ },
+
+ 'should return an Element with class attribute': function(){
+ var div1 = new Element('div', { 'class': 'class' });
+ var div2 = new Element('div', { 'class': 'class1 class2 class3' });
+
+ expect(div1.className).toEqual('class');
+ expect(div2.className).toEqual('class1 class2 class3');
+ },
+
+ 'should return input Elements with name and type attributes': function(){
+ var username = new Element('input', { type: 'text', name: 'username', value: 'username' });
+ var password = new Element('input', { type: 'password', name: 'password', value: 'password' });
+ expect(username.type).toEqual('text');
+ expect(username.name).toEqual('username');
+ expect(username.value).toEqual('username');
+
+ expect(password.type).toEqual('password');
+ expect(password.name).toEqual('password');
+ expect(password.value).toEqual('password');
+
+ var dad = new Element('div');
+ dad.adopt(username, password);
+ dad.inject(document.body);
+ expect(document.getElementsByName('username')[0]).toEqual(username);
+ expect(document.getElementsByName('password')[0]).toEqual(password);
+ dad.dispose();
+ },
+
+ 'should be able to use all kinds of silly characters in your name attribute values': function(){
+ ["foo","bar[]","b'a'z",'b"a"ng','boi ng'].each(function(name){
+ var input = new Element('input', { type: 'text', name: name, value: name });
+ expect(input.type).toEqual('text');
+ expect(input.name).toEqual(name);
+ expect(input.value).toEqual(name);
+ var dad = new Element('div');
+ dad.adopt(input);
+ dad.inject(document.body);
+ expect(document.getElementsByName(name)[0]).toEqual(input);
+ dad.dispose();
+ });
+ },
+
+ 'should return input Elements that are checked': function(){
+ var check1 = new Element('input', { type: 'checkbox' });
+ var check2 = new Element('input', { type: 'checkbox', checked: true });
+ var check3 = new Element('input', { type: 'checkbox', checked: 'checked' });
+
+ expect(check1.checked).toBeFalsy();
+ expect(check2.checked).toBeTruthy();
+ expect(check3.checked).toBeTruthy();
+ },
+
+ "should return a select Element that retains it's selected options": function(){
+ var div = new Element('div', { 'html':
+ '<select multiple="multiple" name="select[]">' +
+ '<option value="" name="none">--</option>' +
+ '<option value="volvo" name="volvo">Volvo</option>' +
+ '<option value="saab" name="saab" selected="selected">Saab</option>' +
+ '<option value="opel" name="opel" selected="selected">Opel</option>' +
+ '<option value="bmw" name="bmw">BMW</option>' +
+ '</select>'
+ });
+
+ var select1 = div.getFirst();
+ var select2 = new Element('select', { name: 'select[]', multiple: true }).adopt(
+ new Element('option', { name: 'none', value: '', html: '--' }),
+ new Element('option', { name: 'volvo', value: 'volvo', html: 'Volvo' }),
+ new Element('option', { name: 'saab', value: 'saab', html: 'Saab', selected: true }),
+ new Element('option', { name: 'opel', value: 'opel', html: 'Opel', selected: 'selected' }),
+ new Element('option', { name: 'bmw', value: 'bmw', html: 'BMW' })
+ );
+
+ expect(select1.multiple).toBeTruthy();
+ expect(select2.multiple).toBeTruthy();
+
+ expect(select1.name).toEqual(select2.name);
+ expect(select1.options.length).toEqual(select2.options.length);
+ expect(select1.toQueryString()).toEqual(select2.toQueryString());
+ }
+
+});
+
+describe('Element.set', {
+
+ "should set a single attribute of an Element": function(){
+ var div = new Element('div').set('id', 'some_id');
+ expect(div.id).toEqual('some_id');
+ },
+
+ "should set the checked attribute of an Element": function(){
+ var input1 = new Element('input', {type: 'checkbox'}).set('checked', 'checked');
+ var input2 = new Element('input', {type: 'checkbox'}).set('checked', true);
+ expect(input1.checked).toBeTruthy();
+ expect(input2.checked).toBeTruthy();
+ },
+
+ "should set the class name of an element": function(){
+ var div = new Element('div').set('class', 'some_class');
+ expect(div.className).toEqual('some_class');
+ },
+
+ "should set the for attribute of an element": function(){
+ var input = new Element('label', {type: 'text'}).set('for', 'some_element');
+ expect(input.htmlFor).toEqual('some_element');
+ },
+
+ "should set the html of an Element": function(){
+ var html = '<a href="http://mootools.net/">Link</a>';
+ var parent = new Element('div').set('html', html);
+ expect(parent.innerHTML.toLowerCase()).toEqual(html.toLowerCase());
+ },
+
+ "should set the html of an Element with multiple arguments": function(){
+ var html = ['<p>Paragraph</p>', '<a href="http://mootools.net/">Link</a>'];
+ var parent = new Element('div').set('html', html);
+ expect(parent.innerHTML.toLowerCase()).toEqual(html.join('').toLowerCase());
+ },
+
+ "should set the html of a select Element": function(){
+ var html = '<option>option 1</option><option selected="selected">option 2</option>';
+ var select = new Element('select').set('html', html);
+ expect(select.getChildren().length).toEqual(2);
+ expect(select.options.length).toEqual(2);
+ expect(select.selectedIndex).toEqual(1);
+ },
+
+ "should set the html of a table Element": function(){
+ var html = '<tbody><tr><td>cell 1</td><td>cell 2</td></tr><tr><td class="cell">cell 1</td><td>cell 2</td></tr></tbody>';
+ var table = new Element('table').set('html', html);
+ expect(table.getChildren().length).toEqual(1);
+ expect(table.getFirst().getFirst().getChildren().length).toEqual(2);
+ expect(table.getFirst().getLast().getFirst().className).toEqual('cell');
+ },
+
+ "should set the html of a tbody Element": function(){
+ var html = '<tr><td>cell 1</td><td>cell 2</td></tr><tr><td class="cell">cell 1</td><td>cell 2</td></tr>';
+ var tbody = new Element('tbody').inject(new Element('table')).set('html', html);
+ expect(tbody.getChildren().length).toEqual(2);
+ expect(tbody.getLast().getFirst().className).toEqual('cell');
+ },
+
+ "should set the html of a tr Element": function(){
+ var html = '<td class="cell">cell 1</td><td>cell 2</td>';
+ var tr = new Element('tr').inject(new Element('tbody').inject(new Element('table'))).set('html', html);
+ expect(tr.getChildren().length).toEqual(2);
+ expect(tr.getFirst().className).toEqual('cell');
+ },
+
+ "adopting should not change the parent of the element doing the adopting": function(){
+ var baldGuy = new Element('div');
+ var annie = new Element('span');
+
+ gramps = baldGuy.getParent();
+ baldGuy.adopt(annie);
+ expect(baldGuy.getParent()).toEqual(gramps)
+ },
+
+ "should set the html of a td Element": function(){
+ var html = '<span class="span">Some Span</span><a href="#">Some Link</a>';
+ var td = new Element('td').inject(new Element('tr').inject(new Element('tbody').inject(new Element('table')))).set('html', html);
+ expect(td.getChildren().length).toEqual(2);
+ expect(td.getFirst().className).toEqual('span');
+ },
+
+ "should set the style attribute of an Element": function(){
+ var style = 'font-size:12px;line-height:23px;';
+ var div = new Element('div').set('style', style);
+ expect(div.style.lineHeight).toEqual('23px');
+ expect(div.style.fontSize).toEqual('12px');
+ },
+
+ "should set the text of an element": function(){
+ var div = new Element('div').set('text', 'some text content');
+ expect(div.get('text')).toEqual('some text content');
+ expect(div.innerHTML).toEqual('some text content');
+ },
+
+ "should set multiple attributes of an Element": function(){
+ var div = new Element('div').set({ id: 'some_id', 'title': 'some_title', 'html': 'some_content' });
+ expect(div.id).toEqual('some_id');
+ expect(div.title).toEqual('some_title');
+ expect(div.innerHTML).toEqual('some_content');
+ },
+
+ "should set various attributes of a script Element": function(){
+ var script = new Element('script').set({ type: 'text/javascript', defer: 'defer' });
+ expect(script.type).toEqual('text/javascript');
+ expect(script.defer).toBeTruthy();
+ },
+
+ "should set various attributes of a table Element": function(){
+ var table1 = new Element('table').set({ border: '2', cellpadding: '3', cellspacing: '4', align: 'center' });
+ var table2 = new Element('table').set({ cellPadding: '3', cellSpacing: '4' });
+ expect(table1.border == 2).toBeTruthy();
+ expect(table1.cellPadding == 3).toBeTruthy();
+ expect(table2.cellPadding == 3).toBeTruthy();
+ expect(table1.cellSpacing == 4).toBeTruthy();
+ expect(table2.cellSpacing == 4).toBeTruthy();
+ expect(table1.align).toEqual('center');
+ }
+
+});
+
+var myElements = new Elements([
+ new Element('div'),
+ document.createElement('a'),
+ new Element('div', {id: 'el-' + $time()})
+]);
+
+describe('Elements', {
+
+ 'should return an array type': function(){
+ expect(Array.type(myElements)).toBeTruthy();
+ },
+
+ 'should return an array of Elements': function(){
+ expect(myElements.every(Element.type)).toBeTruthy();
+ },
+
+ 'should apply Element prototypes to the returned array': function(){
+ expect($defined(myElements.addEvent)).toBeTruthy();
+ },
+
+ 'should return all Elements that match the string matcher': function(){
+ var filter = myElements.filter('div');
+
+ expect(filter[0] == myElements[0] && filter[1] == myElements[2] && filter.length == 2).toBeTruthy();
+ },
+
+ 'should return all Elements that match the comparator': function(){
+ var elements = myElements.filter(function(element){
+ return element.match('a');
+ });
+ expect(elements[0] == myElements[1] && elements.length == 1).toBeTruthy();
+ }
+
+});
+
+describe('TextNode.constructor', {
+
+ 'should return a new textnode element': function(){
+ var text = document.newTextNode('yo');
+ expect($type(text)).toEqual('textnode');
+ }
+
+});
+
+describe('IFrame constructor', {
+
+ 'should return a new IFrame': function(){
+ var iFrame1 = document.createElement('iframe');
+ var iFrame2 = new IFrame();
+ expect(iFrame1.tagName).toEqual(iFrame2.tagName);
+ },
+
+ 'should return the same IFrame if passed': function(){
+ var iFrame1 = document.createElement('iframe');
+ var iFrame2 = new IFrame(iFrame1);
+ expect(iFrame1).toEqual(iFrame2);
+ }
+
+});
+
+describe('$', {
+
+ 'before all': function(){
+ Container = document.createElement('div');
+ Container.innerHTML = '<div id="dollar"></div>';
+ document.body.appendChild(Container);
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);
+ Container = null;
+ },
+
+ 'should return an extended Element by string id': function(){
+ var dollar1 = document.getElementById('dollar');
+ var dollar2 = $('dollar');
+
+ expect(dollar1).toEqual(dollar2);
+ expect($defined(dollar1.addEvent)).toBeTruthy();
+ },
+
+ 'should return the window if passed': function(){
+ var win = $(window);
+ expect(win == window).toBeTruthy();
+ },
+
+ 'should return the document if passed': function(){
+ expect($(document)).toEqual(document);
+ },
+
+ 'should return null if string not found or type mismatch': function(){
+ expect($(1)).toBeNull();
+ expect($('nonexistant')).toBeNull();
+ }
+
+});
+
+describe('$$', {
+
+ 'should return all Elements of a specific tag': function(){
+ var divs1 = $$('div');
+ var divs2 = new Elements($A(document.getElementsByTagName('div')));
+ expect(divs1).toEqual(divs2);
+ },
+
+ 'should return multiple Elements for each specific tag': function(){
+ var uidOf = (typeof $uid != 'undefined') ? $uid : Slick.uidOf;
+ var sortBy = function(a, b){
+ a = uidOf(a); b = uidOf(b);
+ return a > b ? 1 : -1;
+ };
+ var headers1 = $$('h3', 'h4').sort(sortBy);
+ var headers2 = new Elements(Array.flatten([document.getElementsByTagName('h3'), document.getElementsByTagName('h4')])).sort(sortBy);
+ expect(headers1).toEqual(headers2);
+ },
+
+ 'should return an empty array if not is found': function(){
+ expect($$('not_found')).toEqual(new Elements([]));
+ }
+
+});
+
+describe('getDocument', {
+
+ 'should return the owner document for elements': function(){
+ var doc = document.newElement('div').getDocument();
+ expect(doc).toEqual(document);
+ },
+
+ 'should return the owned document for window': function(){
+ var doc = window.getDocument();
+ expect(doc).toEqual(document);
+ },
+
+ 'should return self for document': function(){
+ var doc = document.getDocument();
+ expect(doc).toEqual(document);
+ }
+
+});
+
+describe('getWindow', {
+
+ 'should return the owner window for elements': function(){
+ var win = document.newElement('div').getWindow();
+ expect(win == window).toBeTruthy();
+ },
+
+ 'should return the owner window for document': function(){
+ var win = document.getWindow();
+ expect(win == window).toBeTruthy();
+ },
+
+ 'should return self for window': function(){
+ var win = window.getWindow();
+ expect(win == window).toBeTruthy();
+ }
+
+});
+
+describe('Element.getElement', {
+
+ 'before all': function(){
+ Container = new Element('div');
+ Container.innerHTML = '<div id="first"></div><div id="second"></div><p></p><a></a>';
+ },
+
+ 'after all': function(){
+ Container = null;
+ },
+
+ 'should return the first Element to match the tag, otherwise null': function(){
+ var child = Container.getElement('div');
+ expect(child.id).toEqual('first');
+ expect(Container.getElement('iframe')).toBeNull();
+ }
+
+});
+
+describe('Element.getElements', {
+
+ 'before all': function(){
+ Container = new Element('div');
+ Container.innerHTML = '<div id="first"></div><div id="second"></div><p></p><a></a>';
+ },
+
+ 'after all': function(){
+ Container = null;
+ },
+
+ 'should return all the elements that match the tag': function(){
+ var children = Container.getElements('div');
+ expect(children.length).toEqual(2);
+ },
+
+ 'should return all the elements that match the tags': function(){
+ var children = Container.getElements('div,a');
+ expect(children.length).toEqual(3);
+ expect(children[2].tagName.toLowerCase()).toEqual('a');
+ }
+
+});
+
+describe('Document.getElement', {
+
+ 'should return the first Element to match the tag, otherwise null': function(){
+ var div = document.getElement('div');
+ var ndiv = document.getElementsByTagName('div')[0];
+ expect(div).toEqual(ndiv);
+
+ var notfound = document.getElement('canvas');
+ expect(notfound).toBeNull();
+ }
+
+});
+
+describe('Document.getElements', {
+
+ 'should return all the elements that match the tag': function(){
+ var divs = document.getElements('div');
+ var ndivs = new Elements(document.getElementsByTagName('div'));
+ expect(divs).toEqual(ndivs);
+ },
+
+ 'should return all the elements that match the tags': function(){
+ var headers = document.getElements('h3,h4');
+ var headers2 = new Elements(Array.flatten([document.getElementsByTagName('h3'), document.getElementsByTagName('h4')]));
+ expect(headers.length).toEqual(headers2.length);
+ }
+
+});
+
+describe('Element.getElementById', {
+
+ 'before all': function(){
+ Container = new Element('div');
+ Container.innerHTML = '<div id="first"></div><div id="second"></div><p></p><a></a>';
+ document.body.appendChild(Container);
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);
+ Container = null;
+ },
+
+ 'should getElementById that matches the id, otherwise null': function(){
+ expect(Container.getElementById('first')).toEqual(Container.childNodes[0]);
+ expect(Container.getElementById('not_found')).toBeNull();
+ }
+
+});
+
+describe('Element.get style', {
+
+ "should return a CSS string representing the Element's styles": function(){
+ var style = 'font-size:12px;color:rgb(255,255,255)';
+ var myElement = new Element('div').set('style', style);
+ expect(myElement.get('style').toLowerCase().replace(/\s/g, '').replace(/;$/, '')).toMatch(/(font-size:12px;color:rgb\(255,255,255\))|(color:rgb\(255,255,255\);font-size:12px)/);
+ //I'm replacing these characters (space and the last semicolon) as they are not vital to the style, and browsers sometimes include them, sometimes not.
+ }
+
+});
+
+describe('Element.get tag', {
+
+ "should return the Element's tag": function(){
+ var myElement = new Element('div');
+ expect(myElement.get('tag')).toEqual('div');
+ }
+
+});
+
+describe('Element.get', {
+
+ "should get an absolute href": function(){
+ var link = new Element('a', {href: "http://google.com/"});
+ expect(link.get('href')).toEqual("http://google.com/");
+ },
+
+ "should get an absolute href to the same domain": function(){
+ var link = new Element('a', {href: window.location.href});
+ expect(link.get('href')).toEqual(window.location.href);
+ },
+
+ "should get a relative href": function(){
+ var link = new Element('a', {href: "../index.html"});
+ expect(link.get('href')).toEqual("../index.html");
+ },
+
+ "should get a host absolute href": function(){
+ var link = new Element('a', {href: "/developers"});
+ expect(link.get('href')).toEqual("/developers");
+ },
+
+ "should return null when attribute is missing": function(){
+ var link = new Element('a');
+ expect(link.get('href')).toBeNull();
+ }
+
+});
+
+describe('Element.erase', {
+
+ "should erase an Element's property": function(){
+ var myElement = new Element('a', {href: 'http://mootools.net/', title: 'mootools!'});
+ expect(myElement.get('title')).toEqual('mootools!');
+ expect(myElement.erase('title').get('title')).toBeNull();
+ },
+
+ "should erase an Element's style": function(){
+ var myElement = new Element('div', {style: "color:rgb(255, 255, 255); font-size:12px;"});
+ myElement.erase('style');
+ expect(myElement.get('style')).toEqual('');
+ }
+
+});
+
+describe('Element.match', {
+
+ 'should return true if tag is not provided': function(){
+ var element = new Element('div');
+ expect(element.match()).toBeTruthy();
+ },
+
+ "should return true if the Element's tag matches": function(){
+ var element = new Element('div');
+ expect(element.match('div')).toBeTruthy();
+ }
+
+});
+
+describe('Element.inject', {
+
+ 'before all': function(){
+ var html = [
+ '<div id="first"></div>',
+ '<div id="second">',
+ '<div id="first-child"></div>',
+ '<div id="second-child"></div>',
+ '</div>'
+ ].join('');
+ Container = new Element('div', {style: 'position:absolute;top:0;left:0;visibility:hidden;', html: html});
+ document.body.appendChild(Container);
+
+ test = new Element('div', {id:'inject-test'});
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);
+ Container.set('html', '');
+ Container = null;
+ test = null;
+ },
+
+ 'should inject the Element before an Element': function(){
+ test.inject($('first'), 'before');
+ expect(Container.childNodes[0]).toEqual(test);
+
+ test.inject($('second-child'), 'before');
+ expect(Container.childNodes[1].childNodes[1]).toEqual(test);
+ },
+
+ 'should inject the Element after an Element': function(){
+ test.inject($('first'), 'after');
+ expect(Container.childNodes[1]).toEqual(test);
+
+ test.inject($('first-child'), 'after');
+ expect(Container.childNodes[1].childNodes[1]).toEqual(test);
+ },
+
+ 'should inject the Element at bottom of an Element': function(){
+ var first = $('first');
+ test.inject(first, 'bottom');
+ expect(first.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ test.inject(second, 'bottom');
+ expect(second.childNodes[2]).toEqual(test);
+
+ test.inject(Container, 'bottom');
+ expect(Container.childNodes[2]).toEqual(test);
+ },
+
+ 'should inject the Element inside an Element': function(){
+ var first = $('first');
+ test.inject(first, 'inside');
+ expect(first.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ test.inject(second, 'inside');
+ expect(second.childNodes[2]).toEqual(test);
+
+ test.inject(Container, 'inside');
+ expect(Container.childNodes[2]).toEqual(test);
+ },
+
+ 'should inject the Element at the top of an Element': function(){
+ test.inject(Container, 'top');
+ expect(Container.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ test.inject(second, 'top');
+ expect(second.childNodes[0]).toEqual(test);
+ },
+
+ 'should inject the Element in an Element': function(){
+ var first = $('first');
+ test.inject(first);
+ expect(first.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ test.inject(second);
+ expect(second.childNodes[2]).toEqual(test);
+
+ test.inject(Container);
+ expect(Container.childNodes[2]).toEqual(test);
+ }
+
+});
+
+describe('Element.replaces', {
+
+ 'should replace an Element with the Element': function(){
+ var parent = new Element('div');
+ var div = new Element('div', {id: 'original'}).inject(parent);
+ var el = new Element('div', {id: 'replaced'});
+ el.replaces(div);
+ expect(parent.childNodes[0]).toEqual(el);
+ }
+
+});
+
+describe('Element.grab', {
+
+ 'before all': function(){
+ var html = [
+ '<div id="first"></div>',
+ '<div id="second">',
+ '<div id="first-child"></div>',
+ '<div id="second-child"></div>',
+ '</div>'
+ ].join('');
+ Container = new Element('div', {style: 'position:absolute;top:0;left:0;visibility:hidden;', html: html}).inject(document.body);
+
+ test = new Element('div', {id:'grab-test'});
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);
+ Container.set('html', '');
+ Container = null;
+ test = null;
+ },
+
+ 'should grab the Element before this Element': function(){
+ $('first').grab(test, 'before');
+ expect(Container.childNodes[0]).toEqual(test);
+
+ $('second-child').grab(test, 'before');
+ expect(Container.childNodes[1].childNodes[1]).toEqual(test);
+ },
+
+ 'should grab the Element after this Element': function(){
+ $('first').grab(test, 'after');
+ expect(Container.childNodes[1]).toEqual(test);
+
+ $('first-child').grab(test, 'after');
+ expect(Container.childNodes[1].childNodes[1]).toEqual(test);
+ },
+
+ 'should grab the Element at the bottom of this Element': function(){
+ var first = $('first');
+ first.grab(test, 'bottom');
+ expect(first.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ second.grab(test, 'bottom');
+ expect(second.childNodes[2]).toEqual(test);
+
+ Container.grab(test, 'bottom');
+ expect(Container.childNodes[2]).toEqual(test);
+ },
+
+ 'should grab the Element inside this Element': function(){
+ var first = $('first');
+ first.grab(test, 'inside');
+ expect(first.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ second.grab(test, 'inside');
+ expect(second.childNodes[2]).toEqual(test);
+
+ Container.grab(test, 'inside');
+ expect(Container.childNodes[2]).toEqual(test);
+ },
+
+ 'should grab the Element at the top of this Element': function(){
+ Container.grab(test, 'top');
+ expect(Container.childNodes[0]).toEqual(test);
+
+ var second = $('second');
+ second.grab(test, 'top');
+ expect(second.childNodes[0]).toEqual(test);
+ },
+
+ 'should grab an Element in the Element': function(){
+ var first = $('first').grab(test);
+ expect(first.childNodes[0]).toEqual(test);
+
+ var second = $('second').grab(test);
+ expect(second.childNodes[2]).toEqual(test);
+
+ Container.grab(test);
+ expect(Container.childNodes[2]).toEqual(test);
+ }
+
+});
+
+describe('Element.wraps', {
+
+ 'should replace and adopt the Element': function(){
+ var div = new Element('div');
+ var child = new Element('p').inject(div);
+
+ var wrapper = new Element('div', {id: 'wrapper'}).wraps(div.childNodes[0]);
+ expect(div.childNodes[0]).toEqual(wrapper);
+ expect(wrapper.childNodes[0]).toEqual(child);
+ }
+
+});
+
+describe('Element.appendText', {
+
+ 'before all': function(){
+ Container = new Element('div', {style: 'position:absolute;top:0;left:0;visibility:hidden;'}).inject(document.body);
+ },
+
+ 'before each': function(){
+ var html = [
+ '<div id="first"></div>',
+ '<div id="second">',
+ '<div id="first-child"></div>',
+ '<div id="second-child"></div>',
+ '</div>'
+ ].join('');
+ Container.set('html', html);
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);
+ Container.set('html', '');
+ Container = null;
+ test = null;
+ },
+
+ 'should append a TextNode before this Element': function(){
+ $('first').appendText('test', 'before');
+ expect(Container.childNodes[0].nodeValue).toEqual('test');
+
+ $('second-child').appendText('test', 'before');
+ expect(Container.childNodes[2].childNodes[1].nodeValue).toEqual('test');
+ },
+
+ 'should append a TextNode the Element after this Element': function(){
+ $('first').appendText('test', 'after');
+ expect(Container.childNodes[1].nodeValue).toEqual('test');
+
+ $('first-child').appendText('test', 'after');
+ expect(Container.childNodes[2].childNodes[1].nodeValue).toEqual('test');
+ },
+
+ 'should append a TextNode the Element at the bottom of this Element': function(){
+ var first = $('first');
+ first.appendText('test', 'bottom');
+ expect(first.childNodes[0].nodeValue).toEqual('test');
+
+ var second = $('second');
+ second.appendText('test', 'bottom');
+ expect(second.childNodes[2].nodeValue).toEqual('test');
+
+ Container.appendText('test', 'bottom');
+ expect(Container.childNodes[2].nodeValue).toEqual('test');
+ },
+
+ 'should append a TextNode the Element inside this Element': function(){
+ var first = $('first');
+ first.appendText('test', 'inside');
+ expect(first.childNodes[0].nodeValue).toEqual('test');
+
+ var second = $('second');
+ second.appendText('test', 'inside');
+ expect(second.childNodes[2].nodeValue).toEqual('test');
+
+ Container.appendText('test', 'inside');
+ expect(Container.childNodes[2].nodeValue).toEqual('test');
+ },
+
+ 'should append a TextNode the Element at the top of this Element': function(){
+ Container.appendText('test', 'top');
+ expect(Container.childNodes[0].nodeValue).toEqual('test');
+
+ var second = $('second');
+ second.appendText('test', 'top');
+ expect(second.childNodes[0].nodeValue).toEqual('test');
+ },
+
+ 'should append a TextNode an Element in the Element': function(){
+ var first = $('first').appendText('test');
+ expect(first.childNodes[0].nodeValue).toEqual('test');
+
+ var second = $('second').appendText('test');
+ expect(second.childNodes[2].nodeValue).toEqual('test');
+
+ Container.appendText('test');
+ expect(Container.childNodes[2].nodeValue).toEqual('test');
+ }
+
+});
+
+describe('Element.adopt', {
+
+ 'before all': function(){
+ Container = new Element('div').inject(document.body);
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);
+ Container.set('html', '');
+ Container = null;
+ },
+
+ 'before each': function(){
+ Container.empty();
+ },
+
+ 'should adopt an Element by its id': function(){
+ var child = new Element('div', {id: 'adopt-me'});
+ document.body.appendChild(child);
+ Container.adopt('adopt-me');
+ expect(Container.childNodes[0]).toEqual(child);
+ },
+
+ 'should adopt an Element': function(){
+ var child = new Element('p');
+ Container.adopt(child);
+ expect(Container.childNodes[0]).toEqual(child);
+ },
+
+ 'should adopt any number of Elements or ids': function(){
+ var children = [];
+ (100).times(function(i){ children[i] = new Element('span', {id: 'child-' + i}); });
+ Container.adopt(children);
+ expect(Container.childNodes.length).toEqual(100);
+ expect(Container.childNodes[10]).toEqual(children[10]);
+ }
+
+});
+
+describe('Element.dispose', {
+
+ 'before all': function(){
+ Container = new Element('div').inject(document.body);
+ },
+
+ 'after all': function(){
+ document.body.removeChild(Container);