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("add(String|Element|Array)", function() {
\r
31 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
33 ok( $([]).add($("#form")[0].elements).length > 13, "Check elements from array" );
\r
35 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
36 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
37 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
39 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
40 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
41 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
44 test("each(Function)", function() {
\r
47 div.each(function(){this.foo = 'zoo';});
\r
49 for ( var i = 0; i < div.size(); i++ ) {
\r
50 if ( div.get(i).foo != "zoo" ) pass = false;
\r
52 ok( pass, "Execute a function, Relative" );
\r
55 test("index(Object)", function() {
\r
57 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
58 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
59 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
60 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
61 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
62 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
63 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
64 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
65 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
68 test("attr(String)", function() {
\r
70 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
71 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
72 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
73 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
74 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
75 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
76 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
77 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
78 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
79 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
80 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
81 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
84 test("attr(String, Function)", function() {
\r
86 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
\r
89 test("attr(Hash)", function() {
\r
92 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
93 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
95 ok( pass, "Set Multiple Attributes" );
\r
98 test("attr(String, Object)", function() {
\r
100 var div = $("div");
\r
101 div.attr("foo", "bar");
\r
103 for ( var i = 0; i < div.size(); i++ ) {
\r
104 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
106 ok( pass, "Set Attribute" );
\r
108 $("#name").attr('name', 'something');
\r
109 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
\r
110 $("#check2").attr('checked', true);
\r
111 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
112 $("#check2").attr('checked', false);
\r
113 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
114 $("#text1").attr('readonly', true);
\r
115 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
116 $("#text1").attr('readonly', false);
\r
117 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
120 if ( location.protocol != "file:" ) {
\r
121 test("attr(String, Object)x", function() {
\r
124 $.get('data/dashboard.xml', function(xml) {
\r
126 $('tab', xml).each(function() {
\r
127 titles.push($(this).attr('title'));
\r
129 ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
\r
130 ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
\r
136 test("css(String|Hash)", function() {
\r
139 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
141 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
142 $('#foo').css({display: 'none'});
\r
143 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
144 $('#foo').css({display: 'block'});
\r
145 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
147 $('#floatTest').css({styleFloat: 'right'});
\r
148 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
149 $('#floatTest').css({cssFloat: 'left'});
\r
150 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
151 $('#floatTest').css({'float': 'right'});
\r
152 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
153 $('#floatTest').css({'font-size': '30px'});
\r
154 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
157 test("css(String, Object)", function() {
\r
159 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
160 $('#foo').css('display', 'none');
\r
161 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
162 $('#foo').css('display', 'block');
\r
163 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
165 $('#floatTest').css('styleFloat', 'left');
\r
166 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
167 $('#floatTest').css('cssFloat', 'right');
\r
168 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
169 $('#floatTest').css('float', 'left');
\r
170 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
171 $('#floatTest').css('font-size', '20px');
\r
172 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
175 test("text()", function() {
\r
176 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
177 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
180 test("wrap(String|Element)", function() {
\r
182 var defaultText = 'Try them out:'
\r
183 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
184 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
185 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
188 var defaultText = 'Try them out:'
\r
189 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
190 ok( result.is('ol'), 'Check for element wrapping' );
\r
191 ok( result.text() == defaultText, 'Check for element wrapping' );
\r
194 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
196 var defaultText = 'Try them out:'
\r
197 var result = $('#first').append('<b>buga</b>');
\r
198 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
199 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
202 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
203 $('#sap').append(document.getElementById('first'));
\r
204 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
207 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
208 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
209 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
212 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
213 $('#sap').append($("#first, #yahoo"));
\r
214 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
217 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
219 var defaultText = 'Try them out:'
\r
220 $('<b>buga</b>').appendTo('#first');
\r
221 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
\r
222 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
225 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
226 $(document.getElementById('first')).appendTo('#sap');
\r
227 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
230 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
231 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
232 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
235 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
236 $("#first, #yahoo").appendTo('#sap');
\r
237 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
240 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
242 var defaultText = 'Try them out:'
\r
243 var result = $('#first').prepend('<b>buga</b>');
\r
244 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
245 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
248 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
249 $('#sap').prepend(document.getElementById('first'));
\r
250 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
253 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
254 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
255 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
258 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
259 $('#sap').prepend($("#first, #yahoo"));
\r
260 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
263 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
265 var defaultText = 'Try them out:'
\r
266 $('<b>buga</b>').prependTo('#first');
\r
267 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
268 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
271 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
272 $(document.getElementById('first')).prependTo('#sap');
\r
273 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
276 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
277 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
278 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
281 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
282 $("#yahoo, #first").prependTo('#sap');
\r
283 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
286 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
288 var expected = 'This is a normal link: bugaYahoo';
\r
289 $('#yahoo').before('<b>buga</b>');
\r
290 ok( expected == $('#en').text(), 'Insert String before' );
\r
293 expected = "This is a normal link: Try them out:Yahoo";
\r
294 $('#yahoo').before(document.getElementById('first'));
\r
295 ok( expected == $('#en').text(), "Insert element before" );
\r
298 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
299 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
300 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
303 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
304 $('#yahoo').before($("#first, #mark"));
\r
305 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
308 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
310 var expected = 'This is a normal link: bugaYahoo';
\r
311 $('<b>buga</b>').insertBefore('#yahoo');
\r
312 ok( expected == $('#en').text(), 'Insert String before' );
\r
315 expected = "This is a normal link: Try them out:Yahoo";
\r
316 $(document.getElementById('first')).insertBefore('#yahoo');
\r
317 ok( expected == $('#en').text(), "Insert element before" );
\r
320 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
321 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
322 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
325 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
326 $("#first, #mark").insertBefore('#yahoo');
\r
327 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
330 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
332 var expected = 'This is a normal link: Yahoobuga';
\r
333 $('#yahoo').after('<b>buga</b>');
\r
334 ok( expected == $('#en').text(), 'Insert String after' );
\r
337 expected = "This is a normal link: YahooTry them out:";
\r
338 $('#yahoo').after(document.getElementById('first'));
\r
339 ok( expected == $('#en').text(), "Insert element after" );
\r
342 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
343 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
344 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
347 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
348 $('#yahoo').after($("#first, #mark"));
\r
349 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
352 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
354 var expected = 'This is a normal link: Yahoobuga';
\r
355 $('<b>buga</b>').insertAfter('#yahoo');
\r
356 ok( expected == $('#en').text(), 'Insert String after' );
\r
359 expected = "This is a normal link: YahooTry them out:";
\r
360 $(document.getElementById('first')).insertAfter('#yahoo');
\r
361 ok( expected == $('#en').text(), "Insert element after" );
\r
364 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
365 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
366 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
369 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
370 $("#mark, #first").insertAfter('#yahoo');
\r
371 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
374 test("end()", function() {
\r
376 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
377 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
379 var x = $('#yahoo');
\r
381 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
384 test("find(String)", function() {
\r
385 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
388 test("clone()", function() {
\r
390 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
391 var clone = $('#yahoo').clone();
\r
392 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
393 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
396 test("is(String)", function() {
\r
398 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
399 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
400 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
401 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
402 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
403 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
404 ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
405 ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
406 ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
407 ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
408 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
409 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
410 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
411 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
412 ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
413 ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
414 ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
415 ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
416 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
417 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
418 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
419 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
422 test("$.extend(Object, Object)", function() {
\r
424 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
425 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
426 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
427 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
428 jQuery.extend(settings, options);
\r
429 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
430 isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
433 test("$.extend(Object, Object, Object, Object)", function() {
\r
435 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
436 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
437 options1 = { xnumber2: 1, xstring2: "x" },
\r
438 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
439 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
440 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
441 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
442 var settings = jQuery.extend({}, defaults, options1, options2);
\r
443 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
444 isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
445 isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
446 isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
449 test("val()", function() {
\r
451 ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
452 ok( !$("#text1").val() == "", "Check for value of input element" );
\r
455 test("val(String)", function() {
\r
457 document.getElementById('text1').value = "bla";
\r
458 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
459 $("#text1").val('test');
\r
460 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
463 test("html(String)", function() {
\r
465 var div = $("div");
\r
466 div.html("<b>test</b>");
\r
468 for ( var i = 0; i < div.size(); i++ ) {
\r
469 if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
471 ok( pass, "Set HTML" );
\r
474 test("filter()", function() {
\r
476 isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
477 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
478 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
479 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
482 test("not(String)", function() {
\r
484 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
\r
485 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
489 test("siblings([String])", function() {
\r
491 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
492 isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
493 isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
494 isSet( $("#foo").siblings("form, b").get(), q("form", "floatTest"), "Check for multiple filters" );
\r
497 test("children([String])", function() {
\r
499 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
500 isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
501 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
504 test("parent[s]([String])", function() {
\r
506 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
\r
507 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
\r
508 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
\r
509 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
\r
511 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
\r
512 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
\r
513 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
\r
514 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
517 test("next/prev([String])", function() {
\r
519 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
\r
520 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
\r
521 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
\r
522 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
\r
524 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
\r
525 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
\r
526 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
\r
527 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
\r
530 test("show()", function() {
\r
532 var pass = true, div = $("div");
\r
533 div.show().each(function(){
\r
534 if ( this.style.display == "none" ) pass = false;
\r
536 ok( pass, "Show" );
\r
539 test("addClass(String)", function() {
\r
540 var div = $("div");
\r
541 div.addClass("test");
\r
543 for ( var i = 0; i < div.size(); i++ ) {
\r
544 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
546 ok( pass, "Add Class" );
\r
549 test("removeClass(String) - simple", function() {
\r
551 var div = $("div").addClass("test").removeClass("test"),
\r
553 for ( var i = 0; i < div.size(); i++ ) {
\r
554 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
556 ok( pass, "Remove Class" );
\r
559 test("removeClass(String) - add three classes and remove again", function() {
\r
561 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
562 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
564 for ( var i = 0; i < div.size(); i++ ) {
\r
565 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
567 ok( pass, "Remove multiple classes" );
\r
570 test("toggleClass(String)", function() {
\r
572 var e = $("#firstp");
\r
573 ok( !e.is(".test"), "Assert class not present" );
\r
574 e.toggleClass("test");
\r
575 ok( e.is(".test"), "Assert class present" );
\r
576 e.toggleClass("test");
\r
577 ok( !e.is(".test"), "Assert class not present" );
\r
580 test("removeAttr(String", function() {
\r
581 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
584 test("text(String)", function() {
\r
586 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
589 test("$.each(Object,Function)", function() {
\r
591 $.each( [0,1,2], function(i, n){
\r
592 ok( i == n, "Check array iteration" );
\r
595 $.each( [5,6,7], function(i, n){
\r
596 ok( i == n - 5, "Check array iteration" );
\r
599 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
600 ok( i == n, "Check object iteration" );
\r
604 test("$.prop", function() {
\r
606 var handle = function() { return this.id };
\r
607 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
\r
608 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
\r
611 test("$.className", function() {
\r
613 var x = $("<p>Hi</p>")[0];
\r
614 var c = $.className;
\r
616 ok( x.className == "hi", "Check single added class" );
\r
617 c.add(x, "foo bar");
\r
618 ok( x.className == "hi foo bar", "Check more added classes" );
\r
620 ok( x.className == "", "Remove all classes" );
\r
621 c.add(x, "hi foo bar");
\r
622 c.remove(x, "foo");
\r
623 ok( x.className == "hi bar", "Check removal of one class" );
\r
624 ok( c.has(x, "hi"), "Check has1" );
\r
625 ok( c.has(x, "bar"), "Check has2" );
\r
628 test("remove()", function() {
\r
629 $("#ap").children().remove();
\r
630 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
631 ok( $("#ap").children().length == 0, "Check remove" );
\r
634 $("#ap").children().remove("a");
\r
635 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
636 ok( $("#ap").children().length == 1, "Check filtered remove" );
\r
639 test("empty()", function() {
\r
640 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
\r
641 ok( $("#ap").children().length == 4, "Check elements are not removed" );
\r
644 test("eq(), gt(), lt(), contains()", function() {
\r
645 ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );
\r
646 isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" );
\r
647 isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );
\r
648 isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );
\r