Author: hlship
Date: Wed Jun 29 00:17:42 2011
New Revision: 1140918

URL: http://svn.apache.org/viewvc?rev=1140918&view=rev
Log:
TAP5-999: Rewrite the JS unit testing script to use simple <DIV> elements, not 
a complex table

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TapestryJavaScriptTests.groovy
    
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/JavaScriptTests.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.css
    
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.js

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TapestryJavaScriptTests.groovy
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TapestryJavaScriptTests.groovy?rev=1140918&r1=1140917&r2=1140918&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TapestryJavaScriptTests.groovy
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TapestryJavaScriptTests.groovy
 Wed Jun 29 00:17:42 2011
@@ -9,9 +9,11 @@ class TapestryJavaScriptTests extends Ta
     void basic_javascript_tests() {
         openLinks "JavaScript Unit Tests"
 
-        def resultClass = 
getAttribute("//table[@class='js-results']/caption/@class")
-        
-        if (resultClass == 'failures') {
+        def caption = getText("//div[@class='js-results']/p[@class='caption']")
+
+        def matches = caption =~ /(\d+) failed/
+
+        if (matches[0][1] != "0"){
             fail "Some JavaScript unit tests failed"
         }
     }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/JavaScriptTests.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/JavaScriptTests.tml?rev=1140918&r1=1140917&r2=1140918&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/JavaScriptTests.tml
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/JavaScriptTests.tml
 Wed Jun 29 00:17:42 2011
@@ -6,250 +6,210 @@
     This page executes a number of JavaScript tests.
   </p>
 
-  <table id="results-table">
+  <div id="tests">
 
-    <tr>
-      <td>
-        <pre>
-          assertEqual(isEmpty(null), true)
-          assertEqual(isEmpty(undefined), true)
-          assertEqual(isEmpty([]), true)
-          assertEqual(isEmpty([1]), false)
+    <div>
+      <p> Checks for T5.arrays.isEmpty()
+        </p>
+      <pre>
+        assertEqual(isEmpty(null), true)
+        assertEqual(isEmpty(undefined), true)
+        assertEqual(isEmpty([]), true)
+        assertEqual(isEmpty([1]), false)
     </pre>
-      </td>
-      <td>
-        Checks for T5.arrays.isEmpty()
-    </td>
-    </tr>
-    
-        <tr>
-      <td>
-        <pre>
-          assertEqual(isNonEmpty(null), false)
-          assertEqual(isNonEmpty(undefined), false)
-          assertEqual(isNonEmpty([]), false)
-          assertEqual(isNonEmpty([1]), true)
-    </pre>
-      </td>
-      <td>
-        Checks for T5.arrays.isNonEmpty()
-    </td>
-    </tr>
 
-    <tr>
-      <td>
+    </div>
+    <div>
+      <p> Checks for T5.arrays.isNonEmpty()
+        </p>
+      <pre>
+        assertEqual(isNonEmpty(null), false)
+        assertEqual(isNonEmpty(undefined), false)
+        assertEqual(isNonEmpty([]),
+        false)
+        assertEqual(isNonEmpty([1]), true)
+    </pre>
+    </div>
+    <div>
+      <p> Map() on null returns an empty array        
+        </p>
+      <pre>
         assertEqual(map(null, null), [])
-    </td>
-      <td>
-        Map() on null returns an empty array
-    </td>
-    </tr>
-
-    <tr>
-      <td>
-        assertEqual(map(null, undefined), [])
-    </td>
-      <td>
-        Map() on undefined returns an empty array
-    </td>
-    </tr>
+        </pre>
+    </div>
 
-    <tr>
-      <td>
+    <div>
+      <p> Map() on undefined returns an empty array    
+    </p>
+      <pre>
+        assertEqual(map(null, undefined), [])    
+    </pre>
+    </div>
+
+    <div>
+      <p>Map() on empty array returns an empty array</p>
+      <pre>
         assertEqual(map(null, []), [])
-    </td>
-      <td>Map() on empty array returns an empty array</td>
-    </tr>
-
-    <tr>
-      <td>
-        assertEqual(map(function(e) { return e + 100; }, [1, 2, 3]), [101, 
102, 103])
-        </td>
-      <td>
-        The normal use of map().
-        </td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          assertEqual(map(function(e, index) { return (e + 100) + "@" + index; 
}, [1, 2, 3]),
-          ["101@0", "102@1",
-          "103@2"])            
-        </pre>
-      </td>
-      <td>
-        The normal use of map().
-        </td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          var initial = { };
-          assertSame(reduce(function() { }, initial, []), initial);
-        </pre>
-      </td>
-      <td>
-        The initial value is returned, as is, when no reducing occurs due to 
empty/null/undefined list.
-        </td>
-    </tr>
-
-    <tr>
-
-      <td>
-        <pre>
-          assertEqual(reduce(function(o, value, index) {
-          o[value] = index;
-
-          return o;
-          }, {}, ["fred", "barney",
-          "wilma"]),
-          { fred: 0, barney: 1, wilma: 2 })
-        </pre>
-      </td>
-      <td>
-        Show that the index of each element is passed to the reducer 
function.</td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          var initial = [1, 2, 3]
-          assertSame(without(9, initial), initial)
-        </pre>
-      </td>
-      <td>
-        Removing a value that does not exist in the array returns the array 
unchanged
-        </td>
-    </tr>
+      </pre>
+    </div>
+
+
+    <div>
+      <p> The normal use of map().
+    </p>
+      <pre>
+        assertEqual(map(function(e) { return e + 100; }, [1, 2, 3]), [101, 
102, 103])   
+    </pre>
+    </div>
+
+    <div>
+      <p> Optional second parameter to map() is an index number.    </p>
+      <pre>
+        assertEqual(map(function(e, index) { return (e + 100) + "@" + index; 
}, [1, 2, 3]),
+        ["101@0", "102@1",
+        "103@2"])                
+    </pre>
+    </div>
 
-    <tr>
-      <td>
+    <div>
+      <p> The initial value is returned, as is, when no reducing occurs due to 
empty/null/undefined list.
+    </p>
+      <pre>
+        var initial = { };
+        assertSame(reduce(function() { }, initial, []), initial);   
+    </pre>
+    </div>
+
+    <div>
+      <p> Show that the index of each element is passed to the reducer 
function.</p>
+      <pre>
+        assertEqual(reduce(function(o, value, index) {
+        o[value] = index; return o;
+        }, {}, ["fred", "barney",
+        "wilma"]),
+        { fred: 0, barney: 1, wilma: 2 })
+        </pre>
+
+    </div>
+
+    <div>
+      <p> Removing a value that does not exist in the array returns the array 
unchanged.
+    </p>
+      <pre>
+        var initial = [1, 2, 3]
+        assertSame(without(9, initial), initial)
+        </pre>
+    </div>
+
+    <div>
+      <p> Multiple matches should all be removed.</p>
+      <pre>
         assertEqual(without(2, [1, 2, 2, 3, 4, 2, 5]), [1, 3, 4, 5])
-        </td>
-      <td>
-        Multiple matches should all be removed
-        </td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          var initial = [1, 2, 3]
-          without(2, initial)
-          assertEqual(initial, [1, 2, 3])
-          </pre>
-      </td>
-      <td>
-        The array should not be changed even if values are removed from the 
result
-        </td>
-    </tr>
-
-    <tr>
-      <td>assertEqual(mapcat(null,null), [])</td>
-      <td>mapcat() on empty/null/undefined returns empty list</td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          assertEqual(mapcat(function (value) {
-          var out = []
-          for (var i = 0; i &lt; value; i++) { out.push(value); }
-          return out;
-          }, [1, 3, 5]),
-          [1, 3, 3, 3, 5, 5, 5, 5, 5])            
-            </pre>
-      </td>
-      <td>
-        Basic execution of mapcat().
-      </td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          var message = { }
-          var rcvd;
+</pre>
+    </div>
+
+    <div>
+      <p> The array should not be changed even if values are removed from the 
result.
+</p>
+      <pre>
+        var initial = [1, 2, 3]
+        without(2, initial)
+        assertEqual(initial, [1, 2, 3])
+</pre>
+    </div>
+
+    <div>
+      <p>mapcat() on empty/null/undefined returns empty list.
+    </p>
+      <pre>
+        assertEqual(mapcat(null,null), [])</pre>
+    </div>
+
+    <div>
+      <p> Basic execution of mapcat().
+  </p>
+      <pre>
+        assertEqual(mapcat(function (value) {
+        var out = []
+        for (var i = 0; i &lt; value; i++) { out.push(value); }
+        return out;
+        }, [1, 3, 5]),
+        [1, 3, 3, 3, 5, 5, 5, 5, 5])            
+  </pre>
+    </div>
+
+    <div>
+      <p> Ensure that the message object passed to pub() is delivered to the 
listener.</p>
+      <pre>
+        var message = { }
+        var rcvd;
 
-          sub("foo", function(m) { rcvd = m; })
+        sub("foo", function(m) { rcvd = m; })
 
-          pub("foo", message)
+        pub("foo", message)
 
-          assertSame(rcvd,
-          message)        
+        assertSame(rcvd, message)        
         </pre>
-      </td>
-      <td>
-        Ensure that the message object passed to pub() is delivered to the 
listener.</td>
-    </tr>
+    </div>
 
-    <tr>
-      <td>
-        <pre>
-          var count = 0;
+    <div>
+      <p>Check that the function returned from sub() can be used to cancel 
message reciept.</p>
+      <pre>
+        var count = 0;
 
-          pub("foo"); assertEqual(count, 0)
+        pub("foo"); assertEqual(count, 0)
 
-          var unsub = sub("foo", function() { count++; } )
+        var unsub = sub("foo", function() { count++; } )
 
-          pub("foo");
-          assertEqual(count, 1)
+        pub("foo");
+        assertEqual(count, 1)
 
-          pub("foo"); assertEqual(count, 2)
+        pub("foo"); assertEqual(count, 2)
 
-          pub("bar"); assertEqual(count, 2)
+        pub("bar"); assertEqual(count, 2)
 
-          unsub()
+        unsub()
 
-          pub("foo");
-          assertEqual(count, 2)
+        pub("foo");
+        assertEqual(count, 2)
           </pre>
-      </td>
-      <td>
-        Check that the function returned from sub() can be used to cancel 
message reciept</td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          var pubs = []
-
-          sub("foo/bar", function() { pubs.push("foo/bar"); })
-          sub("foo", function() {
-          pubs.push("foo");
-          })
+    </div>
 
-          pub("foo/bar")
+    <div>
+      <p> Check that messages are published to less specific selectors after 
more specific.
+</p>
+      <pre>
+        var pubs = []
 
-          assertEqual(pubs, ["foo/bar", "foo"])                
+        sub("foo/bar", function() { pubs.push("foo/bar"); })
+        sub("foo", function() {
+        pubs.push("foo");
+        })
+
+        pub("foo/bar")
+
+        assertEqual(pubs, ["foo/bar", "foo"])                
         </pre>
-      </td>
-      <td>
-        Check that messages are published to less specific selectors after 
more specific.
-        </td>
-    </tr>
-
-    <tr>
-      <td>
-        <pre>
-          var pubs = []
-
-          sub("foo/bar", function() { pubs.push("foo/bar"); })
-          sub("foo", function() {
-          pubs.push("foo");
-          })
+    </div>
+
+    <div>
+      <p>Check that messages to less specific selectors do not invoke 
listeners of more specific selectors.   </p>
+      <pre>
+        var pubs = []
 
-          pub("foo")
+        sub("foo/bar", function() { pubs.push("foo/bar"); })
 
-          assertEqual(pubs, ["foo"])                
+        sub("foo", function() {
+        pubs.push("foo");
+        })
+
+        pub("foo")
+
+        assertEqual(pubs, ["foo"])                        
         </pre>
-      </td>
-      <td>
-        Check that messages to less specific selectors do not invoke listeners 
of more specific selectors.        </td>
-    </tr>
-  </table>
+    </div>
+
+  </div>
 
   <script>
 <![CDATA[
@@ -259,6 +219,9 @@
     mapcat = T5.arrays.mapcat
     reduce = T5.arrays.reduce
     without = T5.arrays.without
+    filter = T5.arrays.filter
+    remove = T5.arrays.remove
+    first = T5.arrays.first
 
     pub = T5.pub
     sub = T5.sub
@@ -267,7 +230,7 @@
     assertEqual = JST.assertEqual
     assertSame = JST.assertSame
 
-    JST.runTestSuite("results-table");
+    JST.runTestSuite("tests");
     ]]>
   </script>
 </html>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.css
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.css?rev=1140918&r1=1140917&r2=1140918&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.css
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.css
 Wed Jun 29 00:17:42 2011
@@ -1,36 +1,26 @@
 
-TABLE.js-results { width: 100%; }
-
-TABLE.js-results THEAD TR
+DIV.js-results .caption
 {
     font-weight: bold;
-    background-color: black;
+    background-color: #e5e5e5;
     color: white;
 }
 
-TABLE.js-results TR.odd
+DIV.js-results DIV.odd
 {
   background-color: #e5e5e5;
 }
 
-TABLE.js-results TR.active
+DIV.js-results .active
 {
   font-weight: bold;
   background-color: #ffff00;
 }
 
-TABLE.js-results TR.pass {
+DIV.js-results .pass {
     color: green;    
 }
 
-TABLE.js-results CAPTION {
-  font-weight: bold;
-}
-
-TABLE.js-results CAPTION.success { color: green; }
-
-TABLE.js-results CAPTION.failures { color: red; }
-
-TABLE.js-results TR.fail { color: red; }
-
-TABLE.js-results TR.exception { color: red; font-family: italic; }
\ No newline at end of file
+DIV.js-results .fail {
+    color: red;    
+}
\ No newline at end of file

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.js?rev=1140918&r1=1140917&r2=1140918&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.js
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/js-testing.js
 Wed Jun 29 00:17:42 2011
@@ -44,10 +44,10 @@ var JST = (function() {
        var $fail = {};
 
        function fail(text) {
-               resultElement.next().insert({
+               resultElement.insert({
                        top : "FAIL - ",
-                       bottom : "<hr>" + text
-               }).up().addClassName("fail");
+                       after : "<hr>" + text
+               }).up("div").addClassName("fail");
 
                throw $fail;
        }
@@ -79,32 +79,32 @@ var JST = (function() {
                var passCount = 0;
                var failCount = 0;
 
-               $(elementId).insert({
-                       top : 
"<thead><th>Test</th><th>Description</th></tr></thead>"
-               });
-
-               $(elementId).addClassName("js-results").select("tbody 
tr:odd").each(
+               $(elementId).addClassName("js-results").select("div:odd").each(
                                function(e) {
                                        e.addClassName("odd");
                                });
 
-               $(elementId).select("tbody tr").each(function(row) {
+               $(elementId).select("div").each(function(test) {
 
-                       row.addClassName("active");
+                       test.addClassName("active");
 
-                       row.scrollTo();
+                       test.scrollTo();
 
-                       resultElement = $(row).select("td")[0];
+                       resultElement = test.down("p");
                        resultNoted = false;
 
+                       var testCode = test.down("pre").textContent;
+
                        try {
-                               eval(resultElement.textContent);
+                               eval(testCode);
 
                                passCount++;
 
-                               resultElement.next().insert({
+                               resultElement.insert({
                                        top : "PASS - "
-                               }).up().addClassName("pass");
+                               });
+
+                               test.addClassName("pass");
 
                        } catch (e) {
                                failCount++;
@@ -112,21 +112,23 @@ var JST = (function() {
                                if (e !== $fail) {
                                        resultElement.next().insert({
                                                top : "EXCEPTION - ",
-                                               bottom : "<hr>" + toString(e)
-                                       }).up().addClassName("exception");
+                                               after : "<hr><pre>" + 
toString(e) + "</pre>"
+                                       });
+
+                                       test.addClassName("fail");
                                }
                        }
 
-                       row.removeClassName("active");
+                       test.removeClassName("active");
                });
 
                $(elementId)
                                .insert(
                                                {
-                                                       bottom : "<caption 
class='#{class}'>Results: #{pass} pass / #{fail} fail</caption>"
+                                                       top : "<p 
class='caption #{class}'>Results: #{pass} passed / #{fail} failed</p>"
                                                                        
.interpolate({
-                                                                               
class : failCount == 0 ? "success"
-                                                                               
                : "failures",
+                                                                               
class : failCount == 0 ? "pass"
+                                                                               
                : "fail",
                                                                                
pass : passCount,
                                                                                
fail : failCount
                                                                        })


Reply via email to