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.

GridScrolledToBottomTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import static org.hamcrest.Matchers.greaterThan;
  4. import static org.hamcrest.number.IsCloseTo.closeTo;
  5. import static org.junit.Assert.assertEquals;
  6. import java.util.List;
  7. import org.junit.Test;
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.interactions.Actions;
  11. import com.vaadin.testbench.TestBenchElement;
  12. import com.vaadin.testbench.elements.GridElement;
  13. import com.vaadin.testbench.elements.GridElement.GridRowElement;
  14. import com.vaadin.testbench.elements.VerticalSplitPanelElement;
  15. import com.vaadin.tests.tb3.MultiBrowserTest;
  16. public class GridScrolledToBottomTest extends MultiBrowserTest {
  17. @Test
  18. public void testResizingAndBack() {
  19. openTestURL();
  20. GridElement grid = $(GridElement.class).first();
  21. grid.scrollToRow(99);
  22. GridRowElement row99 = grid.getRow(99);
  23. int rowHeight = row99.getSize().getHeight();
  24. assertThat(grid.getLocation().getY() + grid.getSize().getHeight(),
  25. greaterThan(row99.getLocation().getY() + rowHeight - 2));
  26. VerticalSplitPanelElement splitPanel = $(
  27. VerticalSplitPanelElement.class).first();
  28. TestBenchElement splitter = splitPanel.getSplitter();
  29. // resize by three rows
  30. Actions actions = new Actions(driver);
  31. actions.clickAndHold(splitter).moveByOffset(0, -rowHeight * 3).release()
  32. .perform();
  33. // resize back by two rows
  34. actions.clickAndHold(splitter).moveByOffset(0, rowHeight * 2).release()
  35. .perform();
  36. GridRowElement row95 = grid.getRow(95);
  37. GridRowElement row97 = grid.getRow(97);
  38. assertThat((double) row97.getLocation().getY(),
  39. greaterThan(row95.getLocation().getY() + rowHeight * 1.5));
  40. }
  41. @Test
  42. public void testResizingHalfRow() {
  43. openTestURL();
  44. GridElement grid = $(GridElement.class).first();
  45. grid.scrollToRow(99);
  46. GridRowElement row99 = grid.getRow(99);
  47. int rowHeight = row99.getSize().getHeight();
  48. int gridBottomY = grid.getLocation().getY()
  49. + grid.getSize().getHeight();
  50. // ensure that grid really is scrolled to bottom
  51. assertThat((double) gridBottomY,
  52. closeTo((double) row99.getLocation().getY() + rowHeight, 1d));
  53. VerticalSplitPanelElement splitPanel = $(
  54. VerticalSplitPanelElement.class).first();
  55. TestBenchElement splitter = splitPanel.getSplitter();
  56. // resize by half a row
  57. Actions actions = new Actions(driver);
  58. actions.clickAndHold(splitter).moveByOffset(0, -rowHeight / 2).release()
  59. .perform();
  60. // the last row is now only half visible
  61. // can't query grid.getRow(99) now or it moves the row position,
  62. // have to use element query instead
  63. List<WebElement> rows = grid.findElement(By.className("v-grid-body"))
  64. .findElements(By.className("v-grid-row"));
  65. WebElement lastRow = rows.get(rows.size() - 1);
  66. WebElement secondToLastRow = rows.get(rows.size() - 2);
  67. // ensure the scrolling didn't jump extra
  68. assertEquals("Person 99",
  69. lastRow.findElement(By.className("v-grid-cell")).getText());
  70. assertEquals("Person 98", secondToLastRow
  71. .findElement(By.className("v-grid-cell")).getText());
  72. // re-calculate current end position
  73. gridBottomY = grid.getLocation().getY() + grid.getSize().getHeight();
  74. // ensure the correct final row really is only half visible at the
  75. // bottom
  76. assertThat(gridBottomY, greaterThan(lastRow.getLocation().getY()));
  77. assertThat(lastRow.getLocation().getY() + rowHeight,
  78. greaterThan(gridBottomY));
  79. }
  80. }