diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-11-29 11:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-29 11:21:14 +0200 |
commit | 7bf6967182834ea858489d7b3c08336d1b40a563 (patch) | |
tree | 57a32913a611b1d79e5a6afcb22c5e70c50dd232 /uitest | |
parent | e38e1f905792a2941adcb70c07e464c43b773ec7 (diff) | |
download | vaadin-framework-7bf6967182834ea858489d7b3c08336d1b40a563.tar.gz vaadin-framework-7bf6967182834ea858489d7b3c08336d1b40a563.zip |
Fix selection column size calculation without data (#10384)
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectEmpty.java | 44 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectEmptyTest.java | 42 |
2 files changed, 86 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectEmpty.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectEmpty.java new file mode 100644 index 0000000000..7aa1c0f2fd --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectEmpty.java @@ -0,0 +1,44 @@ +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.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.components.grid.MultiSelectionModel; +import com.vaadin.ui.components.grid.MultiSelectionModel.SelectAllCheckBoxVisibility; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class GridMultiSelectEmpty extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid<String> grid = new Grid<>(); + grid.addColumn(t -> t).setCaption("String"); + grid.setSelectionMode(SelectionMode.MULTI); + MultiSelectionModel<String> selectionModel = (MultiSelectionModel<String>) grid + .getSelectionModel(); + selectionModel.setSelectAllCheckBoxVisibility( + SelectAllCheckBoxVisibility.HIDDEN); + + List<String> items = new ArrayList<>(); + ListDataProvider<String> dataProvider = DataProvider + .ofCollection(items); + grid.setDataProvider(dataProvider); + + addComponent(grid); + addComponent(new Button("Add Row", e -> { + items.add("Foo!"); + dataProvider.refreshAll(); + })); + addComponent(new Button("Recalculate", e -> { + grid.recalculateColumnWidths(); + })); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectEmptyTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectEmptyTest.java new file mode 100644 index 0000000000..baf85cc45a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectEmptyTest.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridMultiSelectEmptyTest extends MultiBrowserTest { + + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + // On PhantomJS the result is more correct before recalculation. + return getBrowsersExcludingPhantomJS(); + } + + @Test + public void testCheckBoxColumnCorrectSize() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + int startingWidth = grid.getHeaderCell(0, 0).getSize().getWidth(); + $(ButtonElement.class).caption("Add Row").first().click(); + int currentWidth = grid.getHeaderCell(0, 0).getSize().getWidth(); + + assertEquals( + "Checkbox column size should not change when data is added", + startingWidth, currentWidth); + + $(ButtonElement.class).caption("Recalculate").first().click(); + currentWidth = grid.getHeaderCell(0, 0).getSize().getWidth(); + assertEquals( + "Checkbox column size should not change when columns are recalculated", + startingWidth, currentWidth); + } + +} |