ok( $, "$()" );\r
});\r
\r
+test("$()", function() {\r
+ var main = $("#main");\r
+ isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );\r
+ \r
+ // make sure this is handled\r
+ $('<p>\r\n</p>');\r
+});\r
+\r
test("length", function() {\r
ok( $("div").length == 2, "Get Number of Elements Found" );\r
});\r
ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );\r
});\r
\r
+test("add(String|Element|Array)", function() {\r
+ isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );\r
+ isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );\r
+ ok( $([]).add($("#form")[0].elements).length > 13, "Check elements from array" );\r
+ \r
+ var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));\r
+ ok( x[0].id == "x1", "Check on-the-fly element1" );\r
+ ok( x[1].id == "x2", "Check on-the-fly element2" );\r
+ \r
+ var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");\r
+ ok( x[0].id == "x1", "Check on-the-fly element1" );\r
+ ok( x[1].id == "x2", "Check on-the-fly element2" );\r
+});\r
+\r
test("each(Function)", function() {\r
expect(1);\r
var div = $("div");\r
});\r
\r
test("attr(String)", function() {\r
- expect(12);\r
+ expect(15);\r
ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );\r
ok( $('#text1').attr('type') == "text", 'Check for type attribute' );\r
ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );\r
ok( $('#name').attr('name') == "name", 'Check for name attribute' );\r
ok( $('#text1').attr('name') == "action", 'Check for name attribute' );\r
ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );\r
+ \r
+ $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path\r
+ ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );\r
+ \r
+ stop();\r
+ $.get("data/dashboard.xml", function(xml) {\r
+ ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );\r
+ ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );\r
+ start();\r
+ });\r
+});\r
+\r
+test("attr(String, Function)", function() {\r
+ expect(2);\r
+ ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );\r
+ ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");\r
});\r
\r
test("attr(Hash)", function() {\r
});\r
\r
test("attr(String, Object)", function() {\r
- expect(6);\r
+ expect(7);\r
var div = $("div");\r
div.attr("foo", "bar");\r
var pass = true;\r
if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;\r
}\r
ok( pass, "Set Attribute" );\r
+\r
+ ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" ); \r
\r
$("#name").attr('name', 'something');\r
- ok( $("#name").name() == 'something', 'Set name attribute' );\r
+ ok( $("#name").attr('name') == 'something', 'Set name attribute' );\r
$("#check2").attr('checked', true);\r
ok( document.getElementById('check2').checked == true, 'Set checked attribute' );\r
$("#check2").attr('checked', false);\r
ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );\r
});\r
\r
-test("attr(String, Object)x", function() {\r
- expect(2);\r
- stop();\r
- $.get('data/dashboard.xml', function(xml) { \r
- var titles = [];\r
- $('tab', xml).each(function() {\r
- titles.push($(this).attr('title'));\r
- });\r
- ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );\r
- ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );\r
- start();\r
+if ( location.protocol != "file:" ) {\r
+ test("attr(String, Object)x", function() {\r
+ expect(2);\r
+ stop();\r
+ $.get('data/dashboard.xml', function(xml) { \r
+ var titles = [];\r
+ $('tab', xml).each(function() {\r
+ titles.push($(this).attr('title'));\r
+ });\r
+ ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );\r
+ ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );\r
+ start();\r
+ });\r
});\r
-});\r
+}\r
\r
test("css(String|Hash)", function() {\r
expect(8);\r
ok( result.text() == defaultText, 'Check for element wrapping' );\r
});\r
\r
-test("append(String|Element|Array<Element>)", function() {\r
- expect(4);\r
+test("append(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(11);\r
var defaultText = 'Try them out:'\r
var result = $('#first').append('<b>buga</b>');\r
ok( result.text() == defaultText + 'buga', 'Check if text appending works' );\r
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
$('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);\r
ok( expected == $('#sap').text(), "Check for appending of array of elements" );\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
+ $('#sap').append($("#first, #yahoo"));\r
+ ok( expected == $('#sap').text(), "Check for appending of jQuery object" );\r
+\r
+ reset();\r
+ $("#sap").append( 5 );\r
+ ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );\r
+\r
+ reset();\r
+ $("#sap").append( " text with spaces " );\r
+ ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );\r
+\r
+ reset();\r
+ ok( $("#sap").append([]), "Check for appending an empty array." );\r
+ ok( $("#sap").append(""), "Check for appending an empty string." );\r
+ ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );\r
+ \r
+ reset();\r
+ $("#sap").append(document.getElementById('form'));\r
+ ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910\r
+ \r
});\r
\r
-test("prepend(String|Element|Array<Element>)", function() {\r
- expect(4);\r
+test("appendTo(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(5);\r
+ var defaultText = 'Try them out:'\r
+ $('<b>buga</b>').appendTo('#first');\r
+ ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );\r
+ ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";\r
+ $(document.getElementById('first')).appendTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for appending of element" );\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
+ $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for appending of array of elements" );\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
+ $("#first, #yahoo").appendTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for appending of jQuery object" );\r
+});\r
+\r
+test("prepend(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(5);\r
var defaultText = 'Try them out:'\r
var result = $('#first').prepend('<b>buga</b>');\r
ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );\r
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
$('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);\r
ok( expected == $('#sap').text(), "Check for prepending of array of elements" );\r
+ \r
+ reset();\r
+ expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
+ $('#sap').prepend($("#first, #yahoo"));\r
+ ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );\r
});\r
\r
-test("before(String|Element|Array<Element>)", function() {\r
- expect(3);\r
+test("prependTo(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(5);\r
+ var defaultText = 'Try them out:'\r
+ $('<b>buga</b>').prependTo('#first');\r
+ ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );\r
+ ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');\r
+ \r
+ reset();\r
+ expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";\r
+ $(document.getElementById('first')).prependTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for prepending of element" );\r
+\r
+ reset();\r
+ expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
+ $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for prepending of array of elements" );\r
+ \r
+ reset();\r
+ expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
+ $("#yahoo, #first").prependTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );\r
+});\r
+\r
+test("before(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(4);\r
var expected = 'This is a normal link: bugaYahoo';\r
$('#yahoo').before('<b>buga</b>');\r
ok( expected == $('#en').text(), 'Insert String before' );\r
expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
$('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);\r
ok( expected == $('#en').text(), "Insert array of elements before" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
+ $('#yahoo').before($("#first, #mark"));\r
+ ok( expected == $('#en').text(), "Insert jQuery before" );\r
});\r
\r
-test("after(String|Element|Array<Element>)", function() {\r
- expect(3);\r
+test("insertBefore(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(4);\r
+ var expected = 'This is a normal link: bugaYahoo';\r
+ $('<b>buga</b>').insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), 'Insert String before' );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:Yahoo";\r
+ $(document.getElementById('first')).insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert element before" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
+ $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert array of elements before" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
+ $("#first, #mark").insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert jQuery before" );\r
+});\r
+\r
+test("after(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(4);\r
var expected = 'This is a normal link: Yahoobuga';\r
$('#yahoo').after('<b>buga</b>');\r
ok( expected == $('#en').text(), 'Insert String after' );\r
expected = "This is a normal link: YahooTry them out:diveintomark";\r
$('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);\r
ok( expected == $('#en').text(), "Insert array of elements after" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:diveintomark";\r
+ $('#yahoo').after($("#first, #mark"));\r
+ ok( expected == $('#en').text(), "Insert jQuery after" );\r
+});\r
+\r
+test("insertAfter(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(4);\r
+ var expected = 'This is a normal link: Yahoobuga';\r
+ $('<b>buga</b>').insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), 'Insert String after' );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:";\r
+ $(document.getElementById('first')).insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert element after" );\r
+\r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:diveintomark";\r
+ $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert array of elements after" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:diveintomark";\r
+ $("#mark, #first").insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert jQuery after" );\r
});\r
\r
test("end()", function() {\r
- expect(2);\r
+ expect(3);\r
ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );\r
ok( $('#yahoo').end(), 'Check for end with nothing to end' );\r
+ \r
+ var x = $('#yahoo');\r
+ x.parent();\r
+ ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );\r
});\r
\r
test("find(String)", function() {\r
ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );\r
});\r
\r
-test("filter()", function() {\r
- isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );\r
- isSet( $("p").filter(["#ap", "#sndp"]).get(), q("ap", "sndp"), "filter(Array<String>)" );\r
-});\r
-\r
-test("not(String)", function() {\r
- ok($("#main > p#ap > a").not("#google").length == 2, "not('selector')")\r
- // TODO: Comma-based selector\r
- //isSet( $("p").not("#ap, #sndp").get(), q("firstp", "en", "sap", "first", "result"), "not('selector, selector')" );\r
-});\r
-\r
test("is(String)", function() {\r
- expect(22);\r
+ expect(26);\r
ok( $('#form').is('form'), 'Check for element: A form must be a form' );\r
ok( !$('#form').is('div'), 'Check for element: A form is not a div' );\r
ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );\r
ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );\r
ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );\r
ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );\r
+ \r
+ // test is() with comma-seperated expressions\r
+ ok( $('#en').is('[@lang="en"],[@lang="de"]'), 'Check for lang attribute: Expecte en or de' );\r
+ ok( $('#en').is('[@lang="de"],[@lang="en"]'), 'Check for lang attribute: Expecte en or de' );\r
+ ok( $('#en').is('[@lang="en"] , [@lang="de"]'), 'Check for lang attribute: Expecte en or de' );\r
+ ok( $('#en').is('[@lang="de"] , [@lang="en"]'), 'Check for lang attribute: Expecte en or de' );\r
});\r
\r
test("$.extend(Object, Object)", function() {\r
isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );\r
});\r
\r
-test("expressions - element", function() {\r
- expect(5);\r
- ok( $("*").size() >= 30, "Select all" );\r
- t( "Element Selector", "div", ["main","foo"] );\r
- t( "Element Selector", "body", ["body"] );\r
- t( "Element Selector", "html", ["html"] );\r
- t( "Parent Element", "div div", ["foo"] );\r
-});\r
-\r
-test("expressions - id", function() {\r
- expect(8);\r
- t( "ID Selector", "#body", ["body"] );\r
- t( "ID Selector w/ Element", "body#body", ["body"] );\r
- t( "ID Selector w/ Element", "ul#first", [] );\r
- \r
- t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267\r
- t( "ID Selector, not an ancestor ID", "#form #first", [] );\r
- t( "ID Selector, not a child ID", "#form > #option1a", [] );\r
- \r
- t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );\r
- t( "All Children of ID with no children", "#firstUL/*", [] );\r
-});\r
-\r
-test("expressions - class", function() {\r
- expect(4);\r
- t( "Class Selector", ".blog", ["mark","simon"] );\r
- t( "Class Selector", ".blog.link", ["simon"] );\r
- t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );\r
- t( "Parent Class Selector", "p .blog", ["mark","simon"] );\r
-});\r
-\r
-test("expressions - multiple", function() {\r
- expect(4);\r
- t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );\r
- t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );\r
- t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );\r
- t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );\r
-});\r
-\r
-test("expressions - child and adjacent", function() {\r
- expect(14);\r
- t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );\r
- t( "Child w/ Class", "p > a.blog", ["mark","simon"] );\r
- t( "All Children", "code > *", ["anchor1","anchor2"] );\r
- t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );\r
- t( "Adjacent", "a + a", ["groups"] );\r
- t( "Adjacent", "a +a", ["groups"] );\r
- t( "Adjacent", "a+ a", ["groups"] );\r
- t( "Adjacent", "a+a", ["groups"] );\r
- t( "Adjacent", "p + p", ["ap","en","sap"] );\r
- t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );\r
- t( "First Child", "p:first-child", ["firstp","sndp"] );\r
-});\r
-\r
-test("expressions - attributes", function() {\r
- expect(19);\r
- t( "Attribute Exists", "a[@title]", ["google"] );\r
- t( "Attribute Exists", "*[@title]", ["google"] );\r
- t( "Attribute Exists", "[@title]", ["google"] );\r
- \r
- t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );\r
- t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );\r
- t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );\r
- t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );\r
- t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );\r
- t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );\r
- \r
- t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );\r
- t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );\r
- t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );\r
- \r
- t("Select options via [@selected]", "#select1 option[@selected]", ["option1a"] );\r
- t("Select options via [@selected]", "#select2 option[@selected]", ["option2d"] );\r
- t("Select options via [@selected]", "#select3 option[@selected]", ["option3b", "option3c"] );\r
- \r
- t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );\r
- \r
- t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);\r
- t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);\r
- t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);\r
-});\r
-\r
-test("expressions - pseudo (:) selctors", function() {\r
- expect(30);\r
- t( "First Child", "p:first-child", ["firstp","sndp"] );\r
- t( "Last Child", "p:last-child", ["sap"] );\r
- t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );\r
- t( "Empty", "ul:empty", ["firstUL"] );\r
- t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );\r
- t( "Disabled UI Element", "input:disabled", ["text2"] );\r
- t( "Checked UI Element", "input:checked", ["radio2","check1"] );\r
- t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );\r
- t( "Text Contains", "a:contains('Google')", ["google","groups"] );\r
- t( "Text Contains", "a:contains('Google Groups')", ["groups"] );\r
- t( "Element Preceded By", "p ~ div", ["foo"] );\r
- t( "Not", "a.blog:not(.link)", ["mark"] );\r
- \r
- t( "nth Element", "p:nth(1)", ["ap"] );\r
- t( "First Element", "p:first", ["firstp"] );\r
- t( "Last Element", "p:last", ["first"] );\r
- t( "Even Elements", "p:even", ["firstp","sndp","sap"] );\r
- t( "Odd Elements", "p:odd", ["ap","en","first"] );\r
- t( "Position Equals", "p:eq(1)", ["ap"] );\r
- t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );\r
- t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );\r
- t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );\r
- t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );\r
- t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );\r
- \r
- t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );\r
- t( "Form element :radio", ":radio", ["radio1", "radio2"] );\r
- t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );\r
- t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );\r
- t( "Form element :radio:checked", ":radio:checked", ["radio2"] );\r
- t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );\r
- t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );\r
-});\r
-\r
-test("expressions - basic xpath", function() {\r
- expect(14);\r
- ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );\r
- t( "All Div Elements", "//div", ["main","foo"] );\r
- t( "Absolute Path", "/html/body", ["body"] );\r
- t( "Absolute Path w/ *", "/* /body", ["body"] );\r
- t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );\r
- t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );\r
- t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );\r
- t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );\r
- t( "Attribute Exists", "//a[@title]", ["google"] );\r
- t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );\r
- t( "Parent Axis", "//p/..", ["main","foo"] );\r
- t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );\r
- t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );\r
- t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );\r
-});\r
-\r
test("val()", function() {\r
expect(2);\r
ok( $("#text1").val() == "Test", "Check for value of input element" );\r
ok( pass, "Set HTML" );\r
});\r
\r
-test("id()", function() {\r
- expect(3);\r
- ok( $(document.getElementById('main')).id() == "main", "Check for id" );\r
- ok( $("#foo").id() == "foo", "Check for id" );\r
- ok( !$("head").id(), "Check for id" );\r
-});\r
-\r
-test("title()", function() {\r
- expect(2);\r
- ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );\r
- ok( !$("#yahoo").title(), "Check for title" );\r
+test("filter()", function() {\r
+ expect(4);\r
+ isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );\r
+ isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );\r
+ isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );\r
+ isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );\r
});\r
\r
-test("name()", function() {\r
+test("not()", function() {\r
expect(3);\r
- ok( $(document.getElementById('text1')).name() == "action", "Check for name" );\r
- ok( $("#hidden1").name() == "hidden", "Check for name" );\r
- ok( !$("#area1").name(), "Check for name" );\r
+ ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );\r
+ isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );\r
+ isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );\r
});\r
\r
\r
test("siblings([String])", function() {\r
- expect(3);\r
+ expect(4);\r
isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );\r
isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" ); \r
isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );\r
+ isSet( $("#foo").siblings("form, b").get(), q("form", "floatTest"), "Check for multiple filters" );\r
});\r
\r
test("children([String])", function() {\r
- expect(2);\r
+ expect(3);\r
isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );\r
isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );\r
+ isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );\r
+});\r
+\r
+test("parent[s]([String])", function() {\r
+ expect(8);\r
+ ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );\r
+ ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );\r
+ ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );\r
+ ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );\r
+ \r
+ ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );\r
+ ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );\r
+ ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );\r
+ isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );\r
});\r
\r
+test("next/prev([String])", function() {\r
+ expect(8);\r
+ ok( $("#ap").next()[0].id == "foo", "Simple next check" );\r
+ ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );\r
+ ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );\r
+ ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );\r
+ \r
+ ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );\r
+ ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );\r
+ ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );\r
+ ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );\r
+});\r
\r
test("show()", function() {\r
expect(1);\r
ok( pass, "Remove multiple classes" );\r
});\r
\r
+test("toggleClass(String)", function() {\r
+ expect(3);\r
+ var e = $("#firstp");\r
+ ok( !e.is(".test"), "Assert class not present" );\r
+ e.toggleClass("test");\r
+ ok( e.is(".test"), "Assert class present" ); \r
+ e.toggleClass("test");\r
+ ok( !e.is(".test"), "Assert class not present" );\r
+});\r
+\r
test("removeAttr(String", function() {\r
ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );\r
});\r
+\r
+test("text(String)", function() {\r
+ expect(1);\r
+ ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );\r
+});\r
+\r
+test("$.each(Object,Function)", function() {\r
+ expect(8);\r
+ $.each( [0,1,2], function(i, n){\r
+ ok( i == n, "Check array iteration" );\r
+ });\r
+ \r
+ $.each( [5,6,7], function(i, n){\r
+ ok( i == n - 5, "Check array iteration" );\r
+ });\r
+ \r
+ $.each( { name: "name", lang: "lang" }, function(i, n){\r
+ ok( i == n, "Check object iteration" );\r
+ });\r
+});\r
+\r
+test("$.prop", function() {\r
+ expect(2);\r
+ var handle = function() { return this.id };\r
+ ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );\r
+ ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );\r
+});\r
+\r
+test("$.className", function() {\r
+ expect(6);\r
+ var x = $("<p>Hi</p>")[0];\r
+ var c = $.className;\r
+ c.add(x, "hi");\r
+ ok( x.className == "hi", "Check single added class" );\r
+ c.add(x, "foo bar");\r
+ ok( x.className == "hi foo bar", "Check more added classes" );\r
+ c.remove(x);\r
+ ok( x.className == "", "Remove all classes" );\r
+ c.add(x, "hi foo bar");\r
+ c.remove(x, "foo");\r
+ ok( x.className == "hi bar", "Check removal of one class" );\r
+ ok( c.has(x, "hi"), "Check has1" );\r
+ ok( c.has(x, "bar"), "Check has2" );\r
+});\r
+\r
+test("remove()", function() {\r
+ $("#ap").children().remove();\r
+ ok( $("#ap").text().length > 10, "Check text is not removed" );\r
+ ok( $("#ap").children().length == 0, "Check remove" );\r
+ \r
+ reset();\r
+ $("#ap").children().remove("a");\r
+ ok( $("#ap").text().length > 10, "Check text is not removed" );\r
+ ok( $("#ap").children().length == 1, "Check filtered remove" );\r
+});\r
+\r
+test("empty()", function() {\r
+ ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );\r
+ ok( $("#ap").children().length == 4, "Check elements are not removed" );\r
+});\r
+\r
+test("eq(), gt(), lt(), contains()", function() {\r
+ ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );\r
+ isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" );\r
+ isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );\r
+ isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );\r
+});\r
+\r
+test("click() context", function() {\r
+ $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {\r
+ var close = $('spanx', this); // same with $(this).find('span');\r
+ ok( close.length == 0, "Element does not exist, length must be zero" );\r
+ ok( !close[0], "Element does not exist, direct access to element must return undefined" );\r
+ //console.log( close[0]); // it's the <a> and not a <span> element\r
+ return false;\r
+ }).click();\r
+});\r