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.

GridColumnsNoMinimumWidthFromContentTest.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.assertEquals;
  5. import org.junit.Test;
  6. import org.openqa.selenium.Dimension;
  7. import org.openqa.selenium.WebElement;
  8. import com.vaadin.testbench.By;
  9. import com.vaadin.testbench.elements.GridElement;
  10. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. public class GridColumnsNoMinimumWidthFromContentTest extends MultiBrowserTest {
  13. @Test
  14. public void testResizing() {
  15. openTestURL();
  16. GridElement grid = $(GridElement.class).first();
  17. WebElement hScrollbar = grid
  18. .findElement(By.className("v-grid-scroller-horizontal"));
  19. // initial state, should have no scrollbar
  20. GridCellElement lastColumn = grid.getHeaderCell(0, 19);
  21. ensureScrollbarVisibility(hScrollbar, false);
  22. ensureNoGap(grid, lastColumn);
  23. // resize small enough to get a scrollbar
  24. getDriver().manage().window().setSize(new Dimension(810, 800));
  25. ensureScrollbarVisibility(hScrollbar, true);
  26. // resize just enough to lose the scrollbar
  27. getDriver().manage().window().setSize(new Dimension(840, 800));
  28. ensureScrollbarVisibility(hScrollbar, false);
  29. ensureNoGap(grid, lastColumn);
  30. int lastColumnWidth = lastColumn.getSize().getWidth();
  31. assertGreater("Unexpected last column width: " + lastColumnWidth
  32. + " (should be over 30)", lastColumnWidth, 30);
  33. }
  34. private void ensureNoGap(GridElement grid, GridCellElement lastColumn) {
  35. int gridRightEdge = grid.getLocation().getX()
  36. + grid.getSize().getWidth();
  37. int lastColumnRightEdge = lastColumn.getLocation().getX()
  38. + lastColumn.getSize().getWidth();
  39. assertThat("Unexpected positioning.", (double) gridRightEdge,
  40. closeTo(lastColumnRightEdge, 1d));
  41. }
  42. private void ensureScrollbarVisibility(WebElement scrollbar,
  43. boolean displayed) {
  44. assertEquals(displayed ? "block" : "none",
  45. scrollbar.getCssValue("display"));
  46. }
  47. }