You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridSidebarPositionTest.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.grid;
  17. import java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.Dimension;
  22. import org.openqa.selenium.Point;
  23. import org.openqa.selenium.WebElement;
  24. import com.vaadin.testbench.elements.GridElement;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. public class GridSidebarPositionTest extends MultiBrowserTest {
  27. @Test
  28. public void heightRestrictedToBrowserWindow() {
  29. openTestURL();
  30. GridElement gridWithVeryManyColumns = $(LegacyGridElement.class)
  31. .id(GridSidebarPosition.POPUP_WINDOW_HEIGHT);
  32. getSidebarOpenButton(gridWithVeryManyColumns).click();
  33. Dimension popupSize = getSidebarPopup().getSize();
  34. Dimension browserWindowSize = getDriver().manage().window().getSize();
  35. Assert.assertTrue(
  36. popupSize.getHeight() <= browserWindowSize.getHeight());
  37. }
  38. @Test
  39. public void popupNotBelowBrowserWindow() {
  40. openTestURL();
  41. GridElement gridAtBottom = $(LegacyGridElement.class)
  42. .id(GridSidebarPosition.POPUP_WINDOW_MOVED_UP);
  43. getSidebarOpenButton(gridAtBottom).click();
  44. WebElement sidebarPopup = getSidebarPopup();
  45. Dimension popupSize = sidebarPopup.getSize();
  46. Point popupLocation = sidebarPopup.getLocation();
  47. int popupBottom = popupLocation.getY() + popupSize.getHeight();
  48. Dimension browserWindowSize = getDriver().manage().window().getSize();
  49. Assert.assertTrue(popupBottom <= browserWindowSize.getHeight());
  50. }
  51. @Test
  52. public void popupAbove() {
  53. openTestURL();
  54. GridElement gridPopupAbove = $(LegacyGridElement.class)
  55. .id(GridSidebarPosition.POPUP_ABOVE);
  56. WebElement sidebarOpenButton = getSidebarOpenButton(gridPopupAbove);
  57. sidebarOpenButton.click();
  58. WebElement sidebarPopup = getSidebarPopup();
  59. Dimension popupSize = sidebarPopup.getSize();
  60. Point popupLocation = sidebarPopup.getLocation();
  61. int popupBottom = popupLocation.getY() + popupSize.getHeight();
  62. int sideBarButtonTop = sidebarOpenButton.getLocation().getY();
  63. Assert.assertTrue(popupBottom <= sideBarButtonTop);
  64. }
  65. protected WebElement getSidebarOpenButton(GridElement grid) {
  66. List<WebElement> elements = grid
  67. .findElements(By.className("v-grid-sidebar-button"));
  68. return elements.isEmpty() ? null : elements.get(0);
  69. }
  70. protected WebElement getSidebarPopup() {
  71. List<WebElement> elements = findElements(
  72. By.className("v-grid-sidebar-popup"));
  73. return elements.isEmpty() ? null : elements.get(0);
  74. }
  75. }