diff options
author | Artur Signell <artur@vaadin.com> | 2016-04-17 11:31:01 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-04-28 15:18:45 +0000 |
commit | 0b0495b6d87b3c623b38643ff1ce27abf5a30d5c (patch) | |
tree | d0c0b29753148eac0b7c1d473d10bf8d1235ed99 /uitest | |
parent | ab30dfe29d12e57d7c00c12cf2edc9328cb47a65 (diff) | |
download | vaadin-framework-0b0495b6d87b3c623b38643ff1ce27abf5a30d5c.tar.gz vaadin-framework-0b0495b6d87b3c623b38643ff1ce27abf5a30d5c.zip |
Restrict grid sidebar size to visible viewport (#19349)
Change-Id: I75b7c662251de53b46e045d17d3cac650586acd2
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java | 69 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.java | 95 |
2 files changed, 164 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java new file mode 100644 index 0000000000..852ec7cea6 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java @@ -0,0 +1,69 @@ +/* + * 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.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Grid; +import com.vaadin.ui.HorizontalLayout; + +@Theme("valo") +public class GridSidebarPosition extends AbstractTestUI { + + static final String POPUP_ABOVE = "above"; + static final String POPUP_WINDOW_MOVED_UP = "movedup"; + static final String POPUP_WINDOW_HEIGHT = "windowheight"; + + @Override + protected void setup(VaadinRequest request) { + HorizontalLayout hl = new HorizontalLayout(); + hl.setSpacing(true); + hl.setHeight("100%"); + setContent(hl); + Grid grid = new Grid("Popup window height"); + grid.setId(POPUP_WINDOW_HEIGHT); + grid.setWidth("100px"); + for (int i = 0; i < 30; i++) { + grid.addColumn( + "This is a really really really really long column name " + + i).setHidable(true); + } + hl.addComponent(grid); + + grid = new Grid("Popup moved up"); + grid.setId(POPUP_WINDOW_MOVED_UP); + grid.setWidth("100px"); + grid.setHeight("400px"); + for (int i = 0; i < 15; i++) { + grid.addColumn("Column " + i).setHidable(true); + } + hl.addComponent(grid); + hl.setComponentAlignment(grid, Alignment.BOTTOM_LEFT); + + grid = new Grid("Popup above"); + grid.setId(POPUP_ABOVE); + grid.setWidth("100px"); + grid.setHeight("200px"); + for (int i = 0; i < 10; i++) { + grid.addColumn("Column " + i).setHidable(true); + } + hl.addComponent(grid); + hl.setComponentAlignment(grid, Alignment.BOTTOM_LEFT); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.java new file mode 100644 index 0000000000..88771b50ca --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.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 java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridSidebarPositionTest extends MultiBrowserTest { + + @Test + public void heightRestrictedToBrowserWindow() { + openTestURL(); + GridElement gridWithVeryManyColumns = $(GridElement.class).id( + GridSidebarPosition.POPUP_WINDOW_HEIGHT); + getSidebarOpenButton(gridWithVeryManyColumns).click(); + Dimension popupSize = getSidebarPopup().getSize(); + Dimension browserWindowSize = getDriver().manage().window().getSize(); + + Assert.assertTrue(popupSize.getHeight() <= browserWindowSize + .getHeight()); + } + + @Test + public void popupNotBelowBrowserWindow() { + openTestURL(); + GridElement gridAtBottom = $(GridElement.class).id( + GridSidebarPosition.POPUP_WINDOW_MOVED_UP); + getSidebarOpenButton(gridAtBottom).click(); + WebElement sidebarPopup = getSidebarPopup(); + Dimension popupSize = sidebarPopup.getSize(); + Point popupLocation = sidebarPopup.getLocation(); + int popupBottom = popupLocation.getY() + popupSize.getHeight(); + Dimension browserWindowSize = getDriver().manage().window().getSize(); + + Assert.assertTrue(popupBottom <= browserWindowSize.getHeight()); + } + + @Test + public void popupAbove() { + openTestURL(); + GridElement gridPopupAbove = $(GridElement.class).id( + GridSidebarPosition.POPUP_ABOVE); + WebElement sidebarOpenButton = getSidebarOpenButton(gridPopupAbove); + sidebarOpenButton.click(); + WebElement sidebarPopup = getSidebarPopup(); + Dimension popupSize = sidebarPopup.getSize(); + Point popupLocation = sidebarPopup.getLocation(); + int popupBottom = popupLocation.getY() + popupSize.getHeight(); + int sideBarButtonTop; + if (BrowserUtil.isIE8(getDesiredCapabilities())) { + // IE8 gets the top coordinate for the button completely wrong for + // some reason + sideBarButtonTop = 660; + } else { + sideBarButtonTop = sidebarOpenButton.getLocation().getY(); + } + Assert.assertTrue(popupBottom <= sideBarButtonTop); + } + + protected WebElement getSidebarOpenButton(GridElement grid) { + List<WebElement> elements = grid.findElements(By + .className("v-grid-sidebar-button")); + return elements.isEmpty() ? null : elements.get(0); + } + + protected WebElement getSidebarPopup() { + List<WebElement> elements = findElements(By + .className("v-grid-sidebar-popup")); + return elements.isEmpty() ? null : elements.get(0); + } + +} |