]> source.dussan.org Git - vaadin-framework.git/commitdiff
Open details rows shouldn't get removed when a new row is added to Grid (#12109) 7.7.22
authorAnna Koskinen <Ansku@users.noreply.github.com>
Tue, 6 Oct 2020 08:43:33 +0000 (11:43 +0300)
committerGitHub <noreply@github.com>
Tue, 6 Oct 2020 08:43:33 +0000 (11:43 +0300)
Fixes: #12106
client/src/main/java/com/vaadin/client/widgets/Grid.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsAddRow.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsAddRowTest.java [new file with mode: 0644]

index 6ed2e78b272c4c358bfe9adf95b838f89b5ba265..ebf5c8ca960918664d916793385394fc1583569a 100755 (executable)
@@ -7311,12 +7311,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
                         RowContainer body = escalator.getBody();
                         int oldSize = body.getRowCount();
 
-                        // Hide all details.
-                        Set<Integer> oldDetails = new HashSet<>(visibleDetails);
-                        for (int i : oldDetails) {
-                            setDetailsVisible(i, false);
-                        }
-
                         if (newSize > oldSize) {
                             if (oldSize == 0 && !isHeaderVisible()) {
                                 // Fixes framework/issues/11607
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsAddRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsAddRow.java
new file mode 100644 (file)
index 0000000..b2dd451
--- /dev/null
@@ -0,0 +1,53 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.data.provider.ListDataProvider;
+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 GridOpenDetailsAddRow extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        Grid<String> testGrid = new Grid<>();
+
+        testGrid.addColumn(item -> item).setCaption("column").setId("column");
+
+        List<String> list = new ArrayList<>();
+        list.add("row1");
+        list.add("row2");
+        list.add("row3");
+        ListDataProvider<String> dataProvider = new ListDataProvider<>(list);
+
+        testGrid.setDataProvider(dataProvider);
+        testGrid.setDetailsGenerator(item -> new Label("details - " + item));
+        list.forEach(item -> testGrid.setDetailsVisible(item, true));
+
+        Button addButton = new Button("add");
+        addButton.addClickListener(event -> {
+            String newItem = "row" + (list.size() + 1);
+            list.add(newItem);
+            testGrid.setDetailsVisible(newItem, true);
+            dataProvider.refreshAll();
+        });
+
+        VerticalLayout testLayout = new VerticalLayout(addButton, testGrid);
+        addComponent(testLayout);
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 12106;
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Already open details rows shouldn't disappear when a new row is added";
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsAddRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsAddRowTest.java
new file mode 100644 (file)
index 0000000..939815b
--- /dev/null
@@ -0,0 +1,40 @@
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridOpenDetailsAddRowTest extends MultiBrowserTest {
+
+    @Test
+    public void addRow() {
+        openTestURL();
+        waitUntilLoadingIndicatorNotVisible();
+
+        // confirm initial state
+        List<WebElement> spacers = findElements(By.className("v-grid-spacer"));
+        assertEquals("Unexpected initial amount of spacers", 3, spacers.size());
+
+        // add a row
+        $(ButtonElement.class).first().click();
+        waitUntilLoadingIndicatorNotVisible();
+
+        // ensure all existing spacers are still visible, as well as the new one
+        spacers = findElements(By.className("v-grid-spacer"));
+        assertEquals("Unexpected amount of spacers after adding a row", 4,
+                spacers.size());
+
+        assertEquals("Unexpected spacer contents for new row", "details - row4",
+                spacers.get(3).getText());
+
+        assertEquals("Unexpected spacer contents for first row",
+                "details - row1", spacers.get(0).getText());
+    }
+}