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.

GridSizeChangeTest.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import static org.hamcrest.number.IsCloseTo.closeTo;
  4. import static org.junit.Assert.assertEquals;
  5. import org.junit.Test;
  6. import org.openqa.selenium.WebElement;
  7. import com.vaadin.testbench.By;
  8. import com.vaadin.testbench.elements.ButtonElement;
  9. import com.vaadin.testbench.elements.GridElement;
  10. import com.vaadin.testbench.elements.TabSheetElement;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. public class GridSizeChangeTest extends MultiBrowserTest {
  13. private TabSheetElement tabSheet;
  14. private GridElement grid;
  15. private WebElement vScrollbar;
  16. private WebElement hScrollbar;
  17. @Test
  18. public void scrollbarsTakenIntoAccountInSizeChanges() {
  19. openTestURL();
  20. tabSheet = $(TabSheetElement.class).first();
  21. grid = $(GridElement.class).first();
  22. vScrollbar = grid.findElement(By.className("v-grid-scroller-vertical"));
  23. hScrollbar = grid
  24. .findElement(By.className("v-grid-scroller-horizontal"));
  25. // ensure no initial scrollbars
  26. ensureVerticalScrollbar(false);
  27. ensureHorizontalScrollbar(false);
  28. assertGridWithinTabSheet();
  29. $(ButtonElement.class).caption("Reduce height").first().click();
  30. // more rows than height -> scrollbar
  31. assertGridWithinTabSheet();
  32. ensureVerticalScrollbar(true);
  33. $(ButtonElement.class).caption("Remove row").first().click();
  34. // height matches rows -> no scrollbar
  35. assertGridWithinTabSheet();
  36. ensureVerticalScrollbar(false);
  37. $(ButtonElement.class).caption("Reduce width").first().click();
  38. // column too wide -> scrollbar
  39. assertGridWithinTabSheet();
  40. ensureHorizontalScrollbar(true);
  41. $(ButtonElement.class).caption("Increase width").first().click();
  42. // column fits -> no scrollbar
  43. assertGridWithinTabSheet();
  44. ensureHorizontalScrollbar(false);
  45. $(ButtonElement.class).caption("Add row").first().click();
  46. // more rows than height -> scrollbar
  47. assertGridWithinTabSheet();
  48. ensureVerticalScrollbar(true);
  49. $(ButtonElement.class).caption("Increase height").first().click();
  50. // height matches rows -> no scrollbar
  51. assertGridWithinTabSheet();
  52. ensureVerticalScrollbar(false);
  53. }
  54. private void ensureVerticalScrollbar(boolean displayed) {
  55. assertEquals(displayed ? "block" : "none",
  56. vScrollbar.getCssValue("display"));
  57. }
  58. private void ensureHorizontalScrollbar(boolean displayed) {
  59. assertEquals(displayed ? "block" : "none",
  60. hScrollbar.getCssValue("display"));
  61. }
  62. private void assertGridWithinTabSheet() throws AssertionError {
  63. // allow two pixel leeway
  64. assertThat(
  65. "Grid and TabSheet should always have the same bottom position, "
  66. + "not be offset by a scrollbar's thickness",
  67. (double) grid.getLocation().getY() + grid.getSize().getHeight(),
  68. closeTo(tabSheet.getLocation().getY()
  69. + tabSheet.getSize().getHeight(), 2));
  70. }
  71. }