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.

AbstractGridColumnAutoWidthTest.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.vaadin.tests.components.grid;
  2. import static org.junit.Assert.assertEquals;
  3. import java.io.IOException;
  4. import java.util.regex.Pattern;
  5. import org.junit.Before;
  6. import org.junit.Test;
  7. import org.openqa.selenium.By;
  8. import org.openqa.selenium.WebElement;
  9. import com.vaadin.testbench.parallel.BrowserUtil;
  10. import com.vaadin.testbench.parallel.TestCategory;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. @SuppressWarnings("boxing")
  13. @TestCategory("grid")
  14. public abstract class AbstractGridColumnAutoWidthTest extends MultiBrowserTest {
  15. public static final int TOTAL_MARGIN_PX = 26;
  16. private static final int tolerance = 10;
  17. @Before
  18. public void before() {
  19. openTestURL();
  20. }
  21. @Test
  22. public void testNarrowHeaderWideBody() {
  23. WebElement[] col = getColumn(1);
  24. int headerWidth = col[0].getSize().getWidth();
  25. int bodyWidth = col[1].getSize().getWidth();
  26. int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
  27. assertLessThan("header should've been narrower than body", headerWidth,
  28. bodyWidth);
  29. assertEquals("column should've been roughly as wide as the body",
  30. bodyWidth, colWidth, tolerance);
  31. }
  32. @Test
  33. public void testWideHeaderNarrowBody() {
  34. WebElement[] col = getColumn(2);
  35. int headerWidth = col[0].getSize().getWidth();
  36. int bodyWidth = col[1].getSize().getWidth();
  37. int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
  38. assertGreater("header should've been wider than body", headerWidth,
  39. bodyWidth);
  40. assertEquals("column should've been roughly as wide as the header",
  41. headerWidth, colWidth, tolerance);
  42. }
  43. @Test
  44. public void testTooNarrowColumn() {
  45. if (BrowserUtil.isIE(getDesiredCapabilities())) {
  46. // IE can't deal with overflow nicely.
  47. return;
  48. }
  49. WebElement[] col = getColumn(3);
  50. int headerWidth = col[0].getSize().getWidth();
  51. int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
  52. assertLessThan("column should've been narrower than content", colWidth,
  53. headerWidth);
  54. }
  55. @Test
  56. public void testTooWideColumn() {
  57. WebElement[] col = getColumn(4);
  58. int headerWidth = col[0].getSize().getWidth();
  59. int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX;
  60. assertGreater("column should've been wider than content", colWidth,
  61. headerWidth);
  62. }
  63. @Test
  64. public void testColumnsRenderCorrectly() throws IOException {
  65. WebElement loadingIndicator = findElement(
  66. By.className("v-loading-indicator"));
  67. Pattern pattern = Pattern.compile("display: *none;");
  68. waitUntil(driver -> pattern
  69. .matcher(loadingIndicator.getAttribute("style")).find());
  70. compareScreen("grid-v8-initialRender");
  71. }
  72. private WebElement[] getColumn(int i) {
  73. WebElement[] col = new WebElement[3];
  74. col[0] = getDriver().findElement(
  75. By.xpath("//thead//th[" + (i + 1) + "]/div[1]/span"));
  76. col[1] = getDriver()
  77. .findElement(By.xpath("//tbody//td[" + (i + 1) + "]//span"));
  78. col[2] = getDriver()
  79. .findElement(By.xpath("//tbody//td[" + (i + 1) + "]"));
  80. return col;
  81. }
  82. }