You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2013/11/25 21:11:19 UTC

[3/5] git commit: More corrections to fix tests broken when using jQuery infrastructure

More corrections to fix tests broken when using jQuery infrastructure


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a5de2b69
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a5de2b69
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a5de2b69

Branch: refs/heads/master
Commit: a5de2b69edc7be63328d056d94e933e16dfdcaf0
Parents: dd0a273
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Nov 25 11:14:50 2013 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Nov 25 11:14:50 2013 -0800

----------------------------------------------------------------------
 .../META-INF/modules/app/test-support.coffee     | 14 ++++++++++++++
 .../integration/app1/components/Border.java      |  4 ++--
 .../META-INF/assets/ExpressionInJsFunction.js    | 16 ++++++++++------
 .../apache/tapestry5/test/SeleniumTestCase.java  | 19 ++++++++++++++-----
 4 files changed, 40 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a5de2b69/tapestry-core/src/test/coffeescript/META-INF/modules/app/test-support.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/coffeescript/META-INF/modules/app/test-support.coffee b/tapestry-core/src/test/coffeescript/META-INF/modules/app/test-support.coffee
new file mode 100644
index 0000000..ffbb583
--- /dev/null
+++ b/tapestry-core/src/test/coffeescript/META-INF/modules/app/test-support.coffee
@@ -0,0 +1,14 @@
+# Provide test support functions that can be addressed via Selenium.
+
+# TODO: Maybe move this to main, for external re-use?
+
+define ["t5/core/dom"],
+  (dom) ->
+
+    exports =
+      findCSSMatchCount: (selector) -> dom.body.find(selector).length
+      doesNotExist: (elementId) -> (dom elementId) is null
+
+    window.testSupport = exports
+
+    return exports
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a5de2b69/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java
index 404f46c..ef117a1 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2011 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import org.apache.tapestry5.services.Request;
  * Here's a component with a template, including a t:body element. Really should rename this to "Layout" as that's the
  * T5 naming.
  */
-@Import(stylesheet = "context:css/app.css", module = "bootstrap/collapse")
+@Import(stylesheet = "context:css/app.css", module = {"bootstrap/collapse", "app/test-support"})
 public class Border
 {
     @Inject

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a5de2b69/tapestry-core/src/test/resources/META-INF/assets/ExpressionInJsFunction.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/META-INF/assets/ExpressionInJsFunction.js b/tapestry-core/src/test/resources/META-INF/assets/ExpressionInJsFunction.js
index da27472..d4116c3 100644
--- a/tapestry-core/src/test/resources/META-INF/assets/ExpressionInJsFunction.js
+++ b/tapestry-core/src/test/resources/META-INF/assets/ExpressionInJsFunction.js
@@ -1,7 +1,11 @@
-function test_func() {
-    $('target').setValue("test1");
-}
+require(["t5/core/dom"], function (dom) {
+
+    window.test_func = function () {
+        dom('target').value("test1");
+    };
+
+    window.test_func_with_map = function () {
+        dom('target').value("{key=test2}");
+    };
+});
 
-function test_func_with_map() {
-    $('target').setValue("{key=test2}");
-}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a5de2b69/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
----------------------------------------------------------------------
diff --git a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
index e2b6a90..db14829 100644
--- a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
+++ b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java
@@ -1458,14 +1458,19 @@ public abstract class SeleniumTestCase extends Assert implements Selenium
     /**
      * Waits, up to the page load limit for an element (identified by a CSS rule) to exist
      * (it is not assured that the element will be visible).
+     * <p/>
+     * This implementation only works if the application provides a function onto the
+     * window object:  "testSupport.findCSSMatchCount()" which accepts a CSS rule and returns the number
+     * of matching elements.
      *
-     * @param cssRule
+     * @param cssSelector
      *         used to locate the element
      * @since 5.3
+     * @deprecated Deprecated in 5.4 with no replacement
      */
-    protected void waitForCSSSelectedElementToAppear(String cssRule)
+    protected void waitForCSSSelectedElementToAppear(String cssSelector)
     {
-        String condition = String.format("window.$$ && window.$$(\"%s\").size() > 0", cssRule);
+        String condition = String.format("window.testSupport.findCSSMatchCount(\"%s\") > 0", cssSelector);
 
         waitForCondition(condition, PAGE_LOAD_TIMEOUT);
     }
@@ -1481,7 +1486,7 @@ public abstract class SeleniumTestCase extends Assert implements Selenium
     protected final void waitForElementToAppear(String elementId)
     {
 
-        String condition = String.format("window.$(\"%s\")", elementId);
+        String condition = String.format("window.getElementById(\"%s\")", elementId);
 
         waitForCondition(condition, PAGE_LOAD_TIMEOUT);
     }
@@ -1489,13 +1494,17 @@ public abstract class SeleniumTestCase extends Assert implements Selenium
     /**
      * Waits for the element to be removed from the DOM.
      *
+     * <p/>
+     * This implementation depends on window being extended with testSupport.isNotVisible().
+     *
      * @param elementId
      *         client-side id of element
      * @since 5.3
+     * @deprecated Deprecated in 5.4 with no replacement
      */
     protected final void waitForElementToDisappear(String elementId)
     {
-        String condition = String.format("window.$(\"%s\").hide()", elementId);
+        String condition = String.format("window.testSupport.doesNotExist(\"%s\")", elementId);
 
         waitForCondition(condition, PAGE_LOAD_TIMEOUT);
     }