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
18 // make sure this is handled
\r
22 test("length", function() {
\r
23 ok( $("div").length == 2, "Get Number of Elements Found" );
\r
26 test("size()", function() {
\r
27 ok( $("div").size() == 2, "Get Number of Elements Found" );
\r
30 test("get()", function() {
\r
31 isSet( $("div").get(), q("main","foo"), "Get All Elements" );
\r
34 test("get(Number)", function() {
\r
35 ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
\r
38 test("add(String|Element|Array)", function() {
\r
39 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
40 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
\r
41 ok( $([]).add($("#form")[0].elements).length > 13, "Check elements from array" );
\r
43 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
\r
44 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
45 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
47 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
\r
48 ok( x[0].id == "x1", "Check on-the-fly element1" );
\r
49 ok( x[1].id == "x2", "Check on-the-fly element2" );
\r
52 test("each(Function)", function() {
\r
55 div.each(function(){this.foo = 'zoo';});
\r
57 for ( var i = 0; i < div.size(); i++ ) {
\r
58 if ( div.get(i).foo != "zoo" ) pass = false;
\r
60 ok( pass, "Execute a function, Relative" );
\r
63 test("index(Object)", function() {
\r
65 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
\r
66 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
\r
67 var inputElements = $('#radio1,#radio2,#check1,#check2');
\r
68 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
\r
69 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
\r
70 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
\r
71 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
\r
72 ok( inputElements.index(window) == -1, "Check for not found index" );
\r
73 ok( inputElements.index(document) == -1, "Check for not found index" );
\r
76 test("attr(String)", function() {
\r
78 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
\r
79 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
\r
80 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
\r
81 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
\r
82 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
\r
83 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
\r
84 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
\r
85 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
\r
86 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
\r
87 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
\r
88 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
\r
89 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
\r
90 //equals( "#2", $('#anchor2').attr('href'), 'Check for non-absolute href (an anchor)' ); This fails in IE because the _config.fixture is reloaded using innerHTML
\r
92 $.get("data/dashboard.xml", function(xml) {
\r
93 ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
\r
94 ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
\r
99 test("attr(String, Function)", function() {
\r
101 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
\r
102 ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
\r
105 test("attr(Hash)", function() {
\r
108 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
\r
109 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
\r
111 ok( pass, "Set Multiple Attributes" );
\r
114 test("attr(String, Object)", function() {
\r
116 var div = $("div");
\r
117 div.attr("foo", "bar");
\r
119 for ( var i = 0; i < div.size(); i++ ) {
\r
120 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
\r
122 ok( pass, "Set Attribute" );
\r
124 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
\r
126 $("#name").attr('name', 'something');
\r
127 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
\r
128 $("#check2").attr('checked', true);
\r
129 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
\r
130 $("#check2").attr('checked', false);
\r
131 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
\r
132 $("#text1").attr('readonly', true);
\r
133 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
\r
134 $("#text1").attr('readonly', false);
\r
135 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
\r
138 if ( location.protocol != "file:" ) {
\r
139 test("attr(String, Object)x", function() {
\r
142 $.get('data/dashboard.xml', function(xml) {
\r
144 $('tab', xml).each(function() {
\r
145 titles.push($(this).attr('title'));
\r
147 ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
\r
148 ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
\r
154 test("css(String|Hash)", function() {
\r
157 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
\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: 'right'});
\r
166 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
\r
167 $('#floatTest').css({cssFloat: 'left'});
\r
168 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
\r
169 $('#floatTest').css({'float': 'right'});
\r
170 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
\r
171 $('#floatTest').css({'font-size': '30px'});
\r
172 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
\r
175 test("css(String, Object)", function() {
\r
177 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
\r
178 $('#foo').css('display', 'none');
\r
179 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
\r
180 $('#foo').css('display', 'block');
\r
181 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
\r
183 $('#floatTest').css('styleFloat', 'left');
\r
184 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
\r
185 $('#floatTest').css('cssFloat', 'right');
\r
186 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
\r
187 $('#floatTest').css('float', 'left');
\r
188 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
\r
189 $('#floatTest').css('font-size', '20px');
\r
190 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
\r
193 test("text()", function() {
\r
194 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
\r
195 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
\r
198 test("wrap(String|Element)", function() {
\r
200 var defaultText = 'Try them out:'
\r
201 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
\r
202 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
\r
203 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
\r
206 var defaultText = 'Try them out:'
\r
207 var result = $('#first').wrap(document.getElementById('empty')).parent();
\r
208 ok( result.is('ol'), 'Check for element wrapping' );
\r
209 ok( result.text() == defaultText, 'Check for element wrapping' );
\r
212 test("append(String|Element|Array<Element>|jQuery)", function() {
\r
214 var defaultText = 'Try them out:'
\r
215 var result = $('#first').append('<b>buga</b>');
\r
216 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
\r
217 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
220 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
221 $('#sap').append(document.getElementById('first'));
\r
222 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
225 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
226 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
\r
227 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
230 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
231 $('#sap').append($("#first, #yahoo"));
\r
232 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
235 $("#sap").append( 5 );
\r
236 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
\r
239 ok( $("#sap").append([]), "Check for appending an empty array." );
\r
240 ok( $("#sap").append(""), "Check for appending an empty string." );
\r
241 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
\r
244 $("#sap").append(document.getElementById('form'));
\r
245 ok( $("#sap>form").size() == 1, "Check for appending a form" );
\r
249 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
\r
251 var defaultText = 'Try them out:'
\r
252 $('<b>buga</b>').appendTo('#first');
\r
253 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
\r
254 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
\r
257 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
\r
258 $(document.getElementById('first')).appendTo('#sap');
\r
259 ok( expected == $('#sap').text(), "Check for appending of element" );
\r
262 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
263 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
\r
264 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
\r
267 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
\r
268 $("#first, #yahoo").appendTo('#sap');
\r
269 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
\r
272 test("prepend(String|Element|Array<Element>|jQuery)", function() {
\r
274 var defaultText = 'Try them out:'
\r
275 var result = $('#first').prepend('<b>buga</b>');
\r
276 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
277 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
280 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
281 $('#sap').prepend(document.getElementById('first'));
\r
282 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
285 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
286 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
\r
287 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
290 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
291 $('#sap').prepend($("#first, #yahoo"));
\r
292 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
295 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
\r
297 var defaultText = 'Try them out:'
\r
298 $('<b>buga</b>').prependTo('#first');
\r
299 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
\r
300 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
\r
303 expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
\r
304 $(document.getElementById('first')).prependTo('#sap');
\r
305 ok( expected == $('#sap').text(), "Check for prepending of element" );
\r
308 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
309 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
\r
310 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
\r
313 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
\r
314 $("#yahoo, #first").prependTo('#sap');
\r
315 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
\r
318 test("before(String|Element|Array<Element>|jQuery)", function() {
\r
320 var expected = 'This is a normal link: bugaYahoo';
\r
321 $('#yahoo').before('<b>buga</b>');
\r
322 ok( expected == $('#en').text(), 'Insert String before' );
\r
325 expected = "This is a normal link: Try them out:Yahoo";
\r
326 $('#yahoo').before(document.getElementById('first'));
\r
327 ok( expected == $('#en').text(), "Insert element before" );
\r
330 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
331 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
\r
332 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
335 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
336 $('#yahoo').before($("#first, #mark"));
\r
337 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
340 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
\r
342 var expected = 'This is a normal link: bugaYahoo';
\r
343 $('<b>buga</b>').insertBefore('#yahoo');
\r
344 ok( expected == $('#en').text(), 'Insert String before' );
\r
347 expected = "This is a normal link: Try them out:Yahoo";
\r
348 $(document.getElementById('first')).insertBefore('#yahoo');
\r
349 ok( expected == $('#en').text(), "Insert element before" );
\r
352 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
353 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
\r
354 ok( expected == $('#en').text(), "Insert array of elements before" );
\r
357 expected = "This is a normal link: Try them out:diveintomarkYahoo";
\r
358 $("#first, #mark").insertBefore('#yahoo');
\r
359 ok( expected == $('#en').text(), "Insert jQuery before" );
\r
362 test("after(String|Element|Array<Element>|jQuery)", function() {
\r
364 var expected = 'This is a normal link: Yahoobuga';
\r
365 $('#yahoo').after('<b>buga</b>');
\r
366 ok( expected == $('#en').text(), 'Insert String after' );
\r
369 expected = "This is a normal link: YahooTry them out:";
\r
370 $('#yahoo').after(document.getElementById('first'));
\r
371 ok( expected == $('#en').text(), "Insert element after" );
\r
374 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
375 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
\r
376 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
379 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
380 $('#yahoo').after($("#first, #mark"));
\r
381 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
384 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
\r
386 var expected = 'This is a normal link: Yahoobuga';
\r
387 $('<b>buga</b>').insertAfter('#yahoo');
\r
388 ok( expected == $('#en').text(), 'Insert String after' );
\r
391 expected = "This is a normal link: YahooTry them out:";
\r
392 $(document.getElementById('first')).insertAfter('#yahoo');
\r
393 ok( expected == $('#en').text(), "Insert element after" );
\r
396 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
397 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
\r
398 ok( expected == $('#en').text(), "Insert array of elements after" );
\r
401 expected = "This is a normal link: YahooTry them out:diveintomark";
\r
402 $("#mark, #first").insertAfter('#yahoo');
\r
403 ok( expected == $('#en').text(), "Insert jQuery after" );
\r
406 test("end()", function() {
\r
408 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
\r
409 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
\r
411 var x = $('#yahoo');
\r
413 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
\r
416 test("find(String)", function() {
\r
417 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
\r
420 test("clone()", function() {
\r
422 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
\r
423 var clone = $('#yahoo').clone();
\r
424 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
\r
425 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
\r
428 test("is(String)", function() {
\r
430 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
\r
431 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
\r
432 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
\r
433 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
\r
434 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
\r
435 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
\r
436 ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
\r
437 ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
\r
438 ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
\r
439 ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
\r
440 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
\r
441 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
\r
442 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
\r
443 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
\r
444 ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
\r
445 ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
\r
446 ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
\r
447 ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
\r
448 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
\r
449 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
\r
450 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
\r
451 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
\r
454 test("$.extend(Object, Object)", function() {
\r
456 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
457 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
458 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
\r
459 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
\r
460 jQuery.extend(settings, options);
\r
461 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
462 isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
\r
465 test("$.extend(Object, Object, Object, Object)", function() {
\r
467 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
468 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
\r
469 options1 = { xnumber2: 1, xstring2: "x" },
\r
470 options1Copy = { xnumber2: 1, xstring2: "x" },
\r
471 options2 = { xstring2: "xx", xxx: "newstringx" },
\r
472 options2Copy = { xstring2: "xx", xxx: "newstringx" },
\r
473 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
\r
474 var settings = jQuery.extend({}, defaults, options1, options2);
\r
475 isSet( settings, merged, "Check if extended: settings must be extended" );
\r
476 isSet ( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
\r
477 isSet ( options1, options1Copy, "Check if not modified: options1 must not be modified" );
\r
478 isSet ( options2, options2Copy, "Check if not modified: options2 must not be modified" );
\r
481 test("val()", function() {
\r
483 ok( $("#text1").val() == "Test", "Check for value of input element" );
\r
484 ok( !$("#text1").val() == "", "Check for value of input element" );
\r
487 test("val(String)", function() {
\r
489 document.getElementById('text1').value = "bla";
\r
490 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
\r
491 $("#text1").val('test');
\r
492 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
\r
495 test("html(String)", function() {
\r
497 var div = $("div");
\r
498 div.html("<b>test</b>");
\r
500 for ( var i = 0; i < div.size(); i++ ) {
\r
501 if ( div.get(i).childNodes.length == 0 ) pass = false;
\r
503 ok( pass, "Set HTML" );
\r
506 test("filter()", function() {
\r
508 isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
\r
509 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
\r
510 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
\r
511 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
\r
514 test("not()", function() {
\r
516 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
\r
517 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
\r
518 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
\r
522 test("siblings([String])", function() {
\r
524 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
\r
525 isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" );
\r
526 isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
\r
527 isSet( $("#foo").siblings("form, b").get(), q("form", "floatTest"), "Check for multiple filters" );
\r
530 test("children([String])", function() {
\r
532 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
\r
533 isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
\r
534 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
\r
537 test("parent[s]([String])", function() {
\r
539 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
\r
540 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
\r
541 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
\r
542 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
\r
544 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
\r
545 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
\r
546 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
\r
547 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
\r
550 test("next/prev([String])", function() {
\r
552 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
\r
553 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
\r
554 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
\r
555 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
\r
557 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
\r
558 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
\r
559 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
\r
560 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
\r
563 test("show()", function() {
\r
565 var pass = true, div = $("div");
\r
566 div.show().each(function(){
\r
567 if ( this.style.display == "none" ) pass = false;
\r
569 ok( pass, "Show" );
\r
572 test("addClass(String)", function() {
\r
573 var div = $("div");
\r
574 div.addClass("test");
\r
576 for ( var i = 0; i < div.size(); i++ ) {
\r
577 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
\r
579 ok( pass, "Add Class" );
\r
582 test("removeClass(String) - simple", function() {
\r
584 var div = $("div").addClass("test").removeClass("test"),
\r
586 for ( var i = 0; i < div.size(); i++ ) {
\r
587 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
\r
589 ok( pass, "Remove Class" );
\r
592 test("removeClass(String) - add three classes and remove again", function() {
\r
594 var div = $("div").addClass("test").addClass("foo").addClass("bar");
\r
595 div.removeClass("test").removeClass("bar").removeClass("foo");
\r
597 for ( var i = 0; i < div.size(); i++ ) {
\r
598 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
\r
600 ok( pass, "Remove multiple classes" );
\r
603 test("toggleClass(String)", function() {
\r
605 var e = $("#firstp");
\r
606 ok( !e.is(".test"), "Assert class not present" );
\r
607 e.toggleClass("test");
\r
608 ok( e.is(".test"), "Assert class present" );
\r
609 e.toggleClass("test");
\r
610 ok( !e.is(".test"), "Assert class not present" );
\r
613 test("removeAttr(String", function() {
\r
614 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
\r
617 test("text(String)", function() {
\r
619 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
\r
622 test("$.each(Object,Function)", function() {
\r
624 $.each( [0,1,2], function(i, n){
\r
625 ok( i == n, "Check array iteration" );
\r
628 $.each( [5,6,7], function(i, n){
\r
629 ok( i == n - 5, "Check array iteration" );
\r
632 $.each( { name: "name", lang: "lang" }, function(i, n){
\r
633 ok( i == n, "Check object iteration" );
\r
637 test("$.prop", function() {
\r
639 var handle = function() { return this.id };
\r
640 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
\r
641 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
\r
644 test("$.className", function() {
\r
646 var x = $("<p>Hi</p>")[0];
\r
647 var c = $.className;
\r
649 ok( x.className == "hi", "Check single added class" );
\r
650 c.add(x, "foo bar");
\r
651 ok( x.className == "hi foo bar", "Check more added classes" );
\r
653 ok( x.className == "", "Remove all classes" );
\r
654 c.add(x, "hi foo bar");
\r
655 c.remove(x, "foo");
\r
656 ok( x.className == "hi bar", "Check removal of one class" );
\r
657 ok( c.has(x, "hi"), "Check has1" );
\r
658 ok( c.has(x, "bar"), "Check has2" );
\r
661 test("remove()", function() {
\r
662 $("#ap").children().remove();
\r
663 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
664 ok( $("#ap").children().length == 0, "Check remove" );
\r
667 $("#ap").children().remove("a");
\r
668 ok( $("#ap").text().length > 10, "Check text is not removed" );
\r
669 ok( $("#ap").children().length == 1, "Check filtered remove" );
\r
672 test("empty()", function() {
\r
673 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
\r
674 ok( $("#ap").children().length == 4, "Check elements are not removed" );
\r
677 test("eq(), gt(), lt(), contains()", function() {
\r
678 ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );
\r
679 isSet( $("#ap a").gt(0).get(), q("groups", "anchor1", "mark"), "gt()" );
\r
680 isSet( $("#ap a").lt(3).get(), q("google", "groups", "anchor1"), "lt()" );
\r
681 isSet( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );
\r
684 test("click() context", function() {
\r
685 $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
\r
686 var close = $('spanx', this); // same with $(this).find('span');
\r
687 ok( close.length == 0, "Element does not exist, length must be zero" );
\r
688 ok( !close[0], "Element does not exist, direct access to element must return undefined" );
\r
689 //console.log( close[0]); // it's the <a> and not a <span> element
\r