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.

GridRecalculateColumnWidthNewItemTest.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.core.IsNot.not;
  3. import static org.hamcrest.number.IsCloseTo.closeTo;
  4. import static org.junit.Assert.assertEquals;
  5. import static org.junit.Assert.assertThat;
  6. import java.io.IOException;
  7. import org.junit.Before;
  8. import org.junit.Test;
  9. import com.vaadin.testbench.elements.ButtonElement;
  10. import com.vaadin.testbench.elements.CheckBoxElement;
  11. import com.vaadin.testbench.elements.GridElement;
  12. import com.vaadin.tests.tb3.SingleBrowserTest;
  13. public class GridRecalculateColumnWidthNewItemTest extends SingleBrowserTest {
  14. GridElement grid;
  15. ButtonElement addButton;
  16. ButtonElement removeButton;
  17. @Before
  18. public void init() {
  19. openTestURL();
  20. grid = $(GridElement.class).first();
  21. addButton = $(ButtonElement.class).id("add");
  22. removeButton = $(ButtonElement.class).id("remove");
  23. }
  24. @Test
  25. public void recalculateAfterAddingAndRemovingWorks() throws IOException {
  26. assertEquals("CheckBox should be checked.", "checked",
  27. $(CheckBoxElement.class).first().getValue());
  28. int initialWidth = grid.getHeaderCell(0, 0).getSize().width;
  29. addButton.click();
  30. int newWidth = grid.getHeaderCell(0, 0).getSize().width;
  31. // ensure the column width has increased significantly
  32. assertThat(
  33. "Unexpected column width after adding a row and calling recalculate.",
  34. (double) newWidth, not(closeTo(initialWidth, 20)));
  35. removeButton.click();
  36. newWidth = grid.getHeaderCell(0, 0).getSize().width;
  37. // ensure the column width has decreased significantly (even if it might
  38. // not be exactly the original width)
  39. assertThat(
  40. "Unexpected column width after removing a row and calling recalculate.",
  41. (double) newWidth, closeTo(initialWidth, 2));
  42. }
  43. @Test
  44. public void addingWithoutRecalculateWorks() throws IOException {
  45. CheckBoxElement checkBox = $(CheckBoxElement.class).first();
  46. checkBox.click();
  47. assertEquals("CheckBox should not be checked.", "unchecked",
  48. checkBox.getValue());
  49. int initialWidth = grid.getHeaderCell(0, 0).getSize().width;
  50. addButton.click();
  51. int newWidth = grid.getHeaderCell(0, 0).getSize().width;
  52. // ensure the column width did not change significantly
  53. assertThat(
  54. "Unexpected column width after adding a row without calling recalculate.",
  55. (double) newWidth, closeTo(initialWidth, 2));
  56. }
  57. @Test
  58. public void removingWithoutRecalculateWorks() throws IOException {
  59. // add a row before unchecking
  60. addButton.click();
  61. CheckBoxElement checkBox = $(CheckBoxElement.class).first();
  62. checkBox.click();
  63. assertEquals("CheckBox should not be checked.", "unchecked",
  64. checkBox.getValue());
  65. int initialWidth = grid.getHeaderCell(0, 0).getSize().width;
  66. removeButton.click();
  67. int newWidth = grid.getHeaderCell(0, 0).getSize().width;
  68. // ensure the column width did not change significantly
  69. assertThat(
  70. "Unexpected column width after removing a row without calling recalculate.",
  71. (double) newWidth, closeTo(initialWidth, 2));
  72. }
  73. }