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.

GridHeightTest.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package com.vaadin.tests.components.grid;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import java.util.Map.Entry;
  5. import org.junit.Ignore;
  6. import org.junit.Test;
  7. import org.openqa.selenium.By;
  8. import com.vaadin.testbench.elements.GridElement;
  9. import com.vaadin.testbench.elements.GridElement.GridRowElement;
  10. import com.vaadin.testbench.elements.RadioButtonGroupElement;
  11. import com.vaadin.testbench.parallel.TestCategory;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. import static org.hamcrest.MatcherAssert.assertThat;
  14. import static org.hamcrest.Matchers.is;
  15. import static org.hamcrest.number.IsCloseTo.closeTo;
  16. import static org.junit.Assert.fail;
  17. /**
  18. * Tests that Grid gets correct height based on height mode, and resizes
  19. * properly with details row if height is undefined.
  20. *
  21. * @author Vaadin Ltd
  22. */
  23. @TestCategory("grid")
  24. public class GridHeightTest extends MultiBrowserTest {
  25. @Override
  26. public void setup() throws Exception {
  27. super.setup();
  28. openTestURL();
  29. waitForElementPresent(By.className("v-grid"));
  30. }
  31. @Test
  32. @Ignore
  33. public void testGridHeightAndResizingUndefined()
  34. throws InterruptedException {
  35. assertNoErrors(testGridHeightAndResizing(GridHeight.UNDEFINED));
  36. }
  37. @Test
  38. @Ignore
  39. public void testGridHeightAndResizingRow() throws InterruptedException {
  40. assertNoErrors(testGridHeightAndResizing(GridHeight.ROW3));
  41. }
  42. @Test
  43. public void testGridHeightAndResizingFull() throws InterruptedException {
  44. assertNoErrors(testGridHeightAndResizing(GridHeight.FULL));
  45. }
  46. private Map<AssertionError, Object[]> testGridHeightAndResizing(
  47. Object gridHeight) throws InterruptedException {
  48. Map<AssertionError, Object[]> errors = new HashMap<>();
  49. String caption;
  50. if (GridHeight.ROW3.equals(gridHeight)) {
  51. caption = gridHeight + " rows";
  52. } else {
  53. caption = (String) gridHeight;
  54. }
  55. $(RadioButtonGroupElement.class).id("gridHeightSelector")
  56. .selectByText(caption);
  57. for (String gridWidth : GridHeight.gridWidths) {
  58. $(RadioButtonGroupElement.class).id("gridWidthSelector")
  59. .selectByText(gridWidth);
  60. for (String detailsRowHeight : GridHeight.detailsRowHeights) {
  61. $(RadioButtonGroupElement.class).id("detailsHeightSelector")
  62. .selectByText(detailsRowHeight);
  63. sleep(500);
  64. GridElement grid = $(GridElement.class).first();
  65. int initialHeight = grid.getSize().getHeight();
  66. try {
  67. // check default height
  68. assertGridHeight(getExpectedInitialHeight(gridHeight),
  69. initialHeight);
  70. } catch (AssertionError e) {
  71. errors.put(e, new Object[] { gridHeight, gridWidth,
  72. detailsRowHeight, "initial" });
  73. fail();
  74. }
  75. GridRowElement row = grid.getRow(2);
  76. row.click(getXOffset(row, 5), getYOffset(row, 5));
  77. waitForElementPresent(By.id("lbl1"));
  78. int openHeight = grid.getSize().getHeight();
  79. try {
  80. // check height with details row opened
  81. assertGridHeight(getExpectedOpenedHeight(gridHeight,
  82. detailsRowHeight), openHeight);
  83. } catch (AssertionError e) {
  84. errors.put(e, new Object[] { gridHeight, gridWidth,
  85. detailsRowHeight, "opened" });
  86. }
  87. row.click(5, 5);
  88. waitForElementNotPresent(By.id("lbl1"));
  89. int afterHeight = grid.getSize().getHeight();
  90. try {
  91. // check height with details row closed again
  92. assertThat("Unexpected Grid Height", afterHeight,
  93. is(initialHeight));
  94. } catch (AssertionError e) {
  95. errors.put(e, new Object[] { gridHeight, gridWidth,
  96. detailsRowHeight, "closed" });
  97. }
  98. }
  99. }
  100. return errors;
  101. }
  102. private void assertNoErrors(Map<AssertionError, Object[]> errors) {
  103. if (!errors.isEmpty()) {
  104. StringBuilder sb = new StringBuilder("Exceptions: ");
  105. for (Entry<AssertionError, Object[]> entry : errors.entrySet()) {
  106. sb.append("\n");
  107. for (Object value : entry.getValue()) {
  108. sb.append(value);
  109. sb.append(" - ");
  110. }
  111. sb.append(entry.getKey().getMessage());
  112. }
  113. fail(sb.toString());
  114. }
  115. }
  116. private int getExpectedInitialHeight(Object gridHeight) {
  117. int result = 0;
  118. if (GridHeight.UNDEFINED.equals(gridHeight)
  119. || GridHeight.ROW3.equals(gridHeight)) {
  120. result = 81;
  121. } else if (GridHeight.FULL.equals(gridHeight)) {
  122. // pre-existing issue
  123. result = 400;
  124. }
  125. return result;
  126. }
  127. private int getExpectedOpenedHeight(Object gridHeight,
  128. Object detailsRowHeight) {
  129. int result = 0;
  130. if (GridHeight.UNDEFINED.equals(gridHeight)) {
  131. if (GridHeight.PX100.equals(detailsRowHeight)) {
  132. result = 182;
  133. } else if (GridHeight.FULL.equals(detailsRowHeight)) {
  134. result = 131;
  135. } else if (GridHeight.UNDEFINED.equals(detailsRowHeight)) {
  136. result = 100;
  137. }
  138. } else if (GridHeight.ROW3.equals(gridHeight)
  139. || GridHeight.FULL.equals(gridHeight)) {
  140. result = getExpectedInitialHeight(gridHeight);
  141. }
  142. return result;
  143. }
  144. private void assertGridHeight(int expected, int actual) {
  145. assertThat("Unexpected Grid Height", (double) actual,
  146. closeTo(expected, 1));
  147. }
  148. }