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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 column 'Last Name' visible
  43. WebElement menuButton = grid.findElement(By.className("v-contextmenu"))
  44. .findElement(By.tagName("button"));
  45. action.click(menuButton).perform(); // Click on menu button
  46. WebElement sidebarPopup = findElement(
  47. By.className("v-grid-sidebar-popup"));
  48. WebElement visibilityToggle = findElementByText("Last Name",
  49. sidebarPopup.findElements(By.className("gwt-MenuItem")));
  50. // Click on "Last Name" menu item
  51. action.click(visibilityToggle).perform();
  52. waitUntilLoadingIndicatorNotVisible();
  53. // Check if column "Last Name" is visible
  54. headerCells = grid.getHeaderCells(0);
  55. assertEquals("There should be three visible columns", 3,
  56. headerCells.size());
  57. assertTrue("'Last Name' column should be visible",
  58. containsText("Last Name", headerCells));
  59. // Check if column "Last Name" has expanded width
  60. int widthSum = 0;
  61. for (GridCellElement e : headerCells) {
  62. widthSum += e.getSize().getWidth();
  63. }
  64. assertEquals("'Last Name' column should take up the remaining space",
  65. grid.getHeader().getSize().getWidth(), widthSum, 1d);
  66. }
  67. private WebElement findElementByText(String text,
  68. List<? extends WebElement> elements) {
  69. for (WebElement e : elements) {
  70. if (text.equalsIgnoreCase(e.getText())) {
  71. return e;
  72. }
  73. }
  74. return null;
  75. }
  76. private boolean containsText(String text,
  77. List<? extends WebElement> elements) {
  78. return !(findElementByText(text, elements) == null);
  79. }
  80. private void dragResizeColumn(GridCellElement headerCell, int posX,
  81. int offset) {
  82. Dimension size = headerCell.getSize();
  83. new Actions(getDriver())
  84. .moveToElement(headerCell,
  85. getXOffset(headerCell, size.getWidth() + posX),
  86. getYOffset(headerCell, size.getHeight() / 2))
  87. .clickAndHold().moveByOffset(offset, 0).release().perform();
  88. waitUntilLoadingIndicatorNotVisible();
  89. }
  90. }