summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-07-05 15:10:02 +0300
committerLeif Åstrand <leif@vaadin.com>2012-07-05 15:10:02 +0300
commitb48d4648ee228802cf32de0101d6b815e191d4b2 (patch)
treeccb3cef718319f39d04258e98abe4fbe7e8e7ba7 /tests
parent04d043f95fbdeb698a3c0c39334e76b367afa749 (diff)
downloadvaadin-framework-b48d4648ee228802cf32de0101d6b815e191d4b2.tar.gz
vaadin-framework-b48d4648ee228802cf32de0101d6b815e191d4b2.zip
Add test for JavaScript component fundamentals (#8888)
Diffstat (limited to 'tests')
-rw-r--r--tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java83
-rw-r--r--tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js37
2 files changed, 94 insertions, 26 deletions
diff --git a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java
index 15c5f6b642..a7430705f5 100644
--- a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java
+++ b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java
@@ -3,6 +3,7 @@
*/
package com.vaadin.tests.components.javascriptcomponent;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -10,72 +11,102 @@ import com.vaadin.annotations.JavaScript;
import com.vaadin.external.json.JSONArray;
import com.vaadin.external.json.JSONException;
import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.gwt.client.communication.ClientRpc;
import com.vaadin.terminal.gwt.client.communication.ServerRpc;
import com.vaadin.terminal.gwt.client.ui.JavaScriptComponentState;
import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.tests.util.Log;
import com.vaadin.ui.AbstractJavaScriptComponent;
+import com.vaadin.ui.HasComponents;
import com.vaadin.ui.JavaScriptCallback;
-import com.vaadin.ui.Notification;
public class BasicJavaScriptComponent extends AbstractTestRoot {
- public interface ExampleClickRpc extends ServerRpc {
- public void onClick(String message);
+ public interface TestRpc extends ServerRpc, ClientRpc {
+ public void sendRpc(String message);
}
- public static class SpecialState extends JavaScriptComponentState {
- private List<String> data;
+ public static class TestState extends JavaScriptComponentState {
+ private List<String> messages = new ArrayList<String>();
- public List<String> getData() {
- return data;
+ public List<String> getMessages() {
+ return messages;
}
- public void setData(List<String> data) {
- this.data = data;
+ public void setMessages(List<String> messages) {
+ this.messages = messages;
}
}
- @JavaScript("/statictestfiles/jsconnector.js")
- public static class ExampleWidget extends AbstractJavaScriptComponent {
+ @JavaScript("BasicJavaScriptComponentConnector.js")
+ public class ExampleWidget extends AbstractJavaScriptComponent {
public ExampleWidget() {
- registerRpc(new ExampleClickRpc() {
- public void onClick(String message) {
- Notification.show("Got a click: " + message);
+ registerRpc(new TestRpc() {
+ public void sendRpc(String message) {
+ log.log("Got RPC message: " + message);
}
});
- registerCallback("onclick", new JavaScriptCallback() {
+ registerCallback("messageToServer", new JavaScriptCallback() {
public void call(JSONArray arguments) throws JSONException {
- Notification.show("Got a callback: "
- + arguments.getString(0));
+ log.log("Got callback message: " + arguments.getString(0));
}
});
- getState().setData(Arrays.asList("a", "b", "c"));
+
+ registerCallback("reportParentIds", new JavaScriptCallback() {
+ public void call(JSONArray arguments) throws JSONException {
+ JSONArray parentIds = arguments.getJSONArray(0);
+ if (!parentIds.getString(0).equals(getConnectorId())) {
+ log.log("Connector ids doesn't match");
+ }
+
+ HasComponents parent = getParent();
+ int i = 1;
+ while (parent != null) {
+ if (!parentIds.getString(i).equals(
+ parent.getConnectorId())) {
+ log.log("parentIds[" + i + "] doesn't match");
+ }
+ i++;
+ parent = parent.getParent();
+ }
+ log.log("Parent ids checked");
+ }
+ });
+
+ getRpcProxy(TestRpc.class).sendRpc("RPC message");
+ invokeCallback("messageToClient", "Callback message");
+
+ getState()
+ .setMessages(
+ Arrays.asList("First state message",
+ "Second state message"));
}
@Override
- public SpecialState getState() {
- return (SpecialState) super.getState();
+ public TestState getState() {
+ return (TestState) super.getState();
}
}
+ private final Log log = new Log(5);
+
@Override
protected void setup(WrappedRequest request) {
+ addComponent(log);
+
ExampleWidget c = new ExampleWidget();
- c.setCaption("test caption");
- c.setDescription("Some description");
+ c.setCaption("Component caption");
addComponent(c);
}
@Override
protected String getTestDescription() {
- // TODO Auto-generated method stub
- return null;
+ return "Test for basic JavaScript component functionality.";
}
@Override
protected Integer getTicketNumber() {
- // TODO Auto-generated method stub
- return null;
+ return Integer.valueOf(8888);
}
}
diff --git a/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js
new file mode 100644
index 0000000000..4e9c5280b3
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js
@@ -0,0 +1,37 @@
+window.com_vaadin_tests_components_javascriptcomponent_BasicJavaScriptComponent_ExampleWidget = function() {
+ var parentIds = [];
+ var connectorId = this.getConnectorId();
+ while(connectorId) {
+ parentIds.push(connectorId);
+ connectorId = this.getParentId(connectorId);
+ }
+ this.reportParentIds(parentIds);
+
+ this.onStateChange = function() {
+ var e = this.getElement();
+
+ e.innerHTML = '';
+
+ var row = 1;
+ var log = function(text) {
+ e.innerHTML = "<div>" + row++ + ". " + text + "</div>" + e.innerHTML;
+ }
+
+ log("Parent element className: " + this.getElement(this.getParentId()).className);
+
+ var messages = this.getState().messages;
+ for(var i = 0; i < messages.length; i++) {
+ log("State message: " + messages[i]);
+ }
+ }
+
+ this.registerRpc({
+ sendRpc: function(message) {
+ this.getRpcProxy().sendRpc(message + " processed");
+ }
+ });
+
+ this.messageToClient = function(message) {
+ this.messageToServer(message + " processed");
+ }
+} \ No newline at end of file