Fixes #8129. Fix cloning multiple selected options in IE8.
[jquery.git] / test / unit / manipulation.js
index de84144..1313783 100644 (file)
@@ -402,7 +402,7 @@ test("append(Function) with incoming value", function() {
 });
 
 test("append the same fragment with events (Bug #6997, 5566)", function () {
-       expect(4 + (document.fireEvent ? 1 : 0));
+       expect(2 + (document.fireEvent ? 1 : 0));
        stop(1000);
 
        var element;
@@ -437,14 +437,6 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
 
        jQuery("#listWithTabIndex li").before(element);
        jQuery("#listWithTabIndex li.test6997").eq(1).click();
-
-       element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
-
-       equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
-
-       element = jQuery("<input type='checkbox'>").attr('checked', 'checked');
-
-       equals( element.clone().is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
 });
 
 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@@ -879,6 +871,31 @@ test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
        ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
 });
 
+test("jQuery.clone() (#8017)", function() {
+
+       expect(2);
+
+       ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function.");
+
+       var main = jQuery("#main")[0],
+                       clone = jQuery.clone( main );
+
+       equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
+});
+
+test("clone() (#8070)", function () {
+       expect(2);
+
+       jQuery('<select class="test8070"></select><select class="test8070"></select>').appendTo('#main');
+       var selects = jQuery('.test8070');
+       selects.append('<OPTION>1</OPTION><OPTION>2</OPTION>');
+
+       equals( selects[0].childNodes.length, 2, "First select got two nodes" );
+       equals( selects[1].childNodes.length, 2, "Second select got two nodes" );
+
+       selects.remove();
+});
+
 test("clone()", function() {
        expect(37);
        equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
@@ -936,6 +953,17 @@ test("clone()", function() {
        div.remove();
        clone.remove();
 
+       var divEvt = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
+               ok( false, "Bound event still exists after .clone()." );
+       }),
+               cloneEvt = divEvt.clone();
+
+       // Make sure that doing .clone() doesn't clone events
+       cloneEvt.trigger("click");
+
+       cloneEvt.remove();
+       divEvt.remove();
+
        // this is technically an invalid object, but because of the special
        // classid instantiation it is the only kind that IE has trouble with,
        // so let's test with it too.
@@ -976,6 +1004,36 @@ test("clone()", function() {
        equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
 });
 
+test("clone(form element) (Bug #3879, #6655)", function() {
+       expect(6);
+       var element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
+
+       equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
+
+       element = jQuery("<input type='checkbox' value='foo'>").attr('checked', 'checked');
+       clone = element.clone();
+
+       equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
+       equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
+       equals( clone[0].defaultChecked, !jQuery.support.noCloneEvent, "Checked input defaultChecked cloned correctly" );
+
+       element = jQuery("<input type='text' value='foo'>");
+       clone = element.clone();
+       equals( clone[0].defaultValue, "foo", "Text input defaultValue cloned correctly" );
+
+       element = jQuery("<textarea>foo</textarea>");
+       clone = element.clone();
+       equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
+});
+
+test("clone(multiple selected options) (Bug #8129)", function() {
+       expect(1);
+       var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>");
+
+       equals( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
+
+});
+
 if (!isLocal) {
 test("clone() on XML nodes", function() {
        expect(2);