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.

GridLayoutExtraSpacingTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.gridlayout;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertTrue;
  19. import java.io.IOException;
  20. import org.junit.Test;
  21. import org.openqa.selenium.By;
  22. import org.openqa.selenium.WebElement;
  23. import com.vaadin.testbench.elements.CheckBoxElement;
  24. import com.vaadin.testbench.elements.CssLayoutElement;
  25. import com.vaadin.testbench.elements.GridLayoutElement;
  26. import com.vaadin.testbench.parallel.BrowserUtil;
  27. import com.vaadin.tests.tb3.MultiBrowserTest;
  28. public class GridLayoutExtraSpacingTest extends MultiBrowserTest {
  29. @Test
  30. public void componentRowFour() throws IOException, Exception {
  31. openTestURL();
  32. CssLayoutElement component = $(CssLayoutElement.class).first();
  33. GridLayoutElement gridLayout = $(GridLayoutElement.class).first();
  34. // Spacing on, not hiding empty rows/columns
  35. // There should be 3 * 6px spacing (red) above the csslayout
  36. verifySpacingAbove(3 * 6, gridLayout, component);
  37. CheckBoxElement spacingCheckbox = $(CheckBoxElement.class)
  38. .caption("spacing").first();
  39. check(spacingCheckbox);
  40. // Spacing off, not hiding empty rows/columns
  41. // There should not be any spacing (red) above the csslayout
  42. verifySpacingAbove(0, gridLayout, component);
  43. verifySpacingBelow(0, gridLayout, component);
  44. CheckBoxElement hideRowsColumnsCheckbox = $(CheckBoxElement.class)
  45. .caption("hide empty rows/columns").first();
  46. check(hideRowsColumnsCheckbox);
  47. // Spacing off, hiding empty rows/columns
  48. // There should not be any spacing (red) above the csslayout
  49. verifySpacingAbove(0, gridLayout, component);
  50. verifySpacingBelow(0, gridLayout, component);
  51. check(spacingCheckbox);
  52. // Spacing on, hiding empty rows/columns
  53. // There should not be any spacing (red) above or below the csslayout
  54. verifySpacingAbove(0, gridLayout, component);
  55. verifySpacingBelow(0, gridLayout, component);
  56. }
  57. /**
  58. * workaround for http://dev.vaadin.com/ticket/13763
  59. */
  60. private void check(CheckBoxElement checkbox) {
  61. WebElement cb = checkbox.findElement(By.xpath("input"));
  62. if (BrowserUtil.isChrome(getDesiredCapabilities())) {
  63. testBenchElement(cb).click(0, 0);
  64. } else {
  65. cb.click();
  66. }
  67. }
  68. private void verifySpacingAbove(int spacing, GridLayoutElement gridLayout,
  69. CssLayoutElement component) {
  70. assertHeight(component, 500 - spacing, 1);
  71. int offset = component.getLocation().getY()
  72. - gridLayout.getLocation().getY();
  73. assertEquals(spacing, offset);
  74. }
  75. private void verifySpacingBelow(int spacing, GridLayoutElement gridLayout,
  76. CssLayoutElement component) {
  77. assertHeight(component, 500 - spacing, 1);
  78. int offset = component.getLocation().getY()
  79. - gridLayout.getLocation().getY();
  80. assertEquals(0, offset);
  81. }
  82. private void assertHeight(WebElement component, int height, int tolerance) {
  83. assertTrue(Math
  84. .abs(height - component.getSize().getHeight()) <= tolerance);
  85. }
  86. }