aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2014-11-17 08:14:10 +0200
committerVaadin Code Review <review@vaadin.com>2015-01-13 20:30:45 +0000
commit5102cc98c295a49487fcf90cc6ac7980d166eb40 (patch)
tree59b27fb5a7b41053c7239603052e17793f1aaa3a /uitest/src/com/vaadin
parent30f0e91195447140190f4c4feb232e9c13d02453 (diff)
downloadvaadin-framework-5102cc98c295a49487fcf90cc6ac7980d166eb40.tar.gz
vaadin-framework-5102cc98c295a49487fcf90cc6ac7980d166eb40.zip
Implement JavaScript renderer support (#15485)
Change-Id: Ifeac12d4124a4a7e5d0c143ff5c0590a2c98509d
Diffstat (limited to 'uitest/src/com/vaadin')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java75
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java46
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/MyBeanJSRenderer.java34
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/myBeanJsRenderer.js16
4 files changed, 171 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java
new file mode 100644
index 0000000000..4bfa244c22
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderers.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+
+public class JavaScriptRenderers extends AbstractTestUI {
+
+ public static class MyBean {
+ private int integer;
+ private String string;
+
+ public MyBean(int integer, String string) {
+ super();
+ this.integer = integer;
+ this.string = string;
+ }
+
+ public int getInteger() {
+ return integer;
+ }
+
+ public void setInteger(int integer) {
+ this.integer = integer;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public void setString(String string) {
+ this.string = string;
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ IndexedContainer container = new IndexedContainer();
+ container.addContainerProperty("id", Integer.class, Integer.valueOf(0));
+ container.addContainerProperty("bean", MyBean.class, null);
+
+ for (int i = 0; i < 1000; i++) {
+ Integer itemId = Integer.valueOf(i);
+ Item item = container.addItem(itemId);
+ item.getItemProperty("id").setValue(itemId);
+ item.getItemProperty("bean").setValue(
+ new MyBean(i + 1, Integer.toString(i - 1)));
+ }
+
+ Grid grid = new Grid(container);
+
+ grid.getColumn("bean").setRenderer(new MyBeanJSRenderer());
+ grid.getColumn("bean").setWidth(250);
+
+ addComponent(grid);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java
new file mode 100644
index 0000000000..a3bb736086
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class JavaScriptRenderersTest extends MultiBrowserTest {
+
+ @Test
+ public void testJavaScriptRenderer() {
+ setDebug(true);
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+ GridCellElement cell_1_2 = grid.getCell(1, 2);
+
+ // Verify render functionality
+ Assert.assertEquals("Bean(2, 0)", cell_1_2.getText());
+
+ // Verify init functionality
+ Assert.assertEquals("2", cell_1_2.getAttribute("column"));
+
+ // Verify onbrowserevent
+ cell_1_2.click();
+ Assert.assertTrue(cell_1_2.getText().startsWith(
+ "Clicked 1 with key 1 at"));
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/MyBeanJSRenderer.java b/uitest/src/com/vaadin/tests/components/grid/MyBeanJSRenderer.java
new file mode 100644
index 0000000000..ccb94f5d2d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/MyBeanJSRenderer.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.annotations.JavaScript;
+import com.vaadin.tests.components.grid.JavaScriptRenderers.MyBean;
+import com.vaadin.ui.renderer.AbstractJavaScriptRenderer;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+@JavaScript("myBeanJsRenderer.js")
+public class MyBeanJSRenderer extends AbstractJavaScriptRenderer<MyBean> {
+
+ public MyBeanJSRenderer() {
+ super(MyBean.class);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/myBeanJsRenderer.js b/uitest/src/com/vaadin/tests/components/grid/myBeanJsRenderer.js
new file mode 100644
index 0000000000..5e7bde5ec7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/myBeanJsRenderer.js
@@ -0,0 +1,16 @@
+window.com_vaadin_tests_components_grid_MyBeanJSRenderer = function() {
+ this.init = function(cell) {
+ cell.element.setAttribute("column", cell.columnIndex);
+ }
+
+ this.render = function(cell, data) {
+ cell.element.innerHTML = 'Bean(' + data.integer + ', ' + data.string + ')'
+ }
+
+ this.getConsumedEvents = function() { return ["click"] };
+
+ this.onBrowserEvent = function(cell, event) {
+ cell.element.innerHTML = "Clicked " + cell.rowIndex + " with key " + this.getRowKey(cell.rowIndex) +" at " + event.clientX;
+ return true;
+ }
+} \ No newline at end of file