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 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.assertNotEquals;
  5. import org.junit.Test;
  6. import com.vaadin.testbench.TestBenchElement;
  7. import com.vaadin.testbench.elements.ButtonElement;
  8. import com.vaadin.testbench.elements.GridElement;
  9. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  10. import com.vaadin.tests.tb3.MultiBrowserTest;
  11. public class GridDetailsUpdateItemsTest extends MultiBrowserTest {
  12. @Test
  13. public void testDetailsUpdateWithItems() {
  14. openTestURL();
  15. GridElement grid = $(GridElement.class).first();
  16. ButtonElement button = $(ButtonElement.class).first();
  17. String details0 = grid.getDetails(0).getText();
  18. // change the contents
  19. button.click();
  20. sleep(200);
  21. TestBenchElement detailCell0 = grid.getDetails(0);
  22. // ensure contents have updated
  23. String updatedDetails0 = detailCell0.getText();
  24. assertNotEquals("Details should not be empty", "", updatedDetails0);
  25. assertNotEquals("Unexpected detail contents for row 0", details0,
  26. updatedDetails0);
  27. GridCellElement cell1_0 = grid.getCell(1, 0);
  28. TestBenchElement detailCell1 = grid.getDetails(1);
  29. // ensure positioning is correct
  30. assertDirectlyAbove(detailCell0, cell1_0);
  31. assertDirectlyAbove(cell1_0, detailCell1);
  32. }
  33. private void assertDirectlyAbove(TestBenchElement above,
  34. TestBenchElement below) {
  35. int aboveBottom = above.getLocation().getY()
  36. + above.getSize().getHeight();
  37. int belowTop = below.getLocation().getY();
  38. assertThat("Unexpected positions.", (double) aboveBottom,
  39. closeTo(belowTop, 1d));
  40. }
  41. }