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.

GridResizeHiddenColumnTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package com.vaadin.tests.components.grid;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertFalse;
  4. import static org.junit.Assert.assertTrue;
  5. import java.util.List;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.Dimension;
  10. import org.openqa.selenium.WebElement;
  11. import org.openqa.selenium.interactions.Actions;
  12. import com.vaadin.testbench.elements.GridElement;
  13. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  14. import com.vaadin.testbench.parallel.BrowserUtil;
  15. import com.vaadin.tests.tb3.MultiBrowserTest;
  16. public class GridResizeHiddenColumnTest extends MultiBrowserTest {
  17. @Before
  18. public void before() {
  19. openTestURL();
  20. }
  21. @Test
  22. public void testDragResizeHiddenColumnSize() {
  23. GridElement grid = $(GridElement.class).first();
  24. Actions action = new Actions(getDriver());
  25. // Check if column 'Last Name' hidden
  26. List<GridCellElement> headerCells = grid.getHeaderCells(0);
  27. assertEquals("There should be two visible columns", 2,
  28. headerCells.size());
  29. assertFalse("'Last Name' column should be hidden",
  30. containsText("Last Name", headerCells));
  31. // Resize first column
  32. int dragOffset = -100;
  33. int headerCellWidth = headerCells.get(0).getSize().getWidth();
  34. dragResizeColumn(headerCells.get(0), 1, dragOffset);
  35. // When dragging the resizer on IE8, the final offset will be smaller
  36. // (might be an issue with the feature that doesn't start resizing until
  37. // the cursor moved a few pixels)
  38. double delta = BrowserUtil.isIE8(getDesiredCapabilities()) ? 5d : 0;
  39. assertEquals("Column width should've changed by " + dragOffset + "px",
  40. headerCellWidth + dragOffset,
  41. headerCells.get(0).getSize().getWidth(), delta);
  42. // make absolutely certain the mouse isn't pressed anymore before moving
  43. // to the context menu
  44. new Actions(getDriver()).release().perform();
  45. // Make column 'Last Name' visible
  46. WebElement menuButton = grid.findElement(By.className("v-contextmenu"))
  47. .findElement(By.tagName("button"));
  48. action.click(menuButton).perform(); // Click on menu button
  49. WebElement sidebarPopup = findElement(
  50. By.className("v-grid-sidebar-popup"));
  51. WebElement visibilityToggle = findElementByText("Last Name",
  52. sidebarPopup.findElements(By.className("gwt-MenuItem")));
  53. // Click on "Last Name" menu item
  54. action.click(visibilityToggle).perform();
  55. waitUntilLoadingIndicatorNotVisible();
  56. sleep(200); // wait for layouting
  57. // Check if column "Last Name" is visible
  58. headerCells = grid.getHeaderCells(0);
  59. assertEquals("There should be three visible columns", 3,
  60. headerCells.size());
  61. assertTrue("'Last Name' column should be visible",
  62. containsText("Last Name", headerCells));
  63. // Check if column "Last Name" has expanded width
  64. int widthSum = 0;
  65. for (GridCellElement e : headerCells) {
  66. widthSum += e.getSize().getWidth();
  67. }
  68. assertEquals("'Last Name' column should take up the remaining space",
  69. grid.getHeader().getSize().getWidth(), widthSum, 1d);
  70. }
  71. private WebElement findElementByText(String text,
  72. List<? extends WebElement> elements) {
  73. for (WebElement e : elements) {
  74. if (text.equalsIgnoreCase(e.getText())) {
  75. return e;
  76. }
  77. }
  78. return null;
  79. }
  80. private boolean containsText(String text,
  81. List<? extends WebElement> elements) {
  82. return !(findElementByText(text, elements) == null);
  83. }
  84. private void dragResizeColumn(GridCellElement headerCell, int posX,
  85. int offset) {
  86. Dimension size = headerCell.getSize();
  87. new Actions(getDriver())
  88. .moveToElement(headerCell,
  89. getXOffset(headerCell, size.getWidth() + posX),
  90. getYOffset(headerCell, size.getHeight() / 2))
  91. .clickAndHold().moveByOffset(offset, 0).release().perform();
  92. waitUntilLoadingIndicatorNotVisible();
  93. }
  94. }