From 724a1564de9a02ebc6e2a59e5faf04084d493a41 Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Fri, 6 Aug 2021 14:56:49 +0300 Subject: [PATCH] Ensure Grid details rows get a full refresh when a column is sorted. (#12342) (#12361) Fixes #12341 --- .../grid/DetailsManagerConnector.java | 3 +- .../components/grid/GridOpenDetailsSort.java | 42 ++++++++++++++++++ .../grid/GridOpenDetailsSortTest.java | 44 +++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsSort.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsSortTest.java diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java index b419aef724..40a9183f27 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java @@ -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 index 0000000000..63da6b8956 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridOpenDetailsSort.java @@ -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 testGrid = new Grid<>(); + + testGrid.addColumn(item -> item).setCaption("column").setId("column"); + + List list = new ArrayList<>(); + list.add("row3"); + list.add("row2"); + list.add("row1"); + ListDataProvider 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 index 0000000000..3a2e76eb51 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridOpenDetailsSortTest.java @@ -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 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()); + } + } +} -- 2.39.5