summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-11-30 14:38:25 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2016-01-12 13:35:14 +0000
commit6d42267b118dd3939062611582932c1701567d45 (patch)
tree27078a40fe409fb24f58c90a5e3cad18eddc5a9d /uitest
parentb5efe7d243603effd392a6079d639f8b207c13be (diff)
downloadvaadin-framework-6d42267b118dd3939062611582932c1701567d45.tar.gz
vaadin-framework-6d42267b118dd3939062611582932c1701567d45.zip
Use LayoutManager for details rows (#18821, #18619)
Change-Id: I430e55db8a3e2860f68f5351e06d8d069a657d6e
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java103
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java76
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java95
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java77
4 files changed, 351 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java
new file mode 100644
index 0000000000..be82b49f0c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2000-2014 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.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.DetailsGenerator;
+import com.vaadin.ui.Grid.RowReference;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+
+/**
+ * Tests the layouting of Grid's details row when it contains a HorizontalLayout
+ * with expand ratios.
+ *
+ * @author Vaadin Ltd
+ */
+@SuppressWarnings("serial")
+public class GridDetailsLayoutExpand extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Grid grid = new Grid();
+ grid.setSizeFull();
+ grid.addColumn("name", String.class);
+ grid.addColumn("born", Integer.class);
+
+ grid.addRow("Nicolaus Copernicus", 1543);
+ grid.addRow("Galileo Galilei", 1564);
+ grid.addRow("Johannes Kepler", 1571);
+
+ addComponent(grid);
+
+ grid.setDetailsGenerator(new DetailsGenerator() {
+ @Override
+ public Component getDetails(final RowReference rowReference) {
+ final HorizontalLayout detailsLayout = new HorizontalLayout();
+ detailsLayout.setSizeFull();
+ detailsLayout.setHeightUndefined();
+
+ // Label 1 first element of the detailsLayout, taking 200 pixels
+ final Label lbl1 = new Label("test1");
+ lbl1.setWidth("200px");
+ detailsLayout.addComponent(lbl1);
+
+ // layout2 second element of the detailsLayout, taking the rest
+ // of the available space
+ final HorizontalLayout layout2 = new HorizontalLayout();
+ layout2.setSizeFull();
+ layout2.setHeightUndefined();
+ detailsLayout.addComponent(layout2);
+ detailsLayout.setExpandRatio(layout2, 1);
+
+ // 2 Labels added to the layout2
+ final Label lbl2 = new Label("test2");
+ lbl2.setId("lbl2");
+ layout2.addComponent(lbl2);
+
+ final Label lbl3 = new Label("test3");
+ lbl3.setId("lbl3");
+ layout2.addComponent(lbl3);
+
+ return detailsLayout;
+ }
+ });
+
+ grid.addItemClickListener(new ItemClickListener() {
+ @Override
+ public void itemClick(final ItemClickEvent event) {
+ final Object itemId = event.getItemId();
+ grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
+ }
+ });
+
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 18821;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Details row must be the same after opening another details row";
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java
new file mode 100644
index 0000000000..6ea72540b5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2000-2014 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 static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.parallel.Browser;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Tests the layouting of Grid's details row when it contains a HorizontalLayout
+ * with expand ratios.
+ *
+ * @author Vaadin Ltd
+ */
+@TestCategory("grid")
+public class GridDetailsLayoutExpandTest extends MultiBrowserTest {
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ List<DesiredCapabilities> browsersToTest = super.getBrowsersToTest();
+ // TODO: remove when #19326 is fixed
+ browsersToTest.remove(Browser.IE8.getDesiredCapabilities());
+ browsersToTest.remove(Browser.IE9.getDesiredCapabilities());
+ // for some reason PhantomJS doesn't find the label even if it detects
+ // the presence
+ browsersToTest.remove(Browser.PHANTOMJS.getDesiredCapabilities());
+ return browsersToTest;
+ }
+
+ @Test
+ public void testLabelWidths() {
+ openTestURL();
+ waitForElementPresent(By.className("v-grid"));
+
+ GridElement grid = $(GridElement.class).first();
+ int gridWidth = grid.getSize().width;
+
+ grid.getRow(2).click();
+ waitForElementPresent(By.id("lbl2"));
+
+ // space left over from first label should be divided equally
+ double expectedWidth = (double) (gridWidth - 200) / 2;
+ assertLabelWidth("lbl2", expectedWidth);
+ assertLabelWidth("lbl3", expectedWidth);
+ }
+
+ private void assertLabelWidth(String id, double expectedWidth) {
+ // 1px leeway for calculations
+ assertThat("Unexpected label width.", (double) $(LabelElement.class)
+ .id(id).getSize().width, closeTo(expectedWidth, 1d));
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java b/uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java
new file mode 100644
index 0000000000..51c2598cc0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2000-2014 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.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.DetailsGenerator;
+import com.vaadin.ui.Grid.RowReference;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+
+/**
+ * Tests that details row displays GridLayout contents properly.
+ *
+ * @author Vaadin Ltd
+ */
+public class GridLayoutDetailsRow extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Grid grid = new Grid();
+ grid.setSizeFull();
+ grid.addColumn("name", String.class);
+ grid.addColumn("born", Integer.class);
+
+ grid.addRow("Nicolaus Copernicus", 1543);
+ grid.addRow("Galileo Galilei", 1564);
+ grid.addRow("Johannes Kepler", 1571);
+
+ addComponent(grid);
+
+ grid.setDetailsGenerator(new DetailsGenerator() {
+ @Override
+ public Component getDetails(final RowReference rowReference) {
+ final GridLayout detailsLayout = new GridLayout();
+ detailsLayout.setSizeFull();
+ detailsLayout.setHeightUndefined();
+
+ final Label lbl1 = new Label("test1");
+ lbl1.setId("lbl1");
+ lbl1.setWidth("200px");
+ detailsLayout.addComponent(lbl1);
+
+ final Label lbl2 = new Label("test2");
+ lbl2.setId("lbl2");
+ detailsLayout.addComponent(lbl2);
+
+ final Label lbl3 = new Label("test3");
+ lbl3.setId("lbl3");
+ detailsLayout.addComponent(lbl3);
+
+ final Label lbl4 = new Label("test4");
+ lbl4.setId("lbl4");
+ detailsLayout.addComponent(lbl4);
+
+ return detailsLayout;
+ }
+ });
+
+ grid.addItemClickListener(new ItemClickListener() {
+ @Override
+ public void itemClick(final ItemClickEvent event) {
+ final Object itemId = event.getItemId();
+ grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
+ }
+ });
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "GridLayout as part of Grid detail row should be correctly computed/displayed.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 18619;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java b/uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java
new file mode 100644
index 0000000000..9ec54471b0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2000-2014 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 static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridLayoutElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.parallel.Browser;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Tests that details row displays GridLayout contents properly.
+ *
+ * @author Vaadin Ltd
+ */
+@TestCategory("grid")
+public class GridLayoutDetailsRowTest extends MultiBrowserTest {
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ List<DesiredCapabilities> browsersToTest = super.getBrowsersToTest();
+ // for some reason PhantomJS doesn't find the label even if it detects
+ // the presence
+ browsersToTest.remove(Browser.PHANTOMJS.getDesiredCapabilities());
+ return browsersToTest;
+ }
+
+ @Test
+ public void testLabelHeights() {
+ openTestURL();
+ waitForElementPresent(By.className("v-grid"));
+
+ GridElement grid = $(GridElement.class).first();
+
+ grid.getRow(2).click();
+ waitForElementPresent(By.id("lbl2"));
+
+ GridLayoutElement gridLayout = $(GridLayoutElement.class).first();
+ int gridLayoutHeight = gridLayout.getSize().height;
+
+ // height should be divided equally
+ double expectedHeight = gridLayoutHeight / 4;
+ assertLabelHeight("lbl1", expectedHeight);
+ assertLabelHeight("lbl2", expectedHeight);
+ assertLabelHeight("lbl3", expectedHeight);
+ assertLabelHeight("lbl4", expectedHeight);
+ }
+
+ private void assertLabelHeight(String id, double expectedHeight) {
+ // 1px leeway for calculations
+ assertThat("Unexpected label height.", (double) $(LabelElement.class)
+ .id(id).getSize().height, closeTo(expectedHeight, 1d));
+ }
+}