X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2FcoreTest.js;h=928f07e5cc1bea328e79a1f1cc74adc8998b0be5;hb=fbd2b066a71c8c2371e11f7f6b201a9000b564e4;hp=289a41610e9423e85dad837a59264eaf60e4433c;hpb=2ef4093cf7f52383dd43bd361864edcda27e5c3c;p=jquery.git diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index 289a416..928f07e 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -348,20 +348,50 @@ test("wrap(String|Element)", function() { ok( result.text() == defaultText, 'Check for element wrapping' ); reset(); - //stop(); $('#check1').click(function() { var checkbox = this; ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); $(checkbox).wrap( '' ); ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); - // use a fade in to check state after this event handler has finished - /*setTimeout(function() { - ok( !checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); - start(); - }, 100);*/ }).click(); }); +test("wrapAll(String|Element)", function() { + expect(8); + var prev = $("#first")[0].previousSibling; + var p = $("#first")[0].parentNode; + var result = $('#first,#firstp').wrapAll('
'); + equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' ); + ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); + ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); + equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" ); + equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" ); + + reset(); + var prev = $("#first")[0].previousSibling; + var p = $("#first")[0].parentNode; + var result = $('#first,#firstp').wrapAll(document.getElementById('empty')); + equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" ); + equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); + equals( $("#first").parent()[0].parentNode, p, "Correct Parent" ); +}); + +test("wrapInner(String|Element)", function() { + expect(6); + var num = $("#first").children().length; + var result = $('#first').wrapInner('
'); + equals( $("#first").children().length, 1, "Only one child" ); + ok( $("#first").children().is(".red"), "Verify Right Element" ); + equals( $("#first").children().children().children().length, num, "Verify Elements Intact" ); + + reset(); + var num = $("#first").children().length; + var result = $('#first').wrapInner(document.getElementById('empty')); + equals( $("#first").children().length, 1, "Only one child" ); + ok( $("#first").children().is("#empty"), "Verify Right Element" ); + equals( $("#first").children().children().length, num, "Verify Elements Intact" ); +}); + test("append(String|Element|Array<Element>|jQuery)", function() { expect(18); var defaultText = 'Try them out:' @@ -604,6 +634,54 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { ok( expected == $('#en').text(), "Insert jQuery after" ); }); +test("replaceWith(String|Element|Array<Element>|jQuery)", function() { + expect(10); + $('#yahoo').replaceWith('buga'); + ok( $("#replace")[0], 'Replace element with string' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' ); + + reset(); + $('#yahoo').replaceWith(document.getElementById('first')); + ok( $("#first")[0], 'Replace element with element' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' ); + + reset(); + $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]); + ok( $("#first")[0], 'Replace element with array of elements' ); + ok( $("#mark")[0], 'Replace element with array of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); + + reset(); + $('#yahoo').replaceWith($("#first, #mark")); + ok( $("#first")[0], 'Replace element with set of elements' ); + ok( $("#mark")[0], 'Replace element with set of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); +}); + +test("replaceAll(String|Element|Array<Element>|jQuery)", function() { + expect(10); + $('buga').replaceAll("#yahoo"); + ok( $("#replace")[0], 'Replace element with string' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' ); + + reset(); + $(document.getElementById('first')).replaceAll("#yahoo"); + ok( $("#first")[0], 'Replace element with element' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' ); + + reset(); + $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo"); + ok( $("#first")[0], 'Replace element with array of elements' ); + ok( $("#mark")[0], 'Replace element with array of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); + + reset(); + $("#first, #mark").replaceAll("#yahoo"); + ok( $("#first")[0], 'Replace element with set of elements' ); + ok( $("#mark")[0], 'Replace element with set of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); +}); + test("end()", function() { expect(3); ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' ); @@ -680,7 +758,7 @@ test("$.extend(Object, Object)", function() { isObj( settings, merged, "Check if extended: settings must be extended" ); isObj( options, optionsCopy, "Check if not modified: options must not be modified" ); - jQuery.extend(deep1, deep2); + 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" ); @@ -920,3 +998,38 @@ test("eq(), gt(), lt(), contains()", function() { isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" ); isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" ); }); + +test("slice()", function() { + expect(4); + 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)" ); +}); + +test("map()", function() { + expect(2); + + isSet( + $("#ap").map(function(){ + return $(this).find("a").get(); + }), + q("google", "groups", "anchor1", "mark"), + "Array Map" + ); + + isSet( + $("#ap > a").map(function(){ + return this.parentNode; + }), + q("ap","ap","ap"), + "Single Map" + ); +}); + +test("contents()", function() { + expect(3); + equals( $("#ap").contents().length, 9, "Check element contents" ); + ok( $("#iframe").contents()[0], "Check existance of IFrame document" ); + ok( $("#iframe").contents()[0].body, "Check existance of IFrame body" ); +});