Skip to content

Commit

Permalink
script.aculo.us: Finetuning unittest.js + even more unit tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.rubyonrails.org/rails/spinoffs/scriptaculous@2072 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
madrobby committed Aug 30, 2005
1 parent a0e9ea7 commit 4167d27
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 114 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down Expand Up @@ -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/>");
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
92 changes: 0 additions & 92 deletions test/unit/element_class_test.html

This file was deleted.

144 changes: 144 additions & 0 deletions test/unit/element_test.html
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 2 additions & 1 deletion test/unit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ <h2>util.js</h2>
<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>
Expand Down
16 changes: 1 addition & 15 deletions test/unit/unittest_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,14 @@ <h1>script.aculo.us Unit test file</h1>
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}));

// note: fails with firefox 1.0.X (bug, fixed in Deer Park)
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);

Expand All @@ -99,15 +94,6 @@ <h1>script.aculo.us Unit test file</h1>
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");
Expand Down
Loading

0 comments on commit 4167d27

Please sign in to comment.