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("$()", function() {
\r
15 var main = $("#main");
\r
16 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
\r
19 test("length", function() {
\r
20 ok( $("div").length == 2, "Get Number of Elements Found" );
\r
23 test("size()", function() {
\r
24 ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
27 test("get()", function() {
\r
28 isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
31 test("get(Number)", function() {
\r
32 ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
35 test("add(String|Element|Array)", function() {
\r
36 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
37 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
38 ok( $([]).add($("#form")[0].elements).length > 13, "Check elements from array" );
\r
40 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
41 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
42 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
44 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
45 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
46 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
49 test("each(Function)", function() {
\r
52 div.each(function(){this.foo = 'zoo';});
\r
54 for ( var i = 0; i < div.size(); i++ ) {
\r
55 if ( div.get(i).foo != "zoo" ) pass = false;
\r
57 ok( pass, "Execute a function, Relative" );
\r
60 test("index(Object)", function() {
\r
62 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
63 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
64 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
65 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
66 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
67 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
68 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
69 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
70 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
73 test("attr(String)", function() {
\r
75 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
76 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
77 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
78 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
79 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
80 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
81 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
82 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
83 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
84 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
85 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
86 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
89 test("attr(String, Function)", function() {
\r
91 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
\r
92 ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
\r
95 test("attr(Hash)", function() {
\r
98 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
99 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
101 ok( pass, "Set Multiple Attributes" );
\r
104 test("attr(String, Object)", function() {
\r
106 var div = $("div");
\r
107 div.attr("foo", "bar");
\r
109 for ( var i = 0; i < div.size(); i++ ) {
\r
110 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
112 ok( pass, "Set Attribute" );
\r
114 $("#name").attr('name', 'something');
\r
115 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
\r
116 $("#check2").attr('checked', true);
\r
117 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
118 $("#check2").attr('checked', false);
\r
119 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
120 $("#text1").attr('readonly', true);
\r
121 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
122 $("#text1").attr('readonly', false);
\r
123 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
126 if ( location.protocol != "file:" ) {
\r
127 test("attr(String, Object)x", function() {
\r
130 $.get('data/dashboard.xml', function(xml) {
\r
132 $('tab', xml).each(function() {
\r
133 titles.push($(this).attr('title'));
\r
135 ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
\r
136 ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
\r
142 test("css(String|Hash)", function() {
\r
145 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\r
147 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
148 $('#foo').css({display: 'none'});
\r
149 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
150 $('#foo').css({display: 'block'});
\r
151 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
153 $('#floatTest').css({styleFloat: 'right'});
\r
154 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
155 $('#floatTest').css({cssFloat: 'left'});
\r
156 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
157 $('#floatTest').css({'float': 'right'});
\r
158 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
159 $('#floatTest').css({'font-size': '30px'});
\r
160 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
163 test("css(String, Object)", function() {
\r
165 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
166 $('#foo').css('display', 'none');
\r
167 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
168 $('#foo').css('display', 'block');
\r
169 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
171 $('#floatTest').css('styleFloat', 'left');
\r
172 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
173 $('#floatTest').css('cssFloat', 'right');
\r
174 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
175 $('#floatTest').css('float', 'left');
\r
176 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
177 $('#floatTest').css('font-size', '20px');
\r
178 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
181 test("text()", function() {
\r
182 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
183 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
186 test("wrap(String|Element)", function() {
\r
188 var defaultText = 'Try them out:'
\r
189 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
190 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
191 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
194 var defaultText = 'Try them out:'
\r
195 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
196 ok( result.is('ol'), 'Check for element wrapping' );
\r
197 ok( result.text() == defaultText, 'Check for element wrapping' );
\r
200 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
202 var defaultText = 'Try them out:'
\r
203 var result = $('#first').append('<b>buga</b>');
\r
204 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
205 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
208 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
209 $('#sap').append(document.getElementById('first'));
\r
210 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
213 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
214 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
215 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
218 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
219 $('#sap').append($("#first, #yahoo"));
\r
220 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
223 $("#sap").append( 5 );
\r
224 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
227 ok( $("#sap").append([]), "Check for appending an empty array." );
\r
228 ok( $("#sap").append(""), "Check for appending an empty string." );
\r
229 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
232 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
234 var defaultText = 'Try them out:'
\r
235 $('<b>buga</b>').appendTo('#first');
\r
236 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
\r
237 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
240 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
241 $(document.getElementById('first')).appendTo('#sap');
\r
242 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
245 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
246 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
247 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
250 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
251 $("#first, #yahoo").appendTo('#sap');
\r
252 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
255 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
257 var defaultText = 'Try them out:'
\r
258 var result = $('#first').prepend('<b>buga</b>');
\r
259 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
260 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
263 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
264 $('#sap').prepend(document.getElementById('first'));
\r
265 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
268 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
269 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
270 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
273 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
274 $('#sap').prepend($("#first, #yahoo"));
\r
275 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
278 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
280 var defaultText = 'Try them out:'
\r
281 $('<b>buga</b>').prependTo('#first');
\r
282 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
283 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
286 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
287 $(document.getElementById('first')).prependTo('#sap');
\r
288 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
291 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
292 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
293 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
296 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
297 $("#yahoo, #first").prependTo('#sap');
\r
298 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
301 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
303 var expected = 'This is a normal link: bugaYahoo';
\r
304 $('#yahoo').before('<b>buga</b>');
\r
305 ok( expected == $('#en').text(), 'Insert String before' );
\r
308 expected = "This is a normal link: Try them out:Yahoo";
\r
309 $('#yahoo').before(document.getElementById('first'));
\r
310 ok( expected == $('#en').text(), "Insert element before" );
\r
313 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
314 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
315 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
318 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
319 $('#yahoo').before($("#first, #mark"));
\r
320 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
323 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
325 var expected = 'This is a normal link: bugaYahoo';
\r
326 $('<b>buga</b>').insertBefore('#yahoo');
\r
327 ok( expected == $('#en').text(), 'Insert String before' );
\r
330 expected = "This is a normal link: Try them out:Yahoo";
\r
331 $(document.getElementById('first')).insertBefore('#yahoo');
\r
332 ok( expected == $('#en').text(), "Insert element before" );
\r
335 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
336 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
337 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
340 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
341 $("#first, #mark").insertBefore('#yahoo');
\r
342 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
345 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
347 var expected = 'This is a normal link: Yahoobuga';
\r
348 $('#yahoo').after('<b>buga</b>');
\r
349 ok( expected == $('#en').text(), 'Insert String after' );
\r
352 expected = "This is a normal link: YahooTry them out:";
\r
353 $('#yahoo').after(document.getElementById('first'));
\r
354 ok( expected == $('#en').text(), "Insert element after" );
\r
357 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
358 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
359 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
362 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
363 $('#yahoo').after($("#first, #mark"));
\r
364 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
367 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
369 var expected = 'This is a normal link: Yahoobuga';
\r
370 $('<b>buga</b>').insertAfter('#yahoo');
\r
371 ok( expected == $('#en').text(), 'Insert String after' );
\r
374 expected = "This is a normal link: YahooTry them out:";
\r
375 $(document.getElementById('first')).insertAfter('#yahoo');
\r
376 ok( expected == $('#en').text(), "Insert element after" );
\r
379 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
380 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
381 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
384 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
385 $("#mark, #first").insertAfter('#yahoo');
\r
386 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
389 test("end()", function() {
\r
391 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
392 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
394 var x = $('#yahoo');
\r
396 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
399 test("find(String)", function() {
\r
400 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
403 test("clone()", function() {
\r
405 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
406 var clone = $('#yahoo').clone();
\r
407 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
408 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
411 test("is(String)", function() {
\r
413 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
414 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
415 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
416 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
417 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
418 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
419 ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
420 ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
421 ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
422 ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
423 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
424 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
425 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
426 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
427 ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
428 ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
429 ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
430 ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
431 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
432 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
433 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
434 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
437 test("$.extend(Object, Object)", function() {
\r
439 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
440 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
441 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
442 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
443 jQuery.extend(settings, options);
\r
444 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
445 isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
448 test("$.extend(Object, Object, Object, Object)", function() {
\r
450 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
451 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
452 options1 = { xnumber2: 1, xstring2: "x" },
\r
453 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
454 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
455 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
456 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
457 var settings = jQuery.extend({}, defaults, options1, options2);
\r
458 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
459 isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
460 isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
461 isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\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("filter()", function() {
\r
491 isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
492 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
493 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
494 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
497 test("not(String)", function() {
\r
499 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
\r
500 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
504 test("siblings([String])", function() {
\r
506 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
507 isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
508 isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
509 isSet( $("#foo").siblings("form, b").get(), q("form", "floatTest"), "Check for multiple filters" );
\r
512 test("children([String])", function() {
\r
514 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
515 isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
516 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
519 test("parent[s]([String])", function() {
\r
521 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
\r
522 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
\r
523 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
\r
524 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
\r
526 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
\r
527 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
\r
528 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
\r
529 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
532 test("next/prev([String])", function() {
\r
534 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
\r
535 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
\r
536 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
\r
537 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
\r
539 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
\r
540 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
\r
541 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
\r
542 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
\r
545 test("show()", function() {
\r
547 var pass = true, div = $("div");
\r
548 div.show().each(function(){
\r
549 if ( this.style.display == "none" ) pass = false;
\r
551 ok( pass, "Show" );
\r
554 test("addClass(String)", function() {
\r
555 var div = $("div");
\r
556 div.addClass("test");
\r
558 for ( var i = 0; i < div.size(); i++ ) {
\r
559 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
561 ok( pass, "Add Class" );
\r
564 test("removeClass(String) - simple", function() {
\r
566 var div = $("div").addClass("test").removeClass("test"),
\r
568 for ( var i = 0; i < div.size(); i++ ) {
\r
569 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
571 ok( pass, "Remove Class" );
\r
574 test("removeClass(String) - add three classes and remove again", function() {
\r
576 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
577 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
579 for ( var i = 0; i < div.size(); i++ ) {
\r
580 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
582 ok( pass, "Remove multiple classes" );
\r
585 test("toggleClass(String)", function() {
\r
587 var e = $("#firstp");
\r
588 ok( !e.is(".test"), "Assert class not present" );
\r
589 e.toggleClass("test");
\r
590 ok( e.is(".test"), "Assert class present" );
\r
591 e.toggleClass("test");
\r
592 ok( !e.is(".test"), "Assert class not present" );
\r
595 test("removeAttr(String", function() {
\r
596 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
599 test("text(String)", function() {
\r
601 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
604 test("$.each(Object,Function)", function() {
\r
606 $.each( [0,1,2], function(i, n){
\r
607 ok( i == n, "Check array iteration" );
\r
610 $.each( [5,6,7], function(i, n){
\r
611 ok( i == n - 5, "Check array iteration" );
\r
614 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
615 ok( i == n, "Check object iteration" );
\r
619 test("$.prop", function() {
\r
621 var handle = function() { return this.id };
\r
622 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
\r
623 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
\r
626 test("$.className", function() {
\r
628 var x = $("<p>Hi</p>")[0];
\r
629 var c = $.className;
\r
631 ok( x.className == "hi", "Check single added class" );
\r
632 c.add(x, "foo bar");
\r
633 ok( x.className == "hi foo bar", "Check more added classes" );
\r
635 ok( x.className == "", "Remove all classes" );
\r
636 c.add(x, "hi foo bar");
\r
637 c.remove(x, "foo");
\r
638 ok( x.className == "hi bar", "Check removal of one class" );
\r
639 ok( c.has(x, "hi"), "Check has1" );
\r
640 ok( c.has(x, "bar"), "Check has2" );
\r
643 test("remove()", function() {
\r
644 $("#ap").children().remove();
\r
645 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
646 ok( $("#ap").children().length == 0, "Check remove" );
\r
649 $("#ap").children().remove("a");
\r
650 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
651 ok( $("#ap").children().length == 1, "Check filtered remove" );
\r
654 test("empty()", function() {
\r
655 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
\r
656 ok( $("#ap").children().length == 4, "Check elements are not removed" );
\r
659 test("eq(), gt(), lt(), contains()", function() {
\r
660 ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );
\r
661 isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" );
\r
662 isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );
\r
663 isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );
\r