Fixed #1095 bug where radio buttons became unchecked during show(). Also added unit...
[jquery.git] / test / unit / core.js
index db47856..96b5d40 100644 (file)
@@ -38,6 +38,27 @@ test("$()", function() {
        equals( div.length, 4, "Correct number of elements generated for div hr code b" );
 });
 
+test("noConflict", function() {
+       expect(6);
+       
+       var old = jQuery;
+       var newjQuery = jQuery.noConflict();
+
+       ok( newjQuery == old, "noConflict returned the jQuery object" );
+       ok( jQuery == old, "Make sure jQuery wasn't touched." );
+       ok( $ == "$", "Make sure $ was reverted." );
+
+       jQuery = $ = old;
+
+       newjQuery = jQuery.noConflict(true);
+
+       ok( newjQuery == old, "noConflict returned the jQuery object" );
+       ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
+       ok( $ == "$", "Make sure $ was reverted." );
+
+       jQuery = $ = old;
+});
+
 test("isFunction", function() {
        expect(21);
 
@@ -123,11 +144,18 @@ test("isFunction", function() {
        });
 });
 
+var foo = false;
+
 test("$('html')", function() {
-       expect(2);
+       expect(4);
        
        reset();
-       ok( $("<script>var foo='test';</script>")[0], "Creating a script" );
+       foo = false;
+       var s = $("<script>var foo='test';</script>")[0];
+       ok( s, "Creating a script" );
+       ok( !foo, "Make sure the script wasn't executed prematurely" );
+       $("body").append(s);
+       ok( foo, "Executing a scripts contents in the right context" );
        
        reset();
        ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
@@ -213,15 +241,17 @@ test("attr(String)", function() {
        ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
 });
 
-test("attr(String) in XML Files", function() {
-       expect(2);
-       stop();
-       $.get("data/dashboard.xml", function(xml) {
-               ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
-               ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
-               start();
-       });
-});
+if ( !isLocal ) {
+    test("attr(String) in XML Files", function() {
+        expect(2);
+        stop();
+        $.get("data/dashboard.xml", function(xml) {
+            ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
+            ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
+            start();
+        });
+    });
+}
 
 test("attr(String, Function)", function() {
        expect(2);
@@ -286,19 +316,21 @@ test("attr(String, Object)", function() {
        equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
 });
 
-test("attr(String, Object) - Loaded via XML document", function() {
-       expect(2);
-       stop();
-       $.get('data/dashboard.xml', function(xml) { 
-               var titles = [];
-               $('tab', xml).each(function() {
-                       titles.push($(this).attr('title'));
-               });
-               ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
-               ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
-               start();
-       });
-});
+if ( !isLocal ) {
+    test("attr(String, Object) - Loaded via XML document", function() {
+        expect(2);
+        stop();
+        $.get('data/dashboard.xml', function(xml) { 
+              var titles = [];
+              $('tab', xml).each(function() {
+                    titles.push($(this).attr('title'));
+              });
+              ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
+              ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
+              start();
+        });
+    });
+}
 
 test("css(String|Hash)", function() {
        expect(19);
@@ -357,6 +389,18 @@ test("css(String, Object)", function() {
        ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
 });
 
+test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
+       expect(4);
+
+       var $checkedtest = $("#checkedtest");
+       // IE6 was clearing "checked" in jQuery.css(elem, "height");
+       jQuery.css($checkedtest[0], "height");
+       ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
+       ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
+       ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
+       ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
+});
+
 test("text()", function() {
        expect(1);
        var expected = "This link has class=\"blog\": Simon Willison's Weblog";
@@ -767,7 +811,7 @@ test("is(String)", function() {
 });
 
 test("$.extend(Object, Object)", function() {
-       expect(10);
+       expect(11);
 
        var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
                options =     { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@@ -775,9 +819,9 @@ test("$.extend(Object, Object)", function() {
                merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
                deep1 = { foo: { bar: true } },
                deep1copy = { foo: { bar: true } },
-               deep2 = { foo: { baz: true } },
-               deep2copy = { foo: { baz: true } },
-               deepmerged = { foo: { bar: true, baz: true } };
+               deep2 = { foo: { baz: true }, foo2: document },
+               deep2copy = { foo: { baz: true }, foo2: document },
+               deepmerged = { foo: { bar: true, baz: true }, foo2: document };
 
        jQuery.extend(settings, options);
        isObj( settings, merged, "Check if extended: settings must be extended" );
@@ -790,6 +834,7 @@ test("$.extend(Object, Object)", function() {
        jQuery.extend(true, deep1, deep2);
        isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
        isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
+       equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
 
        var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
                defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
@@ -813,15 +858,20 @@ test("val()", function() {
 });
 
 test("val(String)", function() {
-       expect(2);
+       expect(3);
        document.getElementById('text1').value = "bla";
        ok( $("#text1").val() == "bla", "Check for modified value of input element" );
        $("#text1").val('test');
        ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
+       
+       $("#select1").val("3");
+       ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
 });
 
+var scriptorder = 0;
+
 test("html(String)", function() {
-       expect(1);
+       expect(9);
        var div = $("div");
        div.html("<b>test</b>");
        var pass = true;
@@ -830,8 +880,15 @@ test("html(String)", function() {
        }
        ok( pass, "Set HTML" );
 
-       // Ccommented out until we can resolve it       
-       // $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>').evalScripts();
+       stop();
+
+       $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
+
+       $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
+
+       $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 0,'Execute before html')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
+
+       setTimeout( start, 100 );
 });
 
 test("filter()", function() {
@@ -1029,11 +1086,13 @@ test("empty()", function() {
 });
 
 test("slice()", function() {
-       expect(4);
+       expect(5);
        isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
        isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
        isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
        isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
+
+       isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
 });
 
 test("map()", function() {