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.

GridEditRowTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.CoreMatchers.is;
  3. import static org.hamcrest.CoreMatchers.not;
  4. import static org.hamcrest.MatcherAssert.assertThat;
  5. import static org.hamcrest.Matchers.greaterThan;
  6. import org.junit.Test;
  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.GridElement.GridEditorElement;
  11. import com.vaadin.testbench.parallel.TestCategory;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. /**
  14. * Tests for ensuring that the furthest away visible rows don't get emptied when
  15. * editRow is called, and that the editor doesn't open beyond the lower border
  16. * of the Grid.
  17. *
  18. */
  19. @TestCategory("grid")
  20. public class GridEditRowTest extends MultiBrowserTest {
  21. private GridElement grid;
  22. private ButtonElement addButton;
  23. private ButtonElement editButton;
  24. @Override
  25. public void setup() throws Exception {
  26. super.setup();
  27. openTestURL();
  28. grid = $(GridElement.class).first();
  29. addButton = $(ButtonElement.class).caption("Add").first();
  30. editButton = $(ButtonElement.class).caption("Edit").first();
  31. }
  32. public void addRows(int count) {
  33. for (int i = 0; i < count; ++i) {
  34. addButton.click();
  35. }
  36. }
  37. public void editLastRow() {
  38. editButton.click();
  39. }
  40. private void assertRowContents(int rowIndex) {
  41. assertThat(grid.getCell(rowIndex, 0).getText(), is("name" + rowIndex));
  42. }
  43. private void assertEditorWithinGrid() {
  44. GridEditorElement editor = grid.getEditor();
  45. assertThat(editor.getLocation().y + editor.getSize().height,
  46. not(greaterThan(grid.getLocation().y + grid.getSize().height)));
  47. }
  48. @Test
  49. public void testEditWhenAllRowsVisible() {
  50. addRows(7);
  51. assertRowContents(0);
  52. editLastRow();
  53. assertRowContents(0);
  54. waitForElementVisible(By.className("v-grid-editor"));
  55. assertEditorWithinGrid();
  56. }
  57. @Test
  58. public void testEditWhenSomeRowsNotVisible() {
  59. addRows(11);
  60. assertRowContents(3);
  61. editLastRow();
  62. waitForElementVisible(By.className("v-grid-editor"));
  63. assertRowContents(3);
  64. assertEditorWithinGrid();
  65. }
  66. @Test
  67. public void testEditWhenSomeRowsOutsideOfCache() {
  68. addRows(100);
  69. assertRowContents(91);
  70. editLastRow();
  71. waitForElementVisible(By.className("v-grid-editor"));
  72. assertRowContents(91);
  73. assertEditorWithinGrid();
  74. }
  75. }