diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-03-15 14:00:50 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-03-15 14:00:50 +0200 |
commit | c766694bec0ec16d7dc7b52f8e48f3c4056e6d1f (patch) | |
tree | 9adcbf965914c9ad9c5d84a79cecdbc6117a1234 /uitest/src | |
parent | 0fe0e727784b311e2b76f3b5a06d3a823d2006f4 (diff) | |
download | vaadin-framework-c766694bec0ec16d7dc7b52f8e48f3c4056e6d1f.tar.gz vaadin-framework-c766694bec0ec16d7dc7b52f8e48f3c4056e6d1f.zip |
Allow changing renderers after column creation (#8841)
Closes #8250
Diffstat (limited to 'uitest/src')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererSwitch.java | 53 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererSwitchTest.java | 100 |
2 files changed, 153 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererSwitch.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererSwitch.java new file mode 100644 index 0000000000..b73383d22b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererSwitch.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.grid; + +import java.util.stream.IntStream; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Notification; +import com.vaadin.ui.renderers.ButtonRenderer; +import com.vaadin.ui.renderers.TextRenderer; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridRendererSwitch extends AbstractTestUI { + + private boolean textRenderer = true; + private boolean reverse = false; + + @Override + protected void setup(VaadinRequest request) { + Grid<Integer> grid = new Grid<>(); + Column<Integer, String> column = grid.addColumn(i -> "Foo " + i) + .setCaption("Foo"); + Column<Integer, String> secondColumn = grid.addColumn(i -> "Bar " + i) + .setCaption("Bar"); + + addComponent(grid); + addComponent(new Button("Switch", e -> { + if (textRenderer) { + ButtonRenderer<Integer> renderer = new ButtonRenderer<>(); + renderer.addClickListener(event -> Notification + .show("Click on row: " + event.getItem())); + column.setRenderer(renderer); + } else { + column.setRenderer(new TextRenderer()); + } + textRenderer = !textRenderer; + })); + addComponent(new Button("Reverse", e -> { + if (reverse) { + grid.setColumnOrder(column, secondColumn); + } else { + grid.setColumnOrder(secondColumn, column); + } + reverse = !reverse; + })); + + grid.setItems(IntStream.range(0, 10).boxed()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererSwitchTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererSwitchTest.java new file mode 100644 index 0000000000..1fd775b58a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererSwitchTest.java @@ -0,0 +1,100 @@ +package com.vaadin.tests.components.grid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridRendererSwitchTest extends SingleBrowserTest { + + @Test + public void testSwitchRenderer() { + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Unexpected content in first grid cell", "Foo 0", + grid.getCell(0, 0).getAttribute("innerHTML")); + ButtonElement button = $(ButtonElement.class).first(); + button.click(); + Assert.assertFalse("No button in cell", grid.getCell(0, 0) + .findElements(By.tagName("button")).isEmpty()); + grid.getCell(0, 0).findElement(By.tagName("button")).click(); + Assert.assertTrue("Notification not shown", + isElementPresent(NotificationElement.class)); + button.click(); + Assert.assertEquals("Cell should be back to text content.", "Foo 0", + grid.getCell(0, 0).getAttribute("innerHTML")); + + assertNoErrorNotifications(); + } + + @Test + public void testSwitchRendererReorderColumns() { + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Unexpected content in first grid cell", "Foo 0", + grid.getCell(0, 0).getAttribute("innerHTML")); + ButtonElement button = $(ButtonElement.class).caption("Switch").first(); + button.click(); + ButtonElement reverse = $(ButtonElement.class).caption("Reverse") + .first(); + reverse.click(); + Assert.assertEquals( + "Unexpected content in first grid cell after reorder", "Bar 0", + grid.getCell(0, 0).getAttribute("innerHTML")); + + Assert.assertFalse("No button in cell after reversing order", grid + .getCell(0, 1).findElements(By.tagName("button")).isEmpty()); + grid.getCell(0, 1).findElement(By.tagName("button")).click(); + Assert.assertTrue("Notification not shown", + isElementPresent(NotificationElement.class)); + reverse.click(); + Assert.assertFalse("No button in cell after restoring original order", + grid.getCell(0, 0).findElements(By.tagName("button")) + .isEmpty()); + + assertNoErrorNotifications(); + } + + @Test + public void testReorderColumnsSwitchRenderer() { + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Unexpected content in first grid cell", "Foo 0", + grid.getCell(0, 0).getAttribute("innerHTML")); + ButtonElement reverse = $(ButtonElement.class).caption("Reverse") + .first(); + + reverse.click(); + Assert.assertEquals( + "Unexpected content in first grid cell after reorder", "Bar 0", + grid.getCell(0, 0).getAttribute("innerHTML")); + + ButtonElement button = $(ButtonElement.class).caption("Switch").first(); + button.click(); + + Assert.assertFalse( + "No button in cell after reversing order and changing renderer", + grid.getCell(0, 1).findElements(By.tagName("button")) + .isEmpty()); + grid.getCell(0, 1).findElement(By.tagName("button")).click(); + Assert.assertTrue("Notification not shown", + isElementPresent(NotificationElement.class)); + + button.click(); + Assert.assertEquals("Cell should be back to text content.", "Foo 0", + grid.getCell(0, 1).getAttribute("innerHTML")); + + assertNoErrorNotifications(); + } + +} |