From 31fb84fc6f23ac2bd47bb2e9dfe95399bbee5ec4 Mon Sep 17 00:00:00 2001 From: Adam Wagner Date: Tue, 19 Dec 2017 11:08:18 +0200 Subject: [PATCH] Fix column width resize event firing when mode is SIMPLE (#10452) --- .../java/com/vaadin/client/widgets/Grid.java | 12 ++++++-- .../GridColumnResizeModeTest.java | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 857f95002f..be4d3da587 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -5888,9 +5888,17 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, @Override public void onComplete() { dragEnded(); - col.setWidth(width); - fireEvent(new ColumnResizeEvent(col)); + + // Need to wait for column width recalculation + // scheduled by setWidth() before firing the event + Scheduler.get().scheduleDeferred( + new ScheduledCommand() { + @Override + public void execute() { + fireEvent(new ColumnResizeEvent(col)); + } + }); } }; diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java index d24fe19639..ac9a505f07 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnResizeModeTest.java @@ -23,6 +23,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.parallel.TestCategory; import com.vaadin.tests.components.grid.basicfeatures.element.CustomGridElement; @@ -74,4 +75,33 @@ public class GridColumnResizeModeTest extends GridBasicFeaturesTest { } + + @Test + public void testSimpleResizeModeMultipleDrag() throws Exception { + CustomGridElement grid = getGridElement(); + + List handles = grid + .findElements(By.className("v-grid-column-resize-handle")); + WebElement handle = handles.get(1); + + GridCellElement cell = grid.getHeaderCell(0, 1); + + int initialWidth = cell.getSize().getWidth(); + + selectMenuPath("Component", "Columns", "Simple resize mode"); + sleep(250); + + drag(handle, 100); + sleep(500); + Assert.assertEquals(initialWidth + 100, cell.getSize().getWidth()); + + drag(handle, -100); + sleep(500); + Assert.assertEquals(initialWidth, cell.getSize().getWidth()); + } + + private void drag(WebElement handle, int xOffset) { + new Actions(getDriver()).moveToElement(handle).clickAndHold() + .moveByOffset(xOffset, 0).release().perform(); + } } -- 2.39.5