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.

ResponsiveStylesTest.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.themes.valo;
  17. import static org.hamcrest.MatcherAssert.assertThat;
  18. import static org.hamcrest.Matchers.equalTo;
  19. import java.util.List;
  20. import org.junit.Test;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.interactions.Actions;
  23. import com.vaadin.tests.tb3.MultiBrowserTest;
  24. /**
  25. * Test for the built-in reponsive ("RWD") styles in Valo.
  26. */
  27. public class ResponsiveStylesTest extends MultiBrowserTest {
  28. /**
  29. * Use this parameter to test the collapsed menu state.
  30. */
  31. public static final String COLLAPSED_MENU_TEST_PARAM = "collapsed";
  32. private static final String MENU_STYLENAME = "valo-menu";
  33. private static final int NARROW_ELEMENT_INDEX = 0;
  34. private static final int NARROW_WIDTH = 112;
  35. private static final int WIDE_ELEMENT_INDEX = 1;
  36. private static final int WIDE_WIDTH = 146;
  37. private static final String TOGGLE_STYLENAME = "valo-menu-toggle";
  38. /**
  39. * Tests that valo-menu-responsive can be used in any element on the page,
  40. * not just as top-level component.
  41. *
  42. * @throws Exception
  43. */
  44. @Test
  45. public void testValoMenuResponsiveParentSize() throws Exception {
  46. openTestURL();
  47. List<WebElement> menus = findElements(
  48. com.vaadin.testbench.By.className(MENU_STYLENAME));
  49. WebElement narrowMenu = menus.get(NARROW_ELEMENT_INDEX);
  50. int narrowWidth = narrowMenu.getSize().width;
  51. assertThat(narrowWidth, equalTo(NARROW_WIDTH));
  52. WebElement wideMenu = menus.get(WIDE_ELEMENT_INDEX);
  53. int wideWidth = wideMenu.getSize().width;
  54. assertThat(wideWidth, equalTo(WIDE_WIDTH));
  55. compareScreen("defaultMenuWidths");
  56. }
  57. /**
  58. * Tests that the valo-menu-hover style makes the menu appear on mouseover.
  59. *
  60. * @throws Exception
  61. */
  62. @Test
  63. public void testValoMenuResponsiveHover() throws Exception {
  64. openTestURL(COLLAPSED_MENU_TEST_PARAM);
  65. compareScreen("collapsedMenu");
  66. List<WebElement> toggles = findElements(
  67. com.vaadin.testbench.By.className(TOGGLE_STYLENAME));
  68. // Only one menu in the collapsed example
  69. WebElement toggle = toggles.get(0);
  70. Actions actions = new Actions(getDriver());
  71. actions.moveToElement(toggle);
  72. actions.perform();
  73. compareScreen("expandedMenu");
  74. }
  75. }