3 test("Basic requirements", function() {
\r
5 ok( Array.prototype.push, "Array.push()" );
\r
6 ok( Function.prototype.apply, "Function.apply()" );
\r
7 ok( document.getElementById, "getElementById" );
\r
8 ok( document.getElementsByTagName, "getElementsByTagName" );
\r
9 ok( RegExp, "RegExp" );
\r
10 ok( jQuery, "jQuery" );
\r
14 test("length", function() {
\r
15 ok( $("div").length == 2, "Get Number of Elements Found" );
\r
18 test("size()", function() {
\r
19 ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
22 test("get()", function() {
\r
23 isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
26 test("get(Number)", function() {
\r
27 ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
30 test("each(Function)", function() {
\r
33 div.each(function(){this.foo = 'zoo';});
\r
35 for ( var i = 0; i < div.size(); i++ ) {
\r
36 if ( div.get(i).foo != "zoo" ) pass = false;
\r
38 ok( pass, "Execute a function, Relative" );
\r
41 test("index(Object)", function() {
\r
43 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
44 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
45 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
46 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
47 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
48 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
49 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
50 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
51 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
54 test("attr(String)", function() {
\r
56 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
57 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
58 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
59 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
60 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
61 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
62 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
63 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
64 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
65 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
66 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
67 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
70 test("attr(Hash)", function() {
\r
73 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
74 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
76 ok( pass, "Set Multiple Attributes" );
\r
79 test("attr(String, Object)", function() {
\r
82 div.attr("foo", "bar");
\r
84 for ( var i = 0; i < div.size(); i++ ) {
\r
85 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
87 ok( pass, "Set Attribute" );
\r
89 $("#name").attr('name', 'something');
\r
90 ok( $("#name").name() == 'something', 'Set name attribute' );
\r
91 $("#check2").attr('checked', true);
\r
92 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
93 $("#check2").attr('checked', false);
\r
94 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
95 $("#text1").attr('readonly', true);
\r
96 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
97 $("#text1").attr('readonly', false);
\r
98 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
101 test("attr(String, Object)x", function() {
\r
104 $.get('data/dashboard.xml', function(xml) {
\r
106 $('tab', xml).each(function() {
\r
107 titles.push($(this).attr('title'));
\r
109 ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
\r
110 ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
\r
115 test("css(String|Hash)", function() {
\r
118 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
120 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
121 $('#foo').css({display: 'none'});
\r
122 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
123 $('#foo').css({display: 'block'});
\r
124 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
126 $('#floatTest').css({styleFloat: 'right'});
\r
127 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
128 $('#floatTest').css({cssFloat: 'left'});
\r
129 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
130 $('#floatTest').css({'float': 'right'});
\r
131 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
132 $('#floatTest').css({'font-size': '30px'});
\r
133 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
136 test("css(String, Object)", function() {
\r
138 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
139 $('#foo').css('display', 'none');
\r
140 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
141 $('#foo').css('display', 'block');
\r
142 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
144 $('#floatTest').css('styleFloat', 'left');
\r
145 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
146 $('#floatTest').css('cssFloat', 'right');
\r
147 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
148 $('#floatTest').css('float', 'left');
\r
149 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
150 $('#floatTest').css('font-size', '20px');
\r
151 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
154 test("text()", function() {
\r
155 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
156 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
159 test("wrap(String|Element)", function() {
\r
161 var defaultText = 'Try them out:'
\r
162 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
163 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
164 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
167 var defaultText = 'Try them out:'
\r
168 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
169 ok( result.is('ol'), 'Check for element wrapping' );
\r
170 ok( result.text() == defaultText, 'Check for element wrapping' );
\r
173 test("append(String|Element|Array<Element>)", function() {
\r
175 var defaultText = 'Try them out:'
\r
176 var result = $('#first').append('<b>buga</b>');
\r
177 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
178 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
181 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
182 $('#sap').append(document.getElementById('first'));
\r
183 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
186 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
187 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
188 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
191 test("prepend(String|Element|Array<Element>)", function() {
\r
193 var defaultText = 'Try them out:'
\r
194 var result = $('#first').prepend('<b>buga</b>');
\r
195 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
196 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
199 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
200 $('#sap').prepend(document.getElementById('first'));
\r
201 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
204 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
205 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
206 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
209 test("before(String|Element|Array<Element>)", function() {
\r
211 var expected = 'This is a normal link: bugaYahoo';
\r
212 $('#yahoo').before('<b>buga</b>');
\r
213 ok( expected == $('#en').text(), 'Insert String before' );
\r
216 expected = "This is a normal link: Try them out:Yahoo";
\r
217 $('#yahoo').before(document.getElementById('first'));
\r
218 ok( expected == $('#en').text(), "Insert element before" );
\r
221 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
222 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
223 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
226 test("after(String|Element|Array<Element>)", function() {
\r
228 var expected = 'This is a normal link: Yahoobuga';
\r
229 $('#yahoo').after('<b>buga</b>');
\r
230 ok( expected == $('#en').text(), 'Insert String after' );
\r
233 expected = "This is a normal link: YahooTry them out:";
\r
234 $('#yahoo').after(document.getElementById('first'));
\r
235 ok( expected == $('#en').text(), "Insert element after" );
\r
238 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
239 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
240 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
243 test("end()", function() {
\r
245 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
246 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
249 test("find(String)", function() {
\r
250 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
253 test("clone()", function() {
\r
255 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
256 var clone = $('#yahoo').clone();
\r
257 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
258 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
261 test("filter()", function() {
\r
262 isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
263 isSet( $("p").filter(["#ap", "#sndp"]).get(), q("ap", "sndp"), "filter(Array<String>)" );
\r
266 test("not(String)", function() {
\r
267 ok($("#main > p#ap > a").not("#google").length == 2, "not('selector')")
\r
268 // TODO: Comma-based selector
\r
269 //isSet( $("p").not("#ap, #sndp").get(), q("firstp", "en", "sap", "first", "result"), "not('selector, selector')" );
\r
272 test("is(String)", function() {
\r
274 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
275 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
276 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
277 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
278 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
279 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
280 ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
281 ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
282 ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
283 ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
284 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
285 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
286 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
287 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
288 ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
289 ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
290 ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
291 ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
292 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
293 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
294 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
295 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
298 test("$.extend(Object, Object)", function() {
\r
300 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
301 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
302 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
303 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
304 jQuery.extend(settings, options);
\r
305 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
306 isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
309 test("$.extend(Object, Object, Object, Object)", function() {
\r
311 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
312 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
313 options1 = { xnumber2: 1, xstring2: "x" },
\r
314 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
315 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
316 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
317 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
318 var settings = jQuery.extend({}, defaults, options1, options2);
\r
319 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
320 isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
321 isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
322 isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
325 test("expressions - element", function() {
\r
327 ok( $("*").size() >= 30, "Select all" );
\r
328 t( "Element Selector", "div", ["main","foo"] );
\r
329 t( "Element Selector", "body", ["body"] );
\r
330 t( "Element Selector", "html", ["html"] );
\r
331 t( "Parent Element", "div div", ["foo"] );
\r
334 test("expressions - id", function() {
\r
336 t( "ID Selector", "#body", ["body"] );
\r
337 t( "ID Selector w/ Element", "body#body", ["body"] );
\r
338 t( "ID Selector w/ Element", "ul#first", [] );
\r
340 t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
\r
341 t( "ID Selector, not an ancestor ID", "#form #first", [] );
\r
342 t( "ID Selector, not a child ID", "#form > #option1a", [] );
\r
344 t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
\r
345 t( "All Children of ID with no children", "#firstUL/*", [] );
\r
348 test("expressions - class", function() {
\r
350 t( "Class Selector", ".blog", ["mark","simon"] );
\r
351 t( "Class Selector", ".blog.link", ["simon"] );
\r
352 t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
\r
353 t( "Parent Class Selector", "p .blog", ["mark","simon"] );
\r
356 test("expressions - multiple", function() {
\r
358 t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
\r
359 t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
\r
360 t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
\r
361 t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
\r
364 test("expressions - child and adjacent", function() {
\r
366 t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
367 t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
368 t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
369 t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
\r
370 t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
\r
371 t( "All Children", "code > *", ["anchor1","anchor2"] );
\r
372 t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
\r
373 t( "Adjacent", "a + a", ["groups"] );
\r
374 t( "Adjacent", "a +a", ["groups"] );
\r
375 t( "Adjacent", "a+ a", ["groups"] );
\r
376 t( "Adjacent", "a+a", ["groups"] );
\r
377 t( "Adjacent", "p + p", ["ap","en","sap"] );
\r
378 t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
\r
379 t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
382 test("expressions - attributes", function() {
\r
384 t( "Attribute Exists", "a[@title]", ["google"] );
\r
385 t( "Attribute Exists", "*[@title]", ["google"] );
\r
386 t( "Attribute Exists", "[@title]", ["google"] );
\r
388 t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
\r
389 t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
\r
390 t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
\r
391 t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
392 t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
\r
393 t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
\r
395 t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
\r
396 t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
\r
397 t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
\r
399 t("Select options via [@selected]", "#select1 option[@selected]", ["option1a"] );
\r
400 t("Select options via [@selected]", "#select2 option[@selected]", ["option2d"] );
\r
401 t("Select options via [@selected]", "#select3 option[@selected]", ["option3b", "option3c"] );
\r
403 t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
\r
405 t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
\r
406 t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
\r
407 t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
\r
410 test("expressions - pseudo (:) selctors", function() {
\r
412 t( "First Child", "p:first-child", ["firstp","sndp"] );
\r
413 t( "Last Child", "p:last-child", ["sap"] );
\r
414 t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
\r
415 t( "Empty", "ul:empty", ["firstUL"] );
\r
416 t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
\r
417 t( "Disabled UI Element", "input:disabled", ["text2"] );
\r
418 t( "Checked UI Element", "input:checked", ["radio2","check1"] );
\r
419 t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
\r
420 t( "Text Contains", "a:contains('Google')", ["google","groups"] );
\r
421 t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
\r
422 t( "Element Preceded By", "p ~ div", ["foo"] );
\r
423 t( "Not", "a.blog:not(.link)", ["mark"] );
\r
425 t( "nth Element", "p:nth(1)", ["ap"] );
\r
426 t( "First Element", "p:first", ["firstp"] );
\r
427 t( "Last Element", "p:last", ["first"] );
\r
428 t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
\r
429 t( "Odd Elements", "p:odd", ["ap","en","first"] );
\r
430 t( "Position Equals", "p:eq(1)", ["ap"] );
\r
431 t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
\r
432 t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
\r
433 t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
\r
434 t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
\r
435 t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
\r
437 t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
\r
438 t( "Form element :radio", ":radio", ["radio1", "radio2"] );
\r
439 t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
\r
440 t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
\r
441 t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
\r
442 t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
\r
443 t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
\r
446 test("expressions - basic xpath", function() {
\r
448 ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
\r
449 t( "All Div Elements", "//div", ["main","foo"] );
\r
450 t( "Absolute Path", "/html/body", ["body"] );
\r
451 t( "Absolute Path w/ *", "/* /body", ["body"] );
\r
452 t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
\r
453 t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
\r
454 t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
\r
455 t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
\r
456 t( "Attribute Exists", "//a[@title]", ["google"] );
\r
457 t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
\r
458 t( "Parent Axis", "//p/..", ["main","foo"] );
\r
459 t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
\r
460 t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
\r
461 t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
\r
464 test("val()", function() {
\r
466 ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
467 ok( !$("#text1").val() == "", "Check for value of input element" );
\r
470 test("val(String)", function() {
\r
472 document.getElementById('text1').value = "bla";
\r
473 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
474 $("#text1").val('test');
\r
475 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
478 test("html(String)", function() {
\r
480 var div = $("div");
\r
481 div.html("<b>test</b>");
\r
483 for ( var i = 0; i < div.size(); i++ ) {
\r
484 if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
486 ok( pass, "Set HTML" );
\r
489 test("id()", function() {
\r
491 ok( $(document.getElementById('main')).id() == "main", "Check for id" );
\r
492 ok( $("#foo").id() == "foo", "Check for id" );
\r
493 ok( !$("head").id(), "Check for id" );
\r
496 test("title()", function() {
\r
498 ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
\r
499 ok( !$("#yahoo").title(), "Check for title" );
\r
502 test("name()", function() {
\r
504 ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
\r
505 ok( $("#hidden1").name() == "hidden", "Check for name" );
\r
506 ok( !$("#area1").name(), "Check for name" );
\r
510 test("siblings([String])", function() {
\r
512 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
513 isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
514 isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
517 test("children([String])", function() {
\r
519 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
520 isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
524 test("show()", function() {
\r
526 var pass = true, div = $("div");
\r
527 div.show().each(function(){
\r
528 if ( this.style.display == "none" ) pass = false;
\r
530 ok( pass, "Show" );
\r
533 test("addClass(String)", function() {
\r
534 var div = $("div");
\r
535 div.addClass("test");
\r
537 for ( var i = 0; i < div.size(); i++ ) {
\r
538 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
540 ok( pass, "Add Class" );
\r
543 test("removeClass(String) - simple", function() {
\r
545 var div = $("div").addClass("test").removeClass("test"),
\r
547 for ( var i = 0; i < div.size(); i++ ) {
\r
548 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
550 ok( pass, "Remove Class" );
\r
553 test("removeClass(String) - add three classes and remove again", function() {
\r
555 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
556 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
558 for ( var i = 0; i < div.size(); i++ ) {
\r
559 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
561 ok( pass, "Remove multiple classes" );
\r
564 test("removeAttr(String", function() {
\r
565 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
568 test("unbind(event)", function() {
\r
570 var el = $("#firstp");
\r
571 el.click(function() {
\r
572 ok( true, "Fake normal bind" );
\r
574 el.click(function(event) {
\r
576 ok( true, "Fake onebind" );
\r
578 el.click().click();
\r