]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensure Grid details rows get a full refresh when a column is sorted. (#12342) (#12361)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Fri, 6 Aug 2021 11:56:49 +0000 (14:56 +0300)
committerGitHub <noreply@github.com>
Fri, 6 Aug 2021 11:56:49 +0000 (14:56 +0300)
Fixes #12341

client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsSort.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsSortTest.java [new file with mode: 0644]

index b419aef724301ff8807ed89ed308ef87480c7e8f..40a9183f27141f38be735163015d3e791b2c7c55 100644 (file)
@@ -142,7 +142,8 @@ public class DetailsManagerConnector extends AbstractExtensionConnector {
             boolean scrollToFirst = numberOfRows == 1
                     && latestVisibleRowRange.contains(firstRowIndex);
 
-            if (!newVisibleRowRange.equals(latestVisibleRowRange)) {
+            if (!newVisibleRowRange.equals(latestVisibleRowRange)
+                    || updatedRange.equals(newVisibleRowRange)) {
                 // update visible range
                 latestVisibleRowRange = newVisibleRowRange;
 
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsSort.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsSort.java
new file mode 100644 (file)
index 0000000..63da6b8
--- /dev/null
@@ -0,0 +1,42 @@
+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.Grid;
+import com.vaadin.ui.Label;
+
+public class GridOpenDetailsSort 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("row3");
+        list.add("row2");
+        list.add("row1");
+        ListDataProvider<String> dataProvider = new ListDataProvider<>(list);
+
+        testGrid.setDataProvider(dataProvider);
+        testGrid.setDetailsGenerator(item -> new Label("details - " + item));
+        list.forEach(item -> testGrid.setDetailsVisible(item, true));
+
+        addComponent(testGrid);
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 12341;
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Already open details rows shouldn't break when the Grid is sorted.";
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsSortTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsSortTest.java
new file mode 100644 (file)
index 0000000..3a2e76e
--- /dev/null
@@ -0,0 +1,44 @@
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridOpenDetailsSortTest extends MultiBrowserTest {
+
+    @Test
+    public void sort() {
+        openTestURL();
+        GridElement grid = $(GridElement.class).first();
+        assertRow(grid, 0, "row3");
+        assertDetails();
+
+        grid.getHeaderCell(0, 0).click();
+        assertTrue("First column should be sorted ascending",
+                grid.getHeaderCell(0, 0).getAttribute("class")
+                        .contains("sort-asc"));
+        assertRow(grid, 0, "row1");
+        assertDetails();
+    }
+
+    private void assertRow(GridElement grid, int row, String value) {
+        assertEquals(String.valueOf(value), grid.getCell(row, 0).getText());
+    }
+
+    private void assertDetails() {
+        List<WebElement> details = findElements(By.className("v-grid-spacer"));
+        assertEquals("Unexpected amount of details,", 3, details.size());
+        for (WebElement detail : details) {
+            assertEquals("Unexpected detail contents,", 1,
+                    detail.findElements(By.className("v-label")).size());
+        }
+    }
+}