diff options
Diffstat (limited to 'uitest/src')
3 files changed, 132 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsUpdateItems.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsUpdateItems.java new file mode 100644 index 0000000000..d84e0466a9 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsUpdateItems.java @@ -0,0 +1,74 @@ +package com.vaadin.tests.components.grid; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import com.vaadin.data.ValueProvider; +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.Label; +import com.vaadin.ui.VerticalLayout; + +public class GridDetailsUpdateItems extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(createExamplleLayout()); + } + + private VerticalLayout createExamplleLayout() { + Collection<String> firstCollection = Arrays.asList("Hello", ",", + "world!"); + Collection<String> secondCollection = Arrays.asList("My", "name", "is", + "Sarah"); + Collection<String> thirdCollection = Arrays.asList("red", "blue"); + Collection<String> fourthCollection = Arrays.asList("spring", "summer", + "autumn", "winter"); + + VerticalLayout mainLayout = new VerticalLayout(); + Grid<Collection<String>> grid = new Grid<>(); + grid.setDetailsGenerator(collection -> { + VerticalLayout detailLayout = new VerticalLayout(); + collection.forEach( + item -> detailLayout.addComponent(new Label(item))); + return detailLayout; + }); + ValueProvider<Collection<String>, String> valueProvider = collection -> String + .join(" ", collection); + grid.addColumn(valueProvider).setCaption("Header"); + + List<Collection<String>> itemsInitial = Arrays.asList(firstCollection, + secondCollection, thirdCollection, fourthCollection); + grid.setItems(itemsInitial); + for (Collection<String> tmp : itemsInitial) { + grid.setDetailsVisible(tmp, true); + } + mainLayout.addComponent(grid); + + Button clickButton = new Button("Change items", event -> { + List<Collection<String>> itemsOverwrite = Arrays + .asList(secondCollection, fourthCollection); + grid.setItems(itemsOverwrite); + for (Collection<String> tmp : itemsOverwrite) { + grid.setDetailsVisible(tmp, true); + } + }); + mainLayout.addComponent(clickButton); + + return mainLayout; + } + + @Override + protected Integer getTicketNumber() { + return 12211; + } + + @Override + protected String getTestDescription() { + return "Details should update and not break the positioning " + + "when the item set is changed."; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java index 65fe75e9fa..404556f2d6 100644 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java @@ -117,6 +117,11 @@ public class EscalatorProxy extends Escalator { } @Override + public void resetSpacer(int rowIndex) { + rowContainer.resetSpacer(rowIndex); + } + + @Override public void setSpacerUpdater(SpacerUpdater spacerUpdater) throws IllegalArgumentException { rowContainer.setSpacerUpdater(spacerUpdater); diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsUpdateItemsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsUpdateItemsTest.java new file mode 100644 index 0000000000..3f690ca7cd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsUpdateItemsTest.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.grid; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.number.IsCloseTo.closeTo; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridDetailsUpdateItemsTest extends MultiBrowserTest { + + @Test + public void testDetailsUpdateWithItems() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + ButtonElement button = $(ButtonElement.class).first(); + + String details0 = grid.getDetails(0).getText(); + System.out.println("details: " + details0); + + // change the contents + button.click(); + sleep(200); + + TestBenchElement detailCell0 = grid.getDetails(0); + // ensure contents have updated + String updatedDetails0 = detailCell0.getText(); + assertNotEquals("Details should not be empty", "", updatedDetails0); + assertNotEquals("Unexpected detail contents for row 0", details0, + updatedDetails0); + + GridCellElement cell1_0 = grid.getCell(1, 0); + TestBenchElement detailCell1 = grid.getDetails(1); + + // ensure positioning is correct + assertDirectlyAbove(detailCell0, cell1_0); + assertDirectlyAbove(cell1_0, detailCell1); + } + + private void assertDirectlyAbove(TestBenchElement above, + TestBenchElement below) { + int aboveBottom = above.getLocation().getY() + + above.getSize().getHeight(); + int belowTop = below.getLocation().getY(); + assertThat("Unexpected positions.", (double) aboveBottom, + closeTo(belowTop, 1d)); + } +} |