Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (90 sloc) 4.04 kb
c49a20c mkkk
kangax authored
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6
7 <title>helpers.js test file</title>
8
9 <link rel="stylesheet" href="../lib/test.css" type="text/css" />
10
11 <script src="../lib/prototype.js" type="text/javascript"></script>
12 <script src="../lib/unittest.js" type="text/javascript"></script>
13 <script src="../function.extensions.js" type="text/javascript"></script>
14
15 </head>
16 <body>
17 <div id="testlog"></div>
18 <div id="dummy">foo</div>
d873964 more unit tests
kangax authored
19 <div id="runOnceDummy"></div>
8abdc3a More tests, minor changes
kangax authored
20 <div id="addAdviceDummy"></div>
c49a20c mkkk
kangax authored
21
22 <script type="text/javascript">
23 new Test.Unit.Runner({
add9d35 Add Element#wrapContent
kangax authored
24 testFunctionPrototypeNot: function() {
c49a20c mkkk
kangax authored
25
26 var truthy = function() { return true; };
27 var falsy = function() { return false; };
28 var something = function() { return {foo: 'bar'} };
29
30 this.assert(truthy());
add9d35 Add Element#wrapContent
kangax authored
31 this.assert(!truthy.not()());
c49a20c mkkk
kangax authored
32 this.assert(!falsy());
add9d35 Add Element#wrapContent
kangax authored
33 this.assert(falsy.not()());
c49a20c mkkk
kangax authored
34 },
35
d873964 more unit tests
kangax authored
36 testFunctionPrototypeRunOnce: function() {
37 function updater(){
38 $('runOnceDummy').update('foo');
39 };
40 this.assertIdentical('', $('runOnceDummy').innerHTML); // contents should be empty
41 this.assertIdentical('function', typeof updater.runOnce()); // should return function
42 this.assertIdentical('foo', $('runOnceDummy').innerHTML); // should update content when run
43 },
44
8abdc3a More tests, minor changes
kangax authored
45 testFunctionPrototype_New: function() {
d873964 more unit tests
kangax authored
46 var Person = Class.create({
47 initialize: function(name) { this.name = name },
48 speak: function(message) { return this.name + ': ' + message }
49 })
50 var jd = Person._new('John');
51 this.assert(jd instanceof Person);
52 this.assertIdentical('John', jd.name);
53 this.assertIdentical('John: hi there', jd.speak('hi there'));
54 },
55
56 testFunctionPrototypeToDelayed: function() {
57 var delayed = (function(){
58 $('dummy').addClassName('foo');
59 }).toDelayed(1);
60
61 delayed();
62 this.assert(!$('dummy').hasClassName('foo'));
63 this.wait(1000, (function(){
64 this.assert($('dummy').hasClassName('foo'));
65 }).bind(this))
66 },
67
c49a20c mkkk
kangax authored
68 testFunctionK: function() {
69 this.assert(Function.K(true)());
70 this.assert(!Function.K(false)());
71 this.assertEqual('foo', Function.K('foo')());
72
73 var source = { foo: 'bar', baz: 'qux' }, dest = { };
74 // "prop" variable should NOT be shared via closure
75 for (var prop in source) {
76 dest[prop] = Function.K(prop);
77 }
78
79 this.assertEqual('foo', dest.foo());
80 this.assertEqual('baz', dest.baz());
8abdc3a More tests, minor changes
kangax authored
81 },
82
83 testFunctionPrototypeAddAdvice: function() {
84 Element.addMethods({
85 addClassName: Element.Methods.addClassName.addAdvice({
86 before: function(element, className) {
87 // when passed 'draggable' to addClassName, set element's position to 'absolute'
88 if (className == 'draggable')
89 $(element).absolutize();
90 }
91 })
92 });
93 // should not be "absolute" initially
94 this.assertNotEqual('absolute', $('addAdviceDummy').getStyle('position'));
95 Element.addClassName('addAdviceDummy', 'foo');
96 // should not be "absolute" after assigning "foo" className
97 this.assertNotEqual('absolute', $('addAdviceDummy').getStyle('position'));
98 Element.addClassName('addAdviceDummy', 'draggable');
99 // should be "absolute" after assigning "draggable" className
100 this.assertEqual('absolute', $('addAdviceDummy').getStyle('position'));
c49a20c mkkk
kangax authored
101 }
102
103 })
104 </script>
105
106 </body>
107 </html>
Something went wrong with that request. Please try again.