jquery/build/test/tests/basic.html
2006-08-13 20:01:26 +00:00

87 lines
2.2 KiB
HTML

<html id="html">
<head>
<script type="text/javascript" src="../lib/Test/Builder.js"></script>
<script type="text/javascript" src="../lib/Test/More.js"></script>
<script type="text/javascript" src="../lib/test.js"></script>
<script type="text/javascript" src="../../jquery/jquery-svn.js"></script>
</head>
<body id="body">
<h1>Basic Usage</h1>
<!-- Test HTML -->
<div id="main" style="display: none;"></div>
<div id="foo" style="display: none;"></div>
<pre id="test"><script>
plan({tests: 11});
var div = $("div");
diag( "Getters" );
cmpOK( div.size(), "==", 2, "Get Number of Elements Found" );
isSet( div.get(), q("main","foo"), "Get All Elements" );
cmpOK( div.get(0), "==", document.getElementById("main"),
"Get A Single Element" );
diag( "Setters" );
div.each(function(){this.foo = 'zoo';});
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "zoo" ) pass = false;
}
ok( pass, "Execute, Relative" );
div.addClass("test");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
}
ok( pass, "Add Class" );
div.removeClass("test");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
}
ok( pass, "Remove Class" );
div.html("<b>test</b>");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).childNodes.length == 0 ) pass = false;
}
ok( pass, "Set HTML" );
div.attr("foo", "bar");
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "bar" ) pass = false;
}
ok( pass, "Set Attribute" );
div.attr({foo: 'baz', zoo: 'ping'});
var pass = true;
for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "baz" && div.get(i).zoo != "ping" ) pass = false;
}
ok( pass, "Set Multiple Attributes" );
diag( "Effects" );
var pass = true;
div.show().each(function(){
if ( this.style.display == "none" ) pass = false;
});
ok( pass, "Show" );
var pass = true;
div.hide().each(function(){
if ( this.style.display != "none" ) pass = false;
});
ok( pass, "Hide" );
</script></pre>
</body>
</html>