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.

GridDetailsUpdateItemsTest.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.assertFalse;
  5. import static org.junit.Assert.assertNotEquals;
  6. import org.junit.Test;
  7. import org.openqa.selenium.By;
  8. import com.vaadin.testbench.TestBenchElement;
  9. import com.vaadin.testbench.elements.ButtonElement;
  10. import com.vaadin.testbench.elements.GridElement;
  11. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. public class GridDetailsUpdateItemsTest extends MultiBrowserTest {
  14. @Test
  15. public void testDetailsUpdateWithItems() {
  16. openTestURL();
  17. GridElement grid = $(GridElement.class).first();
  18. ButtonElement button = $(ButtonElement.class)
  19. .caption("Change with details").first();
  20. String details0 = grid.getDetails(0).getText();
  21. // change the contents
  22. button.click();
  23. sleep(200);
  24. TestBenchElement detailCell0 = grid.getDetails(0);
  25. // ensure contents have updated
  26. String updatedDetails0 = detailCell0.getText();
  27. assertNotEquals("Details should not be empty", "", updatedDetails0);
  28. assertNotEquals("Unexpected detail contents for row 0", details0,
  29. updatedDetails0);
  30. GridCellElement cell1_0 = grid.getCell(1, 0);
  31. TestBenchElement detailCell1 = grid.getDetails(1);
  32. // ensure positioning is correct
  33. assertDirectlyAbove(detailCell0, cell1_0);
  34. assertDirectlyAbove(cell1_0, detailCell1);
  35. }
  36. @Test
  37. public void testRemovingDetailsWithItemUpdateRepositionsRowsCorrectly() {
  38. openTestURL();
  39. GridElement grid = $(GridElement.class).first();
  40. ButtonElement button = $(ButtonElement.class)
  41. .caption("Change without details").first();
  42. assertFalse("Details not found when there should be some.",
  43. grid.findElements(By.className("v-grid-spacer")).isEmpty());
  44. // change the contents
  45. button.click();
  46. waitForElementNotPresent(By.className("v-grid-spacer"));
  47. GridCellElement cell0_0 = grid.getCell(0, 0);
  48. GridCellElement cell1_0 = grid.getCell(1, 0);
  49. // ensure positioning is correct
  50. assertDirectlyAbove(cell0_0, cell1_0);
  51. }
  52. private void assertDirectlyAbove(TestBenchElement above,
  53. TestBenchElement below) {
  54. int aboveBottom = above.getLocation().getY()
  55. + above.getSize().getHeight();
  56. int belowTop = below.getLocation().getY();
  57. assertThat("Unexpected positions.", (double) aboveBottom,
  58. closeTo(belowTop, 1d));
  59. }
  60. }