summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-05-30 16:24:58 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-05-30 16:24:58 +0300
commit39846ae08337d55a24d3d90a6350f8e565a5c27f (patch)
tree5b77ba5236e440f7f79990b5e1372188681338a8 /uitest
parent2b9bcc62cfa0ee1d4f5da915190a8f03f076037c (diff)
downloadvaadin-framework-39846ae08337d55a24d3d90a6350f8e565a5c27f.tar.gz
vaadin-framework-39846ae08337d55a24d3d90a6350f8e565a5c27f.zip
Allow grid columns to optionally shrink to be narrower than contents
Fixes #8548
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContents.java45
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContentsTest.java35
-rw-r--r--uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java23
3 files changed, 97 insertions, 6 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContents.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContents.java
new file mode 100644
index 0000000000..e008adbf19
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContents.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Grid;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class GridColumnShrinkSmallerThanContents extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(createGrid(true));
+ addComponent(createGrid(false));
+ }
+
+ private Component createGrid(boolean minimumWidthFromContent) {
+ Grid<Object> grid = new Grid<>();
+ grid.addColumn(item -> "Contents in column 1");
+ grid.addColumn(
+ item -> "Contents in column 2. Contents in column 2. Contents in column 2. Contents in column 2. Contents in column 2.")
+ .setExpandRatio(1)
+ .setMinimumWidthFromContent(minimumWidthFromContent);
+ grid.setItems(new Object(), new Object());
+ grid.setWidth("500px");
+ return grid;
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContentsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContentsTest.java
new file mode 100644
index 0000000000..94fe348bff
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnShrinkSmallerThanContentsTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridColumnShrinkSmallerThanContentsTest extends SingleBrowserTest {
+
+ @Test
+ public void scrollbarAndNoScrollbar() {
+ openTestURL();
+ GridElement noshrinkColumnGrid = $(GridElement.class).get(0);
+ GridElement shrinkColumnGrid = $(GridElement.class).get(1);
+ assertHorizontalScrollbar(noshrinkColumnGrid.getHorizontalScroller(),
+ "Should have a horizontal scrollbar as column 2 should be wide");
+ assertNoHorizontalScrollbar(shrinkColumnGrid.getHorizontalScroller(),
+ "Should not have a horizontal scrollbar as column 2 should be narrow");
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java
index 8447e1e4d5..5f02282a51 100644
--- a/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest/src/test/java/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -1171,18 +1171,29 @@ public abstract class AbstractTB3Test extends ParallelTest {
protected void assertNoHorizontalScrollbar(WebElement element,
String errorMessage) {
+ assertHasHorizontalScrollbar(element, errorMessage, false);
+ }
+
+ protected void assertHorizontalScrollbar(WebElement element,
+ String errorMessage) {
+ assertHasHorizontalScrollbar(element, errorMessage, true);
+ }
+
+ private void assertHasHorizontalScrollbar(WebElement element,
+ String errorMessage, boolean expected) {
// IE rounds clientWidth/clientHeight down and scrollHeight/scrollWidth
// up, so using clientWidth/clientHeight will fail if the element height
// is not an integer
int clientWidth = getClientWidth(element);
int scrollWidth = getScrollWidth(element);
boolean hasScrollbar = scrollWidth > clientWidth;
-
- Assert.assertFalse(
- "The element should not have a horizontal scrollbar (scrollWidth: "
- + scrollWidth + ", clientWidth: " + clientWidth + "): "
- + errorMessage,
- hasScrollbar);
+ String message = "The element should";
+ if (!expected) {
+ message += " not";
+ }
+ message += " have a horizontal scrollbar (scrollWidth: " + scrollWidth
+ + ", clientWidth: " + clientWidth + "): " + errorMessage;
+ Assert.assertEquals(message, expected, hasScrollbar);
}
protected void assertNoVerticalScrollbar(WebElement element,