From 9ffdbc8c29ae2a4fb01a1996d506e3b6042ebb7f Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Thu, 20 May 2021 12:25:09 +0300 Subject: [PATCH] Trigger repositioning after full refresh of current details. (#12312) (#12313) Fixes #12310 --- .../grid/DetailsManagerConnector.java | 6 +++++ .../grid/GridDetailsUpdateItems.java | 10 +++++-- .../grid/GridDetailsUpdateItemsTest.java | 27 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) 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 7e7389e65d..5290effdfa 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 @@ -634,6 +634,12 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { boolean newOrUpdatedDetails = refreshRange(availableAndVisible); + // the update may have affected details row contents and size, + // recalculation and triggering of any pending navigation + // confirmations etc. is needed + triggerDelayedRepositioning(availableAndVisible.getStart(), + availableAndVisible.length()); + markDetailsAddedOrUpdatedForDelayedAlertToGrid(newOrUpdatedDetails); } 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 index d84e0466a9..4bdaf2553a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsUpdateItems.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsUpdateItems.java @@ -48,7 +48,7 @@ public class GridDetailsUpdateItems extends AbstractTestUI { } mainLayout.addComponent(grid); - Button clickButton = new Button("Change items", event -> { + Button changeButton1 = new Button("Change with details", event -> { List> itemsOverwrite = Arrays .asList(secondCollection, fourthCollection); grid.setItems(itemsOverwrite); @@ -56,7 +56,13 @@ public class GridDetailsUpdateItems extends AbstractTestUI { grid.setDetailsVisible(tmp, true); } }); - mainLayout.addComponent(clickButton); + mainLayout.addComponent(changeButton1); + Button changeButton2 = new Button("Change without details", event -> { + List> itemsOverwrite = Arrays + .asList(secondCollection, fourthCollection); + grid.setItems(itemsOverwrite); + }); + mainLayout.addComponent(changeButton2); return mainLayout; } 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 index 22c7da0c02..47cdc7ffff 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsUpdateItemsTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsUpdateItemsTest.java @@ -2,9 +2,11 @@ package com.vaadin.tests.components.grid; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import org.junit.Test; +import org.openqa.selenium.By; import com.vaadin.testbench.TestBenchElement; import com.vaadin.testbench.elements.ButtonElement; @@ -18,7 +20,8 @@ public class GridDetailsUpdateItemsTest extends MultiBrowserTest { public void testDetailsUpdateWithItems() { openTestURL(); GridElement grid = $(GridElement.class).first(); - ButtonElement button = $(ButtonElement.class).first(); + ButtonElement button = $(ButtonElement.class) + .caption("Change with details").first(); String details0 = grid.getDetails(0).getText(); @@ -41,6 +44,28 @@ public class GridDetailsUpdateItemsTest extends MultiBrowserTest { assertDirectlyAbove(cell1_0, detailCell1); } + @Test + public void testRemovingDetailsWithItemUpdateRepositionsRowsCorrectly() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + ButtonElement button = $(ButtonElement.class) + .caption("Change without details").first(); + + assertFalse("Details not found when there should be some.", + grid.findElements(By.className("v-grid-spacer")).isEmpty()); + + // change the contents + button.click(); + + waitForElementNotPresent(By.className("v-grid-spacer")); + + GridCellElement cell0_0 = grid.getCell(0, 0); + GridCellElement cell1_0 = grid.getCell(1, 0); + + // ensure positioning is correct + assertDirectlyAbove(cell0_0, cell1_0); + } + private void assertDirectlyAbove(TestBenchElement above, TestBenchElement below) { int aboveBottom = above.getLocation().getY() -- 2.39.5