diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-11-10 11:51:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 11:51:25 +0200 |
commit | e334a35268c6d0ab855775fad6835ac1620f86a2 (patch) | |
tree | f2ad550178d5d9ea652a66d51b8c771ae2b279af /uitest | |
parent | 6300b4a9a52dd9cde18df077d20c114ddaa2669f (diff) | |
download | vaadin-framework-e334a35268c6d0ab855775fad6835ac1620f86a2.tar.gz vaadin-framework-e334a35268c6d0ab855775fad6835ac1620f86a2.zip |
Tweaks to Grid/Escalator column size handling (#12145)
- ScrollbarBundle: removed delays in scroll handling that were only
needed for IE8, added possibility to update offsetSize and scrollSize at
the same time in order to avoid triggering unnecessary scrollbar
visibility change events during the intermediate state.
- ColumnConfigurator: added new method that allows setting column widths
without triggering element size recalculations.
- EscalatorProxy: added implementation of the new method to
ColumnConfigurationProxy.
- Escalator: switched to use new methods in ScrollbarBundle and
ColumnConfigurator, added a pixel to a scrollbar offsetSize calculation
that was for some reason consistently one pixel too low, removed
duplicate method calls from sectionHeightCalculated handling as those
are already handled by the calling method and can cause incorrect
intermediate state and unnecessary scrollbar visibility change events,
added implementation of the new method to ColumnConfigurationImpl with
the element size recalculations made optional.
- Grid: updated column minimum width calculations to take into account
the potential presence of a resize handle, updated expand ratio handling
to not trigger element size recalculations until the entire handling is
finished.
- Test for column width handling when there are multiple columns with
setMinimumWidthFromContent(false)
Fixes #12139
Diffstat (limited to 'uitest')
3 files changed, 133 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnsNoMinimumWidthFromContent.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnsNoMinimumWidthFromContent.java new file mode 100644 index 0000000000..e5a88f8092 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnsNoMinimumWidthFromContent.java @@ -0,0 +1,66 @@ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.components.grid.FooterRow; + +public class GridColumnsNoMinimumWidthFromContent extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Random random = new Random(); + + List<DummyGridRow> gridRows = new ArrayList<DummyGridRow>(); + gridRows.add(new DummyGridRow(random)); + + Grid<DummyGridRow> grid = new Grid<DummyGridRow>(); + for (int i = 0; i < 20; i++) { + grid.addColumn(DummyGridRow::getValue) + .setCaption("[" + i + "] Quite dummy column") + .setMinimumWidthFromContent(false); + } + + grid.setItems(gridRows); + FooterRow defaultFooter = grid.appendFooterRow(); + grid.getColumns().forEach(column -> defaultFooter.getCell(column) + .setText(grid.getDefaultHeaderRow().getCell(column).getText())); + grid.setFooterVisible(true); + grid.setHeightByRows(gridRows.size()); + grid.setWidthFull(); + + getLayout().addComponent(grid); + } + + class DummyGridRow { + private Random random = null; + + public DummyGridRow(Random random) { + this.random = random; + } + + public int getValue() { + return random.nextInt(1000000000); + } + } + + @Override + protected Integer getTicketNumber() { + return 12139; + } + + @Override + protected String getTestDescription() { + return "Loading the UI should not get stuck in an eternal loop " + + "and the columns should be narrow with ellipsis " + + "until the page is resized small enough that " + + "the resize handles alone force a scrollbar. " + + "No overflowing of header cells should occur " + + "when resized very near to the cutoff point " + + "between no scrollbar and a scrollbar."; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java index 5d5148109b..65fe75e9fa 100644 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java @@ -86,6 +86,14 @@ public class EscalatorProxy extends Escalator { throws IllegalArgumentException { columnConfiguration.setColumnWidths(indexWidthMap); } + + @Override + public void setColumnWidths(Map<Integer, Double> indexWidthMap, + boolean recalculateElementSizes) + throws IllegalArgumentException { + columnConfiguration.setColumnWidths(indexWidthMap, + recalculateElementSizes); + } } private class BodyRowContainerProxy extends RowContainerProxy diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnsNoMinimumWidthFromContentTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnsNoMinimumWidthFromContentTest.java new file mode 100644 index 0000000000..6ae15fdb13 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnsNoMinimumWidthFromContentTest.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.grid; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.number.IsCloseTo.closeTo; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridColumnsNoMinimumWidthFromContentTest extends MultiBrowserTest { + + @Test + public void testResizing() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + WebElement hScrollbar = grid + .findElement(By.className("v-grid-scroller-horizontal")); + + // initial state, should have no scrollbar + GridCellElement lastColumn = grid.getHeaderCell(0, 19); + ensureScrollbarVisibility(hScrollbar, false); + ensureNoGap(grid, lastColumn); + + // resize small enough to get a scrollbar + getDriver().manage().window().setSize(new Dimension(810, 800)); + ensureScrollbarVisibility(hScrollbar, true); + + // resize just enough to lose the scrollbar + getDriver().manage().window().setSize(new Dimension(840, 800)); + ensureScrollbarVisibility(hScrollbar, false); + ensureNoGap(grid, lastColumn); + + int lastColumnWidth = lastColumn.getSize().getWidth(); + assertGreater("Unexpected last column width: " + lastColumnWidth + + " (should be over 30)", lastColumnWidth, 30); + } + + private void ensureNoGap(GridElement grid, GridCellElement lastColumn) { + int gridRightEdge = grid.getLocation().getX() + + grid.getSize().getWidth(); + int lastColumnRightEdge = lastColumn.getLocation().getX() + + lastColumn.getSize().getWidth(); + assertThat("Unexpected positioning.", (double) gridRightEdge, + closeTo(lastColumnRightEdge, 1d)); + } + + private void ensureScrollbarVisibility(WebElement scrollbar, + boolean displayed) { + assertEquals(displayed ? "block" : "none", + scrollbar.getCssValue("display")); + } +} |