Added test for filter(Array), fixed bug #446
[jquery.git] / src / jquery / coreTest.js
1 module("core");
2
3 test("Basic requirements", function() {
4         expect(7);
5         ok( Array.prototype.push, "Array.push()" );
6         ok( Function.prototype.apply, "Function.apply()" );
7         ok( document.getElementById, "getElementById" );
8         ok( document.getElementsByTagName, "getElementsByTagName" );
9         ok( RegExp, "RegExp" );
10         ok( jQuery, "jQuery" );
11         ok( $, "$()" );
12 });
13
14 test("length", function() {
15         ok( $("div").length == 2, "Get Number of Elements Found" );
16 });
17
18 test("size()", function() {
19         ok( $("div").size() == 2, "Get Number of Elements Found" );
20 });
21
22 test("get()", function() {
23         isSet( $("div").get(), q("main","foo"), "Get All Elements" );
24 });
25
26 test("get(Number)", function() {
27         ok( $("div").get(0) == document.getElementById("main"), "Get A Single Element" );
28 });
29
30 test("each(Function)", function() {
31         expect(1);
32         var div = $("div");
33         div.each(function(){this.foo = 'zoo';});
34         var pass = true;
35         for ( var i = 0; i < div.size(); i++ ) {
36           if ( div.get(i).foo != "zoo" ) pass = false;
37         }
38         ok( pass, "Execute a function, Relative" );
39 });
40
41 test("index(Object)", function() {
42         expect(8);
43         ok( $([window, document]).index(window) == 0, "Check for index of elements" );
44         ok( $([window, document]).index(document) == 1, "Check for index of elements" );
45         var inputElements = $('#radio1,#radio2,#check1,#check2');
46         ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
47         ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
48         ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
49         ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
50         ok( inputElements.index(window) == -1, "Check for not found index" );
51         ok( inputElements.index(document) == -1, "Check for not found index" );
52 });
53
54 test("attr(String)", function() {
55         expect(12);
56         ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
57         ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
58         ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
59         ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
60         ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
61         ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
62         ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
63         ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
64         ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
65         ok( $('#name').attr('name') == "name", 'Check for name attribute' );
66         ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
67         ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
68 });
69
70 test("attr(Hash)", function() {
71         expect(1);
72         var pass = true;
73         $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
74           if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
75         });
76         ok( pass, "Set Multiple Attributes" );
77 });
78
79 test("attr(String, Object)", function() {
80         expect(6);
81         var div = $("div");
82         div.attr("foo", "bar");
83         var pass = true;
84         for ( var i = 0; i < div.size(); i++ ) {
85           if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
86         }
87         ok( pass, "Set Attribute" );
88         
89         $("#name").attr('name', 'something');
90         ok( $("#name").name() == 'something', 'Set name attribute' );
91         $("#check2").attr('checked', true);
92         ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
93         $("#check2").attr('checked', false);
94         ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
95         $("#text1").attr('readonly', true);
96         ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
97         $("#text1").attr('readonly', false);
98         ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
99 });
100
101 test("attr(String, Object)x", function() {
102         expect(2);
103         stop();
104         $.get('data/dashboard.xml', function(xml) { 
105           var titles = [];
106           $('tab', xml).each(function() {
107             titles.push($(this).attr('title'));
108           });
109           ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
110           ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
111           start();
112         });
113 });
114
115 test("css(String|Hash)", function() {
116         expect(8);
117         
118         ok( $('#main').css("display") == 'none', 'Check for css property "display"');
119         
120         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
121         $('#foo').css({display: 'none'});
122         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
123         $('#foo').css({display: 'block'});
124         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
125         
126         $('#floatTest').css({styleFloat: 'right'});
127         ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
128         $('#floatTest').css({cssFloat: 'left'});
129         ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
130         $('#floatTest').css({'float': 'right'});
131         ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
132         $('#floatTest').css({'font-size': '30px'});
133         ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
134 });
135
136 test("css(String, Object)", function() {
137         expect(7);
138         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
139         $('#foo').css('display', 'none');
140         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
141         $('#foo').css('display', 'block');
142         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
143         
144         $('#floatTest').css('styleFloat', 'left');
145         ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
146         $('#floatTest').css('cssFloat', 'right');
147         ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
148         $('#floatTest').css('float', 'left');
149         ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
150         $('#floatTest').css('font-size', '20px');
151         ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
152 });
153
154 test("text()", function() {
155         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
156         ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
157 });
158
159 test("wrap(String|Element)", function() {
160         expect(4);
161         var defaultText = 'Try them out:'
162         var result = $('#first').wrap('<div class="red"><span></span></div>').text();
163         ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
164         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
165
166         reset();
167         var defaultText = 'Try them out:'
168         var result = $('#first').wrap(document.getElementById('empty')).parent();
169         ok( result.is('ol'), 'Check for element wrapping' );
170         ok( result.text() == defaultText, 'Check for element wrapping' );
171 });
172
173 test("append(String|Element|Array&lt;Element&gt;)", function() {
174         expect(4);
175         var defaultText = 'Try them out:'
176         var result = $('#first').append('<b>buga</b>');
177         ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
178         ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
179         
180         reset();
181         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
182         $('#sap').append(document.getElementById('first'));
183         ok( expected == $('#sap').text(), "Check for appending of element" );
184         
185         reset();
186         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
187         $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
188         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
189 });
190
191 test("prepend(String|Element|Array&lt;Element&gt;)", function() {
192         expect(4);
193         var defaultText = 'Try them out:'
194         var result = $('#first').prepend('<b>buga</b>');
195         ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
196         ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
197         
198         reset();
199         expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
200         $('#sap').prepend(document.getElementById('first'));
201         ok( expected == $('#sap').text(), "Check for prepending of element" );
202
203         reset();
204         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
205         $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
206         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
207 });
208
209 test("before(String|Element|Array&lt;Element&gt;)", function() {
210         expect(3);
211         var expected = 'This is a normal link: bugaYahoo';
212         $('#yahoo').before('<b>buga</b>');
213         ok( expected == $('#en').text(), 'Insert String before' );
214         
215         reset();
216         expected = "This is a normal link: Try them out:Yahoo";
217         $('#yahoo').before(document.getElementById('first'));
218         ok( expected == $('#en').text(), "Insert element before" );
219         
220         reset();
221         expected = "This is a normal link: Try them out:diveintomarkYahoo";
222         $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
223         ok( expected == $('#en').text(), "Insert array of elements before" );
224 });
225
226 test("after(String|Element|Array&lt;Element&gt;)", function() {
227         expect(3);
228         var expected = 'This is a normal link: Yahoobuga';
229         $('#yahoo').after('<b>buga</b>');
230         ok( expected == $('#en').text(), 'Insert String after' );
231         
232         reset();
233         expected = "This is a normal link: YahooTry them out:";
234         $('#yahoo').after(document.getElementById('first'));
235         ok( expected == $('#en').text(), "Insert element after" );
236
237         reset();
238         expected = "This is a normal link: YahooTry them out:diveintomark";
239         $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
240         ok( expected == $('#en').text(), "Insert array of elements after" );
241 });
242
243 test("end()", function() {
244         expect(2);
245         ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
246         ok( $('#yahoo').end(), 'Check for end with nothing to end' );
247 });
248
249 test("find(String)", function() {
250         ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
251 });
252
253 test("clone()", function() {
254         expect(3);
255         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
256         var clone = $('#yahoo').clone();
257         ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
258         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
259 });
260
261 test("filter()", function() {
262         isSet( $("input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
263         isSet( $("p").filter(["#ap", "#sndp"]).get(), q("ap", "sndp"), "filter(Array&lt;String&gt;)" );
264 });
265
266 test("filter(String) - execute callback in fitting context", function() {
267         expect(1);
268         $("input").filter(":checked",function(i){ 
269                 ok( this == q("radio2", "check1")[i], "Filter elements, context" );
270         });
271 });
272
273 test("filter(String) - execute callback in not-fitting context", function() {
274         expect(1);
275         $("#main > p#ap > a").filter("#foobar",function(){},function(i){
276                 ok( this == q("google","groups", "mark")[i], "Filter elements, else context" );
277         });
278 });
279
280 test("not(String)", function() {
281         ok($("#main > p#ap > a").not("#google").length == 2, "not('selector')")
282         isSet( $("p").not("#ap, #sndp").get(), q("firstp", "en", "sap", "first", "result"), "not('selector, selector')" );
283 });
284
285 test("is(String)", function() {
286         expect(22);
287         ok( $('#form').is('form'), 'Check for element: A form must be a form' );
288         ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
289         ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
290         ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
291         ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
292         ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
293         ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
294         ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
295         ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
296         ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
297         ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
298         ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
299         ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
300         ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
301         ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
302         ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
303         ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
304         ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
305         ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
306         ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
307         ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
308         ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
309 });
310
311 test("$.extend(Object, Object)", function() {
312         expect(2);
313         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
314                 options =     { xnumber2: 1, xstring2: "x", xxx: "newstring" },
315                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
316                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
317         jQuery.extend(settings, options);
318         isSet( settings, merged, "Check if extended: settings must be extended" );
319         isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
320 });
321
322 test("expressions - element", function() {
323         expect(5);
324         ok( $("*").size() >= 30, "Select all" );
325         t( "Element Selector", "div", ["main","foo"] );
326         t( "Element Selector", "body", ["body"] );
327         t( "Element Selector", "html", ["html"] );
328         t( "Parent Element", "div div", ["foo"] );
329 });
330
331 test("expressions - id", function() {
332         expect(5);
333         t( "ID Selector", "#body", ["body"] );
334         t( "ID Selector w/ Element", "body#body", ["body"] );
335         t( "ID Selector w/ Element", "ul#first", [] );
336         
337         t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"]  );
338         t( "All Children of ID with no children", "#firstUL/*", []  );
339 });
340
341 test("expressions - class", function() {
342         expect(4);
343         t( "Class Selector", ".blog", ["mark","simon"] );
344         t( "Class Selector", ".blog.link", ["simon"] );
345         t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
346         t( "Parent Class Selector", "p .blog", ["mark","simon"] );
347 });
348
349 test("expressions - multiple", function() {
350         expect(4);
351         t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
352         t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
353         t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
354         t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
355 });
356
357 test("expressions - child and adjacent", function() {
358         expect(14);
359         t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
360         t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
361         t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
362         t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
363         t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
364         t( "All Children", "code > *", ["anchor1","anchor2"] );
365         t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
366         t( "Adjacent", "a + a", ["groups"] );
367         t( "Adjacent", "a +a", ["groups"] );
368         t( "Adjacent", "a+ a", ["groups"] );
369         t( "Adjacent", "a+a", ["groups"] );
370         t( "Adjacent", "p + p", ["ap","en","sap"] );
371         t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
372         t( "First Child", "p:first-child", ["firstp","sndp"] );
373 });
374
375 test("expressions - attributes", function() {
376         expect(16);
377         t( "Attribute Exists", "a[@title]", ["google"] );
378         t( "Attribute Exists", "*[@title]", ["google"] );
379         t( "Attribute Exists", "[@title]", ["google"] );
380         
381         t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
382         t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
383         t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
384         t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
385         t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
386         t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
387         
388         t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
389         t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
390         t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
391         
392         t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
393         
394         t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
395         t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
396         t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
397 });
398
399 test("expressions - pseudo (:) selctors", function() {
400         expect(30);
401         t( "First Child", "p:first-child", ["firstp","sndp"] );
402         t( "Last Child", "p:last-child", ["sap"] );
403         t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
404         t( "Empty", "ul:empty", ["firstUL"] );
405         t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
406         t( "Disabled UI Element", "input:disabled", ["text2"] );
407         t( "Checked UI Element", "input:checked", ["radio2","check1"] );
408         t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
409         t( "Text Contains", "a:contains('Google')", ["google","groups"] );
410         t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
411         t( "Element Preceded By", "p ~ div", ["foo"] );
412         t( "Not", "a.blog:not(.link)", ["mark"] );
413         
414         t( "nth Element", "p:nth(1)", ["ap"] );
415         t( "First Element", "p:first", ["firstp"] );
416         t( "Last Element", "p:last", ["first"] );
417         t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
418         t( "Odd Elements", "p:odd", ["ap","en","first"] );
419         t( "Position Equals", "p:eq(1)", ["ap"] );
420         t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
421         t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
422         t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
423         t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
424         t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
425         
426         t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3"] );
427         t( "Form element :radio", ":radio", ["radio1", "radio2"] );
428         t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
429         t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name"] );
430         t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
431         t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
432         t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
433 });
434
435 test("expressions - basic xpath", function() {
436         expect(14);
437         ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
438         t( "All Div Elements", "//div", ["main","foo"] );
439         t( "Absolute Path", "/html/body", ["body"] );
440         t( "Absolute Path w/ *", "/* /body", ["body"] );
441         t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
442         t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
443         t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
444         t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
445         t( "Attribute Exists", "//a[@title]", ["google"] );
446         t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
447         t( "Parent Axis", "//p/..", ["main","foo"] );
448         t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
449         t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
450         t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
451 });
452
453 test("val()", function() {
454         expect(2);
455         ok( $("#text1").val() == "Test", "Check for value of input element" );
456         ok( !$("#text1").val() == "", "Check for value of input element" );
457 });
458
459 test("val(String)", function() {
460         expect(2);
461         document.getElementById('text1').value = "bla";
462         ok( $("#text1").val() == "bla", "Check for modified value of input element" );
463         $("#text1").val('test');
464         ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
465 });
466
467 test("html(String)", function() {
468         expect(1);
469         var div = $("div");
470         div.html("<b>test</b>");
471         var pass = true;
472         for ( var i = 0; i < div.size(); i++ ) {
473           if ( div.get(i).childNodes.length == 0 ) pass = false;
474         }
475         ok( pass, "Set HTML" );
476 });
477
478 test("id()", function() {
479         expect(3);
480         ok( $(document.getElementById('main')).id() == "main", "Check for id" );
481         ok( $("#foo").id() == "foo", "Check for id" );
482         ok( !$("head").id(), "Check for id" );
483 });
484
485 test("title()", function() {
486         expect(2);
487         ok( $(document.getElementById('google')).title() == "Google!", "Check for title" );
488         ok( !$("#yahoo").title(), "Check for title" );
489 });
490
491 test("name()", function() {
492         expect(3);
493         ok( $(document.getElementById('text1')).name() == "action", "Check for name" );
494         ok( $("#hidden1").name() == "hidden", "Check for name" );
495         ok( !$("#area1").name(), "Check for name" );
496 });
497
498
499 test("siblings([String])", function() {
500         expect(3);
501         isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
502         isSet( $("#sndp").siblings("[code]").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 
503         isSet( $("#sndp").siblings("[a]").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
504 });
505
506 test("children([String])", function() {
507         expect(2);
508         isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
509         isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );
510 });
511
512
513 test("show()", function() {
514         expect(1);
515         var pass = true, div = $("div");
516         div.show().each(function(){
517           if ( this.style.display == "none" ) pass = false;
518         });
519         ok( pass, "Show" );
520 });
521
522 test("addClass(String)", function() {
523         var div = $("div");
524         div.addClass("test");
525         var pass = true;
526         for ( var i = 0; i < div.size(); i++ ) {
527          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
528         }
529         ok( pass, "Add Class" );
530 });
531
532 test("removeClass(String) - simple", function() {
533         expect(1);
534         var div = $("div").addClass("test").removeClass("test"),
535                 pass = true;
536         for ( var i = 0; i < div.size(); i++ ) {
537                 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
538         }
539         ok( pass, "Remove Class" );
540 });
541
542 test("removeClass(String) - add three classes and remove again", function() {
543         expect(1);
544         var div = $("div").addClass("test").addClass("foo").addClass("bar");
545         div.removeClass("test").removeClass("bar").removeClass("foo");
546         var pass = true;
547         for ( var i = 0; i < div.size(); i++ ) {
548          if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
549         }
550         ok( pass, "Remove multiple classes" );
551 });