diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-07-08 12:42:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-08 12:42:25 +0300 |
commit | d1e6c704fd25a426d5956e521b0903910d7cb4cb (patch) | |
tree | 59f16b53e5d1995f4f255381668e497afda00fe1 /uitest | |
parent | 3640be47c3b21229c55a91b421aec3bbebd425fd (diff) | |
download | vaadin-framework-d1e6c704fd25a426d5956e521b0903910d7cb4cb.tar.gz vaadin-framework-d1e6c704fd25a426d5956e521b0903910d7cb4cb.zip |
All updates to Escalator size should get reported to LayoutManager. (#12050)
Delayed size changes caused by added or removed scrollbars should be
taken into account.
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridSizeChange.java | 109 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridSizeChangeTest.java | 95 |
2 files changed, 204 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSizeChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSizeChange.java new file mode 100644 index 0000000000..a446e47d90 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSizeChange.java @@ -0,0 +1,109 @@ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.VerticalLayout; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridSizeChange extends AbstractReindeerTestUI { + + private Grid<Integer> grid; + private List<Integer> data; + private ListDataProvider<Integer> dataProvider; + private int counter = 0; + + @Override + protected void setup(VaadinRequest request) { + grid = new Grid<>(); + data = new ArrayList<>(); + for (int i = 0; i < 10; ++i) { + data.add(i); + ++counter; + } + + dataProvider = DataProvider.ofCollection(data); + grid.setDataProvider(dataProvider); + + // create column and fill rows + grid.addColumn(item -> "row_" + item).setCaption("Item"); + + // set height mode and height + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(10); + grid.setWidth(90, Unit.PIXELS); + + // create a tabsheet with one tab and place grid inside + VerticalLayout tab = new VerticalLayout(); + tab.setSpacing(false); + tab.setMargin(false); + TabSheet tabSheet = new TabSheet(); + tabSheet.setWidthUndefined(); + tabSheet.addTab(tab, "Tab"); + tab.addComponent(grid); + + GridLayout layout = new GridLayout(3, 2); + layout.setDefaultComponentAlignment(Alignment.TOP_CENTER); + + layout.addComponent(new Button("Reduce height", e -> { + double newHeight = grid.getHeightByRows() - 1; + grid.setHeightByRows(newHeight); + })); + + layout.addComponent(new Button("Remove row", e -> { + removeRow(); + dataProvider.refreshAll(); + })); + + layout.addComponent(new Button("Reduce width", e -> { + grid.setWidth(grid.getWidth() - 30, Unit.PIXELS); + })); + + layout.addComponent(new Button("Increase height", e -> { + double newHeight = grid.getHeightByRows() + 1; + grid.setHeightByRows(newHeight); + })); + + layout.addComponent(new Button("Add row", e -> { + addRow(); + dataProvider.refreshAll(); + })); + + layout.addComponent(new Button("Increase width", e -> { + grid.setWidth(grid.getWidth() + 30, Unit.PIXELS); + })); + + addComponent(tabSheet); + addComponent(layout); + + getLayout().setSpacing(true); + } + + private void removeRow() { + data.remove(0); + dataProvider.refreshAll(); + } + + private void addRow() { + ++counter; + data.add(counter); + dataProvider.refreshAll(); + } + + @Override + protected String getTestDescription() { + return "Changing Grid size should resize the TabSheet accordingly " + + "even if scrollbar(s) appear or disappear."; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSizeChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSizeChangeTest.java new file mode 100644 index 0000000000..3b8e485ed9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSizeChangeTest.java @@ -0,0 +1,95 @@ +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.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridSizeChangeTest extends MultiBrowserTest { + + private TabSheetElement tabSheet; + private GridElement grid; + private WebElement vScrollbar; + private WebElement hScrollbar; + + @Test + public void scrollbarsTakenIntoAccountInSizeChanges() { + openTestURL(); + tabSheet = $(TabSheetElement.class).first(); + grid = $(GridElement.class).first(); + + vScrollbar = grid.findElement(By.className("v-grid-scroller-vertical")); + hScrollbar = grid + .findElement(By.className("v-grid-scroller-horizontal")); + + // ensure no initial scrollbars + ensureVerticalScrollbar(false); + ensureHorizontalScrollbar(false); + + assertGridWithinTabSheet(); + + $(ButtonElement.class).caption("Reduce height").first().click(); + // more rows than height -> scrollbar + + assertGridWithinTabSheet(); + ensureVerticalScrollbar(true); + + $(ButtonElement.class).caption("Remove row").first().click(); + // height matches rows -> no scrollbar + + assertGridWithinTabSheet(); + ensureVerticalScrollbar(false); + + $(ButtonElement.class).caption("Reduce width").first().click(); + // column too wide -> scrollbar + + assertGridWithinTabSheet(); + ensureHorizontalScrollbar(true); + + $(ButtonElement.class).caption("Increase width").first().click(); + // column fits -> no scrollbar + + assertGridWithinTabSheet(); + ensureHorizontalScrollbar(false); + + $(ButtonElement.class).caption("Add row").first().click(); + // more rows than height -> scrollbar + + assertGridWithinTabSheet(); + ensureVerticalScrollbar(true); + + $(ButtonElement.class).caption("Increase height").first().click(); + // height matches rows -> no scrollbar + + assertGridWithinTabSheet(); + ensureVerticalScrollbar(false); + } + + private void ensureVerticalScrollbar(boolean displayed) { + assertEquals(displayed ? "block" : "none", + vScrollbar.getCssValue("display")); + } + + private void ensureHorizontalScrollbar(boolean displayed) { + assertEquals(displayed ? "block" : "none", + hScrollbar.getCssValue("display")); + } + + private void assertGridWithinTabSheet() throws AssertionError { + // allow two pixel leeway + assertThat( + "Grid and TabSheet should always have the same bottom position, " + + "not be offset by a scrollbar's thickness", + (double) grid.getLocation().getY() + grid.getSize().getHeight(), + closeTo(tabSheet.getLocation().getY() + + tabSheet.getSize().getHeight(), 2)); + } +} |