Added test and fixed parents()
[jquery.git] / src / jquery / coreTest.js
index 436dcc5..58616db 100644 (file)
@@ -67,13 +67,9 @@ test("attr(String)", function() {
        ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );\r
 });\r
 \r
-test("attr(String, Function|String)", function() {\r
+test("attr(String, Function)", function() {\r
+       expect(1);\r
        ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );\r
-       ok( $('#text2').attr('value', "${this.id}")[0].value == "text2", "Set value from id" );\r
-       reset();\r
-       $('#text1, #text2').attr({value: "${this.id + 'foobar'}"});\r
-       ok( $('#text1')[0].value == "text1foobar", "Set value from id" );\r
-       ok( $('#text2')[0].value == "text2foobar", "Set value from id" );\r
 });\r
 \r
 test("attr(Hash)", function() {\r
@@ -107,19 +103,21 @@ test("attr(String, Object)", function() {
        ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );\r
 });\r
 \r
-test("attr(String, Object)x", function() {\r
-       expect(2);\r
-       stop();\r
-       $.get('data/dashboard.xml', function(xml) { \r
-         var titles = [];\r
-         $('tab', xml).each(function() {\r
-           titles.push($(this).attr('title'));\r
-         });\r
-         ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );\r
-         ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );\r
-         start();\r
+if ( location.protocol != "file:" ) {\r
+       test("attr(String, Object)x", function() {\r
+               expect(2);\r
+               stop();\r
+               $.get('data/dashboard.xml', function(xml) { \r
+               var titles = [];\r
+               $('tab', xml).each(function() {\r
+               titles.push($(this).attr('title'));\r
+               });\r
+               ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );\r
+               ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );\r
+               start();\r
+               });\r
        });\r
-});\r
+}\r
 \r
 test("css(String|Hash)", function() {\r
        expect(8);\r
@@ -390,6 +388,15 @@ test("children([String])", function() {
        isSet( $("#foo").children("[code]").get(), q("sndp", "sap"), "Check for filtered children" );\r
 });\r
 \r
+test("parent[s]([String])", function() {\r
+       ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );\r
+       ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );\r
+       ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );\r
+       \r
+       ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );\r
+       ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );\r
+       ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );\r
+});\r
 \r
 test("show()", function() {\r
        expect(1);\r
@@ -431,7 +438,21 @@ test("removeClass(String) - add three classes and remove again", function() {
        ok( pass, "Remove multiple classes" );\r
 });\r
 \r
+test("toggleClass(String)", function() {\r
+       expect(3);\r
+       var e = $("#firstp");\r
+       ok( !e.is(".test"), "Assert class not present" );\r
+       e.toggleClass("test");\r
+       ok( e.is(".test"), "Assert class present" ); \r
+       e.toggleClass("test");\r
+       ok( !e.is(".test"), "Assert class not present" );\r
+});\r
+\r
 test("removeAttr(String", function() {\r
        ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );\r
 });\r
 \r
+test("text(String)", function() {\r
+       expect(1);\r
+       ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );\r
+});\r