Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

script.aculo.us: Finetuning unittest.js + even more unit tests

git-svn-id: http://svn.rubyonrails.org/rails/spinoffs/scriptaculous@2072 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4167d27e6fb68892d4346985c242bcf5864beff2 1 parent a0e9ea7
@madrobby madrobby authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Finetuning unittest.js + even more unit tests
+
* Added support for Firefox and Konqueror automatic unit testing on Linux [Michael Schuerig]
* Added basic unit test files for Effects, updated unit testing tests
View
3  Rakefile
@@ -55,8 +55,9 @@ JavaScriptTestTask.new(:unittest) do |t|
t.run("/test/unit/ajax_inplaceeditor_test.html")
t.run("/test/unit/string_test.html")
t.run("/test/unit/builder_test.html")
- t.run("/test/unit/element_class_test.html")
+ t.run("/test/unit/element_test.html")
t.run("/test/unit/position_clone_test.html")
+ t.run("/test/unit/util_test.html")
t.browser(:safari)
t.browser(:firefox)
View
7 src/unittest.js
@@ -91,7 +91,10 @@ Test.Unit.inspect = function(obj) {
} else {
for(property in obj)
if(typeof obj[property]!="function")
- info.push(property + ' => "' + obj[property] + '"');
+ info.push(property + ' => ' +
+ (typeof obj[property] == "string" ?
+ '"' + obj[property] + '"' :
+ obj[property]));
}
return ("'" + obj + "' #" + typeof obj +
@@ -144,7 +147,7 @@ Test.Unit.Logger.prototype = {
this.loglines = $('loglines');
},
_toHTML: function(txt) {
- return txt.escapeHTML().replace(/\n/,"<br/>");
+ return txt.escapeHTML().replace(/\n/g,"<br/>");
}
}
View
8 src/util.js
@@ -4,13 +4,15 @@
Object.inspect = function(obj) {
var info = [];
- if(typeof obj=="string" ||
- typeof obj=="number") {
+ if(typeof obj in ["string","number"]) {
return obj;
} else {
for(property in obj)
if(typeof obj[property]!="function")
- info.push(property + ' => "' + obj[property] + '"');
+ info.push(property + ' => ' +
+ (typeof obj[property] == "string" ?
+ '"' + obj[property] + '"' :
+ obj[property]));
}
return ("'" + obj + "' #" + typeof obj +
View
92 test/unit/element_class_test.html
@@ -1,92 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>script.aculo.us Unit test file</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script src="../../lib/prototype.js" type="text/javascript"></script>
- <script src="../../src/scriptaculous.js" type="text/javascript"></script>
- <script src="../../src/unittest.js" type="text/javascript"></script>
- <link rel="stylesheet" href="../test.css" type="text/css" />
-</head>
-<body>
-<h1>script.aculo.us Unit test file</h1>
-<p>
- This is a preliminary version mostly for testing the unittest library.
-</p>
-
-<!-- Log output -->
-<div id="testlog"> </div>
-
-<!-- Test elements follow -->
-<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
-
-<div id="test_2" class="classA-foobar classB-foobar"> </div> <span> </span>
-
-<!-- Tests follow -->
-<script type="text/javascript" language="javascript" charset="utf-8">
-// <![CDATA[
-
- new Test.Unit.Runner({
-
- testElementClassHas: function() { with(this) {
- assert(Element.Class.has("test_1","a"));
- assert(Element.Class.has("test_1","dddd"));
- assert(Element.Class.has("test_1","bbbbbbbbbbbb"));
- assert(!Element.Class.has("test_1","bbbbbbbbbbb"));
- assert(!Element.Class.has("test_1","bbbbbbbbbbbbbb"));
-
- assert(Element.Class.has("test_1",["a"]));
- assert(Element.Class.has("test_1",["dddd"]));
- assert(Element.Class.has("test_1",["bbbbbbbbbbbb"]));
- assert(!Element.Class.has("test_1",["bbbbbbbbbbb"]));
- assert(!Element.Class.has("test_1",["bbbbbbbbbbbbbb"]));
-
- assert(!Element.Class.has("test_1",["x","a"]));
- assert(!Element.Class.has("test_1",["x","dddd"]));
- assert(!Element.Class.has("test_1",["x","bbbbbbbbbbbb"]));
- assert(!Element.Class.has("test_1",["x","bbbbbbbbbbb"]));
- assert(!Element.Class.has("test_1",["x","bbbbbbbbbbbbbb"]));
-
- assert(Element.Class.has("test_1",["a","a"]));
- assert(Element.Class.has("test_1",["a","dddd"]));
- assert(Element.Class.has("test_1",["a","bbbbbbbbbbbb"]));
- assert(!Element.Class.has("test_1",["a","bbbbbbbbbbb"]));
- assert(!Element.Class.has("test_1",["a","bbbbbbbbbbbbbb"]));
-
- assert(Element.Class.has("test_2","classA-foobar"));
- assert(Element.Class.has("test_2","classB-foobar"));
- assert(!Element.Class.has("test_2","classA"));
- }},
-
- testElementClassHasAny: function() { with(this) {
- assert(Element.Class.has_any("test_1","a"));
- assert(Element.Class.has_any("test_1","dddd"));
- assert(Element.Class.has_any("test_1","bbbbbbbbbbbb"));
- assert(!Element.Class.has_any("test_1","bbbbbbbbbbb"));
- assert(!Element.Class.has_any("test_1","bbbbbbbbbbbbbb"));
-
- assert(Element.Class.has_any("test_1",["a"]));
- assert(Element.Class.has_any("test_1",["dddd"]));
- assert(Element.Class.has_any("test_1",["bbbbbbbbbbbb"]));
- assert(!Element.Class.has_any("test_1",["bbbbbbbbbbb"]));
- assert(!Element.Class.has_any("test_1",["bbbbbbbbbbbbbb"]));
-
- assert(Element.Class.has_any("test_1",["x","a"]));
- assert(Element.Class.has_any("test_1",["x","dddd"]));
- assert(Element.Class.has_any("test_1",["x","bbbbbbbbbbbb"]));
- assert(!Element.Class.has_any("test_1",["x","bbbbbbbbbbb"]));
- assert(!Element.Class.has_any("test_1",["x","bbbbbbbbbbbbbb"]));
-
- assert(Element.Class.has_any("test_1",["a","a"]));
- assert(Element.Class.has_any("test_1",["a","dddd"]));
- assert(Element.Class.has_any("test_1",["a","bbbbbbbbbbbb"]));
- assert(Element.Class.has_any("test_1",["a","bbbbbbbbbbb"]));
- assert(Element.Class.has_any("test_1",["a","bbbbbbbbbbbbbb"]));
- }}
-
- }, "testlog");
-// ]]>
-</script>
-</body>
-</html>
View
144 test/unit/element_test.html
@@ -0,0 +1,144 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>script.aculo.us Unit test file</title>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <script src="../../lib/prototype.js" type="text/javascript"></script>
+ <script src="../../src/scriptaculous.js" type="text/javascript"></script>
+ <script src="../../src/unittest.js" type="text/javascript"></script>
+ <link rel="stylesheet" href="../test.css" type="text/css" />
+ <style type="text/css" media="screen">
+ #style_test_1 { color:rgb(0, 0, 255); background-color: rgb(0, 0, 255); }
+ blah { color:rgb(0, 255, 0); }
+ </style>
+</head>
+<body>
+<h1>script.aculo.us Unit test file</h1>
+<p>
+ Test element extensions
+</p>
+
+<!-- Log output -->
+<div id="testlog"> </div>
+
+<!-- Test elements follow -->
+<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
+
+<div id="test_2" class="classA-foobar classB-foobar"> </div> <span> </span>
+
+<div id="style_test_1" style="display:none;"></div>
+<div id="style_test_2" class="blah" style="font-size:11px;"></div>
+
+<div id="test_whitespace"> <span> </span>
+
+
+
+<div><div></div> </div><span> </span>
+</div>
+
+<!-- Tests follow -->
+<script type="text/javascript" language="javascript" charset="utf-8">
+// <![CDATA[
+
+ new Test.Unit.Runner({
+
+ testElementGetStyle: function() { with(this) {
+ assertEqual("none",
+ Element.getStyle('style_test_1','display'));
+ // not displayed, so "null" ("auto" is tranlated to "null")
+ assertNull(Element.getStyle('style_test_1','width'));
+ assertEqual("static",Element.getStyle('style_test_1','position'), "Note: Safari bug! (see http://bugzilla.opendarwin.org/show_bug.cgi?id=4125)");
+ // from id rule
+ assertEqual("rgb(0, 0, 255)",
+ Element.getStyle('style_test_1','color'));
+ assertEqual("rgb(0, 0, 255)",
+ Element.getStyle('style_test_1','background-color'));
+
+ assertEqual("block",
+ Element.getStyle('style_test_2','display'));
+ assertNotNull(Element.getStyle('style_test_2','width'));
+ assertEqual("static",Element.getStyle('style_test_1','position'));
+ // from style
+ assertEqual("11px",
+ Element.getStyle('style_test_2','font-size'));
+ // from class
+ assertEqual("rgb(0, 0, 255)",
+ Element.getStyle('style_test_1','background-color'));
+ }},
+
+ testElementCleanWhitespace: function() { with(this) {
+ Element.cleanWhitespace("test_whitespace");
+ assertEqual(3, $("test_whitespace").childNodes.length);
+
+ assertEqual(1, $("test_whitespace").firstChild.nodeType);
+ assertEqual('SPAN', $("test_whitespace").firstChild.tagName);
+
+ assertEqual(1, $("test_whitespace").firstChild.nextSibling.nodeType);
+ assertEqual('DIV', $("test_whitespace").firstChild.nextSibling.tagName);
+
+ assertEqual(1, $("test_whitespace").firstChild.nextSibling.nextSibling.nodeType);
+ assertEqual('SPAN', $("test_whitespace").firstChild.nextSibling.nextSibling.tagName);
+ }},
+
+ testElementClassHas: function() { with(this) {
+ assert(Element.Class.has("test_1","a"));
+ assert(Element.Class.has("test_1","dddd"));
+ assert(Element.Class.has("test_1","bbbbbbbbbbbb"));
+ assert(!Element.Class.has("test_1","bbbbbbbbbbb"));
+ assert(!Element.Class.has("test_1","bbbbbbbbbbbbbb"));
+
+ assert(Element.Class.has("test_1",["a"]));
+ assert(Element.Class.has("test_1",["dddd"]));
+ assert(Element.Class.has("test_1",["bbbbbbbbbbbb"]));
+ assert(!Element.Class.has("test_1",["bbbbbbbbbbb"]));
+ assert(!Element.Class.has("test_1",["bbbbbbbbbbbbbb"]));
+
+ assert(!Element.Class.has("test_1",["x","a"]));
+ assert(!Element.Class.has("test_1",["x","dddd"]));
+ assert(!Element.Class.has("test_1",["x","bbbbbbbbbbbb"]));
+ assert(!Element.Class.has("test_1",["x","bbbbbbbbbbb"]));
+ assert(!Element.Class.has("test_1",["x","bbbbbbbbbbbbbb"]));
+
+ assert(Element.Class.has("test_1",["a","a"]));
+ assert(Element.Class.has("test_1",["a","dddd"]));
+ assert(Element.Class.has("test_1",["a","bbbbbbbbbbbb"]));
+ assert(!Element.Class.has("test_1",["a","bbbbbbbbbbb"]));
+ assert(!Element.Class.has("test_1",["a","bbbbbbbbbbbbbb"]));
+
+ assert(Element.Class.has("test_2","classA-foobar"));
+ assert(Element.Class.has("test_2","classB-foobar"));
+ assert(!Element.Class.has("test_2","classA"));
+ }},
+
+ testElementClassHasAny: function() { with(this) {
+ assert(Element.Class.has_any("test_1","a"));
+ assert(Element.Class.has_any("test_1","dddd"));
+ assert(Element.Class.has_any("test_1","bbbbbbbbbbbb"));
+ assert(!Element.Class.has_any("test_1","bbbbbbbbbbb"));
+ assert(!Element.Class.has_any("test_1","bbbbbbbbbbbbbb"));
+
+ assert(Element.Class.has_any("test_1",["a"]));
+ assert(Element.Class.has_any("test_1",["dddd"]));
+ assert(Element.Class.has_any("test_1",["bbbbbbbbbbbb"]));
+ assert(!Element.Class.has_any("test_1",["bbbbbbbbbbb"]));
+ assert(!Element.Class.has_any("test_1",["bbbbbbbbbbbbbb"]));
+
+ assert(Element.Class.has_any("test_1",["x","a"]));
+ assert(Element.Class.has_any("test_1",["x","dddd"]));
+ assert(Element.Class.has_any("test_1",["x","bbbbbbbbbbbb"]));
+ assert(!Element.Class.has_any("test_1",["x","bbbbbbbbbbb"]));
+ assert(!Element.Class.has_any("test_1",["x","bbbbbbbbbbbbbb"]));
+
+ assert(Element.Class.has_any("test_1",["a","a"]));
+ assert(Element.Class.has_any("test_1",["a","dddd"]));
+ assert(Element.Class.has_any("test_1",["a","bbbbbbbbbbbb"]));
+ assert(Element.Class.has_any("test_1",["a","bbbbbbbbbbb"]));
+ assert(Element.Class.has_any("test_1",["a","bbbbbbbbbbbbbb"]));
+ }}
+
+ }, "testlog");
+// ]]>
+</script>
+</body>
+</html>
View
3  test/unit/index.html
@@ -38,8 +38,9 @@
<ul>
<li><a href="builder_test.html" target="test">Builder test</a></li>
<li><a href="string_test.html" target="test">String test</a></li>
- <li><a href="element_class_test.html" target="test">Element.Class test</a></li>
+ <li><a href="element_test.html" target="test">Element extensions test</a></li>
<li><a href="position_clone_test.html" target="test">Position.clone test</a></li>
+ <li><a href="util_test.html" target="test">Other util.js methods</a></li>
</ul>
<h2>effects.js</h2>
View
16 test/unit/unittest_test.html
@@ -61,7 +61,7 @@
assertNotEqual([],{});
}},
- testAssertIntanceOf: function() { with(this) {
+ testAssertInstanceOf: function() { with(this) {
assertInstanceOf(Effect.Opacity, new Effect.Opacity('testcss1',{sync:true}));
assertNotInstanceOf(String, new Effect.Opacity('testcss1',{sync:true}));
@@ -69,11 +69,6 @@
assertNotInstanceOf(Effect.Parallel, new Effect.Opacity('testcss1',{sync:true}), "(note: fails with firefox 1.0.X, fixed in Deer Park)");
}},
- testElementCleanWhitespace: function() { with(this) {
- Element.cleanWhitespace("test_2");
- assertEqual(1,$("test_2").firstChild.nodeType);
- }},
-
testSortableCreate: function() { with(this) {
assertEqual(0,Draggables.observers.length);
@@ -99,15 +94,6 @@
effect.render(1.0);
assertEqual(100, parseFloat($("testmoveby").style.top));
assertEqual(10, parseFloat($("testmoveby").style.left));
- }},
-
- testElementGetStyle: function() { with(this) {
- assertEqual("11px", Element.getStyle('testcss1','font-size'));
- assertEqual("rgb(255, 0, 0)", Element.getStyle('testcss1','color'));
-
- // fail on safari
- assertEqual("12px", Element.getStyle('testcss2','font-size'));
- assertEqual("rgb(0, 255, 0)", Element.getStyle('testcss2','color'));
}}
}, "testlog");
View
54 test/unit/util_test.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>script.aculo.us Unit test file</title>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <script src="../../lib/prototype.js" type="text/javascript"></script>
+ <script src="../../src/scriptaculous.js" type="text/javascript"></script>
+ <script src="../../src/unittest.js" type="text/javascript"></script>
+ <link rel="stylesheet" href="../test.css" type="text/css" />
+ <style type="text/css" media="screen">
+ /* <![CDATA[ */
+ #testcss1 { font-size:11px; color: #f00; }
+ #testcss2 { font-size:12px; color: #0f0; display: none; }
+ /* ]]> */
+ </style>
+</head>
+<body>
+<h1>script.aculo.us Unit test file</h1>
+<p>
+ Test of utility functions in util.js
+</p>
+
+<!-- Log output -->
+<div id="testlog"> </div>
+
+<!-- Tests follow -->
+<script type="text/javascript" language="javascript" charset="utf-8">
+// <![CDATA[
+
+ new Test.Unit.Runner({
+
+ testObjectInspect: function() { with(this) {
+ assertEqual("'[object Object]' #object: {}",
+ Object.inspect({}));
+ assertEqual("'[object Object]' #object: {}",
+ Object.inspect({x:function(){}}));
+ assertEqual("'[object Object]' #object: {x => \"test\"}",
+ Object.inspect({x:"test"}));
+ assertEqual("'[object Object]' #object: {x => \"test\", y => 123}",
+ Object.inspect({x:"test",y:123}));
+ assertEqual("'[object Object]' #object: {x => [object Object]}",
+ Object.inspect({x:{}}));
+ assertEqual("'[object Object]' #object: {x => \"test\", y => [object Object]}",
+ Object.inspect({x:"test",y:{}}));
+ assertEqual("'[object Object]' #object: {x => \"test\", y => [object Object]}",
+ Object.inspect({x:"test",y:{z:"test",blah:{}}}));
+ }}
+
+ }, "testlog");
+// ]]>
+</script>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.