summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-08-30 13:01:46 +0300
committerArtur Signell <artur@vaadin.com>2016-09-01 10:36:14 +0000
commitda8394e5adeda85047a5e167bdd0904dc3387a87 (patch)
tree911cbe7428ec6dcfa9d422083e9d1da07320ea12 /uitest
parentdcf64cd9365c27dc65c78f14091d3365e0cc7cc8 (diff)
downloadvaadin-framework-da8394e5adeda85047a5e167bdd0904dc3387a87.tar.gz
vaadin-framework-da8394e5adeda85047a5e167bdd0904dc3387a87.zip
Reintroduce frozen columns and height by rows to Grid
Change-Id: I5fecfabd023b39dc252e47a6aa403a79034b0f3d
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java38
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicStructureTest.java87
2 files changed, 125 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
index fa032dac48..3445a3e3f3 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
@@ -1,12 +1,17 @@
package com.vaadin.tests.components.grid.basics;
+import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
@@ -20,6 +25,7 @@ import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
+@Widgetset("com.vaadin.DefaultWidgetSet")
public class GridBasics extends AbstractTestUIWithLog {
private static class DetailedDetailsGenerator
@@ -121,10 +127,42 @@ public class GridBasics extends AbstractTestUIWithLog {
private Component createMenu() {
MenuBar menu = new MenuBar();
MenuItem componentMenu = menu.addItem("Component", null);
+ createStateMenu(componentMenu.addItem("State", null));
+ createSizeMenu(componentMenu.addItem("Size", null));
createDetailsMenu(componentMenu.addItem("Details", null));
return menu;
}
+ private void createSizeMenu(MenuItem sizeMenu) {
+ MenuItem heightByRows = sizeMenu.addItem("Height by Rows", null);
+ DecimalFormat df = new DecimalFormat("0.00");
+ Stream.of(0.33, 0.67, 1.00, 1.33, 1.67, 2.00, 2.33, 2.67, 3.00, 3.33,
+ 3.67, 4.00, 4.33, 4.67)
+ .forEach(d -> addGridMethodMenu(heightByRows,
+ df.format(d) + " rows", d, grid::setHeightByRows));
+ sizeMenu.addItem("HeightMode Row", item -> {
+ grid.setHeightMode(
+ item.isChecked() ? HeightMode.ROW : HeightMode.CSS);
+ }).setCheckable(true);
+
+ MenuItem heightMenu = sizeMenu.addItem("Height", null);
+ Stream.of(50, 100, 200, 400).map(i -> i + "px").forEach(
+ i -> addGridMethodMenu(heightMenu, i, i, grid::setHeight));
+ }
+
+ private void createStateMenu(MenuItem stateMenu) {
+ MenuItem frozenColMenu = stateMenu.addItem("Frozen column count", null);
+ for (int i = -1; i < 3; ++i) {
+ addGridMethodMenu(frozenColMenu, "" + i, i,
+ grid::setFrozenColumnCount);
+ }
+ }
+
+ private <T> void addGridMethodMenu(MenuItem parent, String name, T value,
+ Consumer<T> method) {
+ parent.addItem(name, menuItem -> method.accept(value));
+ }
+
/* DetailsGenerator related things */
private void createDetailsMenu(MenuItem detailsMenu) {
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicStructureTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicStructureTest.java
new file mode 100644
index 0000000000..9493463ddb
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicStructureTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.basics;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.TestBenchElement;
+
+public class GridBasicStructureTest extends GridBasicsTest {
+
+ @Test
+ public void testFreezingColumn() throws Exception {
+ // Freeze column 1
+ selectMenuPath("Component", "State", "Frozen column count", "1");
+
+ WebElement cell = getGridElement().getCell(0, 0);
+ assertTrue("First cell on a row should be frozen",
+ cell.getAttribute("class").contains("frozen"));
+
+ assertFalse("Second cell on a row should not be frozen",
+ getGridElement().getCell(0, 1).getAttribute("class")
+ .contains("frozen"));
+
+ int cellX = cell.getLocation().getX();
+ scrollGridHorizontallyTo(100);
+ assertEquals("First cell should not move when scrolling", cellX,
+ cell.getLocation().getX());
+ }
+
+ @Test
+ public void testHeightByRows() throws Exception {
+ int initialHeight = getGridElement().getSize().getHeight();
+
+ selectMenuPath("Component", "Size", "HeightMode Row");
+ selectMenuPath("Component", "Size", "Height by Rows", "2.00 rows");
+
+ TestBenchElement tableWrapper = getGridElement().getTableWrapper();
+ int rowHeight = getGridElement().getRow(0).getSize().getHeight();
+
+ assertTrue("Grid height was not 3 rows", Math
+ .abs(rowHeight * 3 - tableWrapper.getSize().getHeight()) < 2);
+
+ selectMenuPath("Component", "Size", "Height by Rows", "3.33 rows");
+
+ assertTrue("Grid height was not 4.33 rows", Math.abs(
+ rowHeight * 4.33 - tableWrapper.getSize().getHeight()) < 2);
+
+ selectMenuPath("Component", "Size", "HeightMode Row");
+ assertEquals("Grid should have returned to its original size",
+ initialHeight, getGridElement().getSize().getHeight());
+ }
+
+ @Test
+ public void testHeightModeChanges() throws Exception {
+ selectMenuPath("Component", "Size", "Height by Rows", "2.00 rows");
+
+ TestBenchElement tableWrapper = getGridElement().getTableWrapper();
+ int rowHeight = getGridElement().getRow(0).getSize().getHeight();
+
+ assertTrue("Grid height mode did not become ROW", Math
+ .abs(rowHeight * 3 - tableWrapper.getSize().getHeight()) < 2);
+
+ selectMenuPath("Component", "Size", "Height", "200px");
+
+ assertEquals("Grid height mode did not become CSS", 200,
+ getGridElement().getSize().getHeight());
+
+ }
+}