aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components
diff options
context:
space:
mode:
authorPatrik Lindström <patrik@vaadin.com>2015-03-24 12:58:25 +0200
committerAnna Koskinen <anna@vaadin.com>2015-03-26 15:27:36 +0000
commitaaae44fe637a5416a25655510379bb215c9de7b5 (patch)
tree8e3c6f1b797c28af07fef0013e88317169e854c3 /uitest/src/com/vaadin/tests/components
parentb96861c1809d12f2d1339fd64f825a3c513977d2 (diff)
downloadvaadin-framework-aaae44fe637a5416a25655510379bb215c9de7b5.tar.gz
vaadin-framework-aaae44fe637a5416a25655510379bb215c9de7b5.zip
Make Grid update column renderers (#16552)
Change-Id: I3adf9d0cc32f800a535a82ffe5d6ba503a36e746
Diffstat (limited to 'uitest/src/com/vaadin/tests/components')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderers.java103
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java84
2 files changed, 187 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderers.java b/uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderers.java
new file mode 100644
index 0000000000..e233edc5d0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderers.java
@@ -0,0 +1,103 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.List;
+import java.util.Random;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.data.Item;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.Grid.SelectionMode;
+import com.vaadin.ui.renderers.HtmlRenderer;
+import com.vaadin.ui.renderers.TextRenderer;
+
+@SuppressWarnings("serial")
+@Theme("valo")
+public class GridSwitchRenderers extends AbstractTestUIWithLog {
+ private static final int MANUALLY_FORMATTED_COLUMNS = 1;
+ private static final int COLUMNS = 3;
+ private static final int ROWS = 1000;
+ private static final String EXPANSION_COLUMN_ID = "Column 0";
+
+ private IndexedContainer ds;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ ds = new IndexedContainer() {
+ @Override
+ public List<Object> getItemIds(int startIndex, int numberOfIds) {
+ log("Requested items " + startIndex + " - "
+ + (startIndex + numberOfIds));
+ return super.getItemIds(startIndex, numberOfIds);
+ }
+ };
+
+ {
+ ds.addContainerProperty(EXPANSION_COLUMN_ID, String.class, "");
+
+ int col = MANUALLY_FORMATTED_COLUMNS;
+ for (; col < COLUMNS; col++) {
+ ds.addContainerProperty(getColumnProperty(col), String.class,
+ "");
+ }
+ }
+
+ Random rand = new Random();
+ rand.setSeed(13334);
+ for (int row = 0; row < ROWS; row++) {
+ Item item = ds.addItem(Integer.valueOf(row));
+ fillRow("" + row, item);
+ item.getItemProperty(getColumnProperty(1)).setReadOnly(true);
+ }
+
+ final Grid grid = new Grid(ds);
+ grid.setWidth("100%");
+
+ grid.getColumn(EXPANSION_COLUMN_ID).setWidth(50);
+ for (int col = MANUALLY_FORMATTED_COLUMNS; col < COLUMNS; col++) {
+ grid.getColumn(getColumnProperty(col)).setWidth(300);
+ grid.getColumn(getColumnProperty(col)).setRenderer(
+ new TextRenderer());
+ }
+
+ grid.setSelectionMode(SelectionMode.NONE);
+ addComponent(grid);
+
+ final CheckBox changeRenderer = new CheckBox(
+ "SetHtmlRenderer for Column 2", false);
+ changeRenderer.addValueChangeListener(new ValueChangeListener() {
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ Column column = grid.getColumn(getColumnProperty(1));
+ if (changeRenderer.getValue()) {
+ column.setRenderer(new HtmlRenderer());
+ } else {
+ column.setRenderer(new TextRenderer());
+ }
+ grid.markAsDirty();
+ }
+ });
+ addComponent(changeRenderer);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void fillRow(String content, Item item) {
+ int col = MANUALLY_FORMATTED_COLUMNS;
+
+ for (; col < COLUMNS; col++) {
+ item.getItemProperty(getColumnProperty(col)).setValue(
+ "<b>(" + content + ", " + col + ")</b>");
+ }
+ }
+
+ private static String getColumnProperty(int c) {
+ return "Column " + c;
+ }
+
+} \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java b/uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java
new file mode 100644
index 0000000000..e3bab865c0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.CheckBoxElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridSwitchRenderersTest extends MultiBrowserTest {
+
+ @Test
+ public void testRendererSwitch() {
+
+ // The UI should start with TEXT rendering in the second column
+ // Clicking the checkbox will toggle rendering to HTML mode
+ // Clicking it again should return TEXT rendering mode.
+
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+
+ Assert.assertTrue(
+ "Initial rendering of column 1 is not unformatted text",
+ cellTextIsUnformatted(grid.getCell(0, 1).getText()));
+
+ // NOTE: must click at 5,5 because of Valo and rendering in Chrome
+ // This is a TestBench bug that may be fixed sometime in the future
+ CheckBoxElement cb = $(CheckBoxElement.class).first();
+ cb.click(5, 5);
+
+ Assert.assertTrue(
+ "Column 1 data has not been rendered with HTMLRenderer after renderer swap",
+ cellTextIsHTMLFormatted(grid.getCell(0, 1).getText()));
+ cb.click(5, 5);
+
+ Assert.assertTrue(
+ "Column 1 data has not been re-rendered as text after renderer swap",
+ cellTextIsUnformatted(grid.getCell(0, 1).getText()));
+ }
+
+ /**
+ * Attempts to match a string to a string like {@code <b>(4, 1)</b>}.
+ *
+ * @param cellText
+ * input string
+ * @return true if input string is formatted like a raw HTML string
+ */
+ private boolean cellTextIsUnformatted(String cellText) {
+ String regex = "<b>\\(\\d+, \\d+\\)</b>";
+ return cellText.matches(regex);
+ }
+
+ /**
+ * Attempts to match a string to a string like {@code (4, 1)}, i.e. the HTML
+ * formatted version of the above (the bold tags should be consumed by the
+ * renderer).
+ *
+ * @param cellText
+ * input string
+ * @return true if input string is formatted like plain text (i.e. HTML bits
+ * have been consumed by renderer)
+ */
+ private boolean cellTextIsHTMLFormatted(String cellText) {
+ String regex = "\\(\\d+, \\d+\\)";
+ return cellText.matches(regex);
+ }
+
+}