-test("val()", function() {
- expect(4);
- ok( $("#text1").val() == "Test", "Check for value of input element" );
- ok( !$("#text1").val() == "", "Check for value of input element" );
- // ticket #1714 this caused a JS error in IE
- ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
- ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
-});
-
-test("val(String)", function() {
- expect(4);
- 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" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = $("#nonnodes").contents();
- j.val("asdf");
- equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
- j.removeAttr("value");
-});
-
-var scriptorder = 0;
-
-test("html(String)", function() {
- expect(11);
- var div = $("#main > div");
- div.html("<b>test</b>");
- var pass = true;
- for ( var i = 0; i < div.size(); i++ ) {
- if ( div.get(i).childNodes.length != 1 ) pass = false;
- }
- ok( pass, "Set HTML" );
-
- reset();
- // using contents will get comments regular, text, and comment nodes
- var j = $("#nonnodes").contents();
- j.html("<b>bold</b>");
- equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
-
- $("#main").html("<select/>");
- $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
- equals( $("#main select").val(), "O2", "Selected option correct" );
-
- 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>');
-
- // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
- $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script (nested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script (unnested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
-
- setTimeout( start, 100 );
-});
-
-test("filter()", function() {
- expect(6);
- isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
- isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
- isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
- isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = $("#nonnodes").contents();
- equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
- equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
-});
-
-test("not()", function() {
- expect(8);
- ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
- ok( $("#main > p#ap > a").not(document.getElementById("google")).length == 2, "not(DOMElement)" );
- isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
- isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
- isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
- ok( $("p").not(document.getElementsByTagName("p")).length == 0, "not(Array-like DOM collection)" );
- isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
-
- var selects = $("#form select");
- isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
-});
-
-test("andSelf()", function() {
- expect(4);
- isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
- isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
- isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
- isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
-});
-
-test("siblings([String])", function() {
- expect(5);
- isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
- isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
- isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
- isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
- isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
-});
-
-test("children([String])", function() {
- expect(3);
- isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
- isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
- isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
-});
-
-test("parent([String])", function() {
- expect(5);
- ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
- ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
- ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
- ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
- isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
-});
-
-test("parents([String])", function() {
- expect(5);
- ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
- ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
- ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
- isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
- isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
-});
-
-test("next([String])", function() {
- expect(4);
- ok( $("#ap").next()[0].id == "foo", "Simple next check" );
- ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
- ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
- ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
-});
-
-test("prev([String])", function() {
- expect(4);
- ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
- ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
- ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
- ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
-});
-
-test("show()", function() {
- expect(15);
- var pass = true, div = $("div");
- div.show().each(function(){
- if ( this.style.display == "none" ) pass = false;
- });
- ok( pass, "Show" );
-
- $("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
- var test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : $.browser.msie ? "block" : "table",
- "thead" : $.browser.msie ? "block" : "table-header-group",
- "tbody" : $.browser.msie ? "block" : "table-row-group",
- "tr" : $.browser.msie ? "block" : "table-row",
- "th" : $.browser.msie ? "block" : "table-cell",
- "td" : $.browser.msie ? "block" : "table-cell",
- "ul" : "block",
- "li" : $.browser.msie ? "block" : "list-item"
- };
-
- $.each(test, function(selector, expected) {
- var elem = $(selector, "#show-tests").show();
- equals( elem.css("display"), expected, "Show using correct display type for " + selector );