diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-03-09 09:29:51 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-03-09 09:29:51 +0200 |
commit | 761c94ab2e1019f7d83d4e8d63254de1ee591d75 (patch) | |
tree | bd167811a86c0c666d321bdbfdb57dea980cb942 /uitest | |
parent | 264ee7696568827815604f1e22ce7e330775b3ce (diff) | |
download | vaadin-framework-761c94ab2e1019f7d83d4e8d63254de1ee591d75.tar.gz vaadin-framework-761c94ab2e1019f7d83d4e8d63254de1ee591d75.zip |
Initial implementation of ComponentRenderer for Grid (#8743)
Fixes #8622
Fixes #8623
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java | 68 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java | 94 |
2 files changed, 162 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java new file mode 100644 index 0000000000..2eb48f7697 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java @@ -0,0 +1,68 @@ +package com.vaadin.tests.components.grid; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.IntStream; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ValueChangeMode; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Notification.Type; +import com.vaadin.ui.TextField; +import com.vaadin.ui.renderers.ComponentRenderer; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridComponents extends AbstractTestUIWithLog { + + private Map<String, TextField> textFields = new HashMap<>(); + private int counter = 0; + + @Override + protected void setup(VaadinRequest request) { + Grid<String> grid = new Grid<String>(); + grid.addColumn(string -> new Label(string), new ComponentRenderer()); + grid.addColumn(string -> { + if (textFields.containsKey(string)) { + log("Reusing old text field for: " + string); + return textFields.get(string); + } + + TextField textField = new TextField(); + textField.setValue(string); + // Make sure all changes are sent immediately + textField.setValueChangeMode(ValueChangeMode.EAGER); + textField.addValueChangeListener(e -> { + // Value of text field edited by user, store + textFields.put(string, textField); + }); + return textField; + }, new ComponentRenderer()); + grid.addColumn(string -> { + Button button = new Button("Click Me!", + e -> Notification.show( + "Clicked button on row for: " + string, + Type.WARNING_MESSAGE)); + button.setId(string.replace(' ', '_').toLowerCase()); + return button; + }, new ComponentRenderer()); + + addComponent(grid); + grid.setSizeFull(); + + Button resetData = new Button("Reset data", e -> { + grid.setItems(IntStream.range(0, 1000).boxed() + .map(i -> "Row " + (i + (counter * 1000)))); + textFields.clear(); + ++counter; + }); + resetData.click(); + addComponent(resetData); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java new file mode 100644 index 0000000000..89226c147e --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java @@ -0,0 +1,94 @@ +package com.vaadin.tests.components.grid; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridComponentsTest extends MultiBrowserTest { + + @Test + public void testReuseTextFieldOnScroll() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + editTextFieldInCell(grid, 0, 1); + // Scroll out of view port + grid.getRow(900); + // Scroll back + grid.getRow(0); + + WebElement textField = grid.getCell(0, 1) + .findElement(By.tagName("input")); + Assert.assertEquals("TextField value was reset", "Foo", + textField.getAttribute("value")); + Assert.assertTrue("No mention in the log", + logContainsText("1. Reusing old text field for: Row 0")); + } + + @Test + public void testReuseTextFieldOnSelect() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + editTextFieldInCell(grid, 1, 1); + // Select row + grid.getCell(1, 1).click(1, 1); + + WebElement textField = grid.getCell(1, 1) + .findElement(By.tagName("input")); + Assert.assertEquals("TextField value was reset", "Foo", + textField.getAttribute("value")); + Assert.assertTrue("No mention in the log", + logContainsText("1. Reusing old text field for: Row 1")); + } + + @Test + public void testReplaceData() { + openTestURL(); + assertRowExists(5, "Row 5"); + $(ButtonElement.class).caption("Reset data").first().click(); + assertRowExists(5, "Row 1005"); + } + + private void editTextFieldInCell(GridElement grid, int row, int col) { + WebElement textField = grid.getCell(row, col) + .findElement(By.tagName("input")); + textField.clear(); + textField.sendKeys("Foo"); + } + + @Test + public void testRow5() { + openTestURL(); + assertRowExists(5, "Row 5"); + } + + @Test + public void testRow0() { + openTestURL(); + assertRowExists(0, "Row 0"); + } + + @Test + public void testRow999() { + openTestURL(); + assertRowExists(999, "Row 999"); + } + + private void assertRowExists(int i, String string) { + GridRowElement row = $(GridElement.class).first().getRow(i); + Assert.assertEquals("Label text did not match", string, + row.getCell(0).getText()); + row.findElement(By.id(string.replace(' ', '_').toLowerCase())).click(); + // IE 11 is slow, need to wait for the notification. + waitUntil(driver -> isElementPresent(NotificationElement.class), 10); + Assert.assertTrue("Notification should contain given text", + $(NotificationElement.class).first().getText() + .contains(string)); + } +} |