You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/06/03 15:50:02 UTC

svn commit: r1488993 - in /myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp: script/tobago-assert.js test/flowLayout/flowLayout-textAlign.xhtml

Author: lofwyr
Date: Mon Jun  3 13:50:02 2013
New Revision: 1488993

URL: http://svn.apache.org/r1488993
Log:
* implementing an tolerance value epsilon, for layout checks 
* using widget for layout checks

Modified:
    myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/script/tobago-assert.js
    myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/flowLayout/flowLayout-textAlign.xhtml

Modified: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/script/tobago-assert.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/script/tobago-assert.js?rev=1488993&r1=1488992&r2=1488993&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/script/tobago-assert.js (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/script/tobago-assert.js Mon Jun  3 13:50:02 2013
@@ -21,37 +21,41 @@
 
 var TobagoAssert = {
 
-  assertLeft:function (elementOrId, left) {
+  assertLeft:function (elementOrId, left, epsilon) {
     var element = TobagoAssert.jQueryElement(elementOrId);
+    epsilon = epsilon != null ? epsilon : 0;
     var offsetLeft = element.offset().left;
-    if (offsetLeft != left) {
+    if (Math.abs(offsetLeft - left) > epsilon) {
       LOG.error("The element '" + element.get(0).tagName + "' with id='" + element.attr("id")
           + "' has wrong left: expected=" + left + " actual=" + offsetLeft);
     }
   },
 
-  assertTop:function (elementOrId, top) {
+  assertTop:function (elementOrId, top, epsilon) {
     var element = TobagoAssert.jQueryElement(elementOrId);
+    epsilon = epsilon != null ? epsilon : 0;
     var offsetTop = element.offset().top;
-    if (offsetTop != top) {
+    if (Math.abs(offsetTop - top) > epsilon) {
       LOG.error("The element '" + element.get(0).tagName + "' with id='" + element.attr("id")
           + "' has wrong top: expected=" + top + " actual=" + offsetTop);
     }
   },
 
-  assertWidth:function (elementOrId, width) {
+  assertWidth:function (elementOrId, width, epsilon) {
     var element = TobagoAssert.jQueryElement(elementOrId);
+    epsilon = epsilon != null ? epsilon : 0;
     var offsetWidth = element.get(0).offsetWidth;
-    if (offsetWidth != width) {
+    if (Math.abs(offsetWidth - width) > epsilon) {
       LOG.error("The element '" + element.get(0).tagName + "' with id='" + element.attr("id")
           + "' has wrong width: expected=" + width + " actual=" + offsetWidth);
     }
   },
 
-  assertHeight:function (elementOrId, height) {
+  assertHeight:function (elementOrId, height, epsilon) {
     var element = TobagoAssert.jQueryElement(elementOrId);
+    epsilon = epsilon != null ? epsilon : 0;
     var offsetHeight = element.get(0).offsetHeight;
-    if (offsetHeight != height) {
+    if (Math.abs(offsetHeight - height) > epsilon) {
       LOG.error("The element '" + element.get(0).tagName + "' with id='" + element.attr("id")
           + "' has wrong height: expected=" + height + " actual=" + offsetHeight);
     }
@@ -101,3 +105,40 @@ var TobagoAssert = {
     return element;
   }
 };
+
+(function ($) {
+
+  $.widget("test.assertLayout", {
+
+    _create: function () {
+
+      var epsilon = this.element.data("assert-epsilon");
+
+      var left = this.element.data("assert-left");
+      if (left != null) {
+        TobagoAssert.assertLeft(this.element, left, epsilon);
+      }
+      var top = this.element.data("assert-top");
+      if (top != null) {
+        TobagoAssert.assertTop(this.element, top, epsilon);
+      }
+      var width = this.element.data("assert-width");
+      if (width != null) {
+        TobagoAssert.assertWidth(this.element, width, epsilon);
+      }
+      var height = this.element.data("assert-height");
+      if (height != null) {
+        TobagoAssert.assertHeight(this.element, height, epsilon);
+      }
+    },
+
+    _destroy: function () {
+    }
+
+  });
+
+}(jQuery));
+
+Tobago.registerListener(function() {
+    jQuery("[data-assert-width],[data-assert-height],[data-assert-left],[data-assert-top]").assertLayout();
+}, Tobago.Phase.DOCUMENT_READY);

Modified: myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/flowLayout/flowLayout-textAlign.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/flowLayout/flowLayout-textAlign.xhtml?rev=1488993&r1=1488992&r2=1488993&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/flowLayout/flowLayout-textAlign.xhtml (original)
+++ myfaces/tobago/branches/tobago-1.5.x/tobago-example/tobago-example-test/src/main/webapp/test/flowLayout/flowLayout-textAlign.xhtml Mon Jun  3 13:50:02 2013
@@ -33,7 +33,13 @@
         <tc:flowLayout textAlign="left"/>
       </f:facet>
 
-      <tc:out id="left" value="left"/>
+      <tc:out id="left" value="left">
+        <tc:dataAttribute name="assert-left" value="0"/>
+        <tc:dataAttribute name="assert-top" value="0"/>
+        <tc:dataAttribute name="assert-width" value="16"/>
+        <tc:dataAttribute name="assert-height" value="14"/>
+        <tc:dataAttribute name="assert-epsilon" value="1"/>
+      </tc:out>
     </tc:panel>
 
     <tc:separator/>
@@ -43,7 +49,13 @@
         <tc:flowLayout textAlign="right"/>
       </f:facet>
 
-      <tc:out id="right" value="right"/>
+      <tc:out id="right" value="right">
+        <tc:dataAttribute name="assert-left" value="577"/>
+        <tc:dataAttribute name="assert-top" value="31"/>
+        <tc:dataAttribute name="assert-width" value="23"/>
+        <tc:dataAttribute name="assert-height" value="14"/>
+        <tc:dataAttribute name="assert-epsilon" value="1"/>
+      </tc:out>
     </tc:panel>
 
     <tc:separator/>
@@ -53,7 +65,13 @@
         <tc:flowLayout textAlign="center"/>
       </f:facet>
 
-      <tc:out id="center" value="center"/>
+      <tc:out id="center" value="center">
+        <tc:dataAttribute name="assert-left" value="283"/>
+        <tc:dataAttribute name="assert-top" value="62"/>
+        <tc:dataAttribute name="assert-width" value="33"/>
+        <tc:dataAttribute name="assert-height" value="14"/>
+        <tc:dataAttribute name="assert-epsilon" value="1"/>
+      </tc:out>
     </tc:panel>
 
     <tc:separator/>
@@ -65,17 +83,18 @@
 
       1_XXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXX
       2_XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
-      3_XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX <tc:out id="justify" value="justify"/>
+      3_XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
+      <tc:out id="justify" value="justify">
+        <tc:dataAttribute name="assert-left" value="569"/>
+        <tc:dataAttribute name="assert-top" value="122"/>
+        <tc:dataAttribute name="assert-width" value="31"/>
+        <tc:dataAttribute name="assert-height" value="14"/>
+        <tc:dataAttribute name="assert-epsilon" value="1"/>
+      </tc:out>
       4_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     </tc:panel>
 
     <tc:script file="script/tobago-assert.js"/>
-    <tc:script onload="TobagoAssert.assertLayout('page:left', 0, 0, 16, 14);"/>
-    <tc:script onload="TobagoAssert.assertLayout('page:right', 577, 31, 23, 14);"/>
-    <tc:script onload="TobagoAssert.assertLayout('page:center', 283, 62, 33, 14);"/>
-    <tc:script onload="TobagoAssert.assertLayout('page:justify', 569, 122, 31, 14);"/>
-
-    <!-- TODO: the values are not exact, write a tolerance value epsilon -->
 
   </tc:page>
 </f:view>