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.

GridDetailsLayoutExpandTest.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.vaadin.tests.components.grid;
  2. import static org.hamcrest.MatcherAssert.assertThat;
  3. import static org.hamcrest.number.IsCloseTo.closeTo;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import com.vaadin.testbench.elements.GridElement;
  7. import com.vaadin.testbench.elements.LabelElement;
  8. import com.vaadin.testbench.parallel.TestCategory;
  9. import com.vaadin.tests.tb3.MultiBrowserTest;
  10. /**
  11. * Tests the layouting of Grid's details row when it contains a HorizontalLayout
  12. * with expand ratios.
  13. *
  14. * @author Vaadin Ltd
  15. */
  16. @TestCategory("grid")
  17. public class GridDetailsLayoutExpandTest extends MultiBrowserTest {
  18. @Test
  19. public void testLabelWidths() {
  20. openTestURL();
  21. waitForElementPresent(By.className("v-grid"));
  22. GridElement grid = $(GridElement.class).first();
  23. int gridWidth = grid.getSize().width;
  24. grid.getRow(2).click();
  25. waitForElementPresent(By.id("lbl2"));
  26. // space left over from first label should be divided equally
  27. double expectedWidth = (double) (gridWidth - 200) / 2;
  28. assertLabelWidth("lbl2", expectedWidth);
  29. assertLabelWidth("lbl3", expectedWidth);
  30. }
  31. private void assertLabelWidth(String id, double expectedWidth) {
  32. // 1px leeway for calculations
  33. assertThat("Unexpected label width.",
  34. (double) $(LabelElement.class).id(id).getSize().width,
  35. closeTo(expectedWidth, 1d));
  36. }
  37. }