diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2016-12-14 15:36:14 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2016-12-14 15:36:14 +0200 |
commit | afcd95da1dba4abfd6158f38ab0a95755e2623e4 (patch) | |
tree | 9be6dfe6f1ea576e17171c573ffdf34310e2301d /uitest | |
parent | ce26bf7c4ce2d3f4a40904d103cb85bdd8fb17c6 (diff) | |
download | vaadin-framework-afcd95da1dba4abfd6158f38ab0a95755e2623e4.tar.gz vaadin-framework-afcd95da1dba4abfd6158f38ab0a95755e2623e4.zip |
Make AbstractListing implement Focusable (#7965)
* Make AbstractListing implement Focusable
Fixes vaadin/framework8-issues#552
* Add tests for other components that inherit from AbstractListing
* Fix setTabIndex in NativeSelect, ListSelect, RadioButtonGroup
Also adds a test for TwinColSelect.
Diffstat (limited to 'uitest')
8 files changed, 175 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java index a72a055e59..2d0c893ddf 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java @@ -438,6 +438,12 @@ public class GridBasics extends AbstractTestUIWithLog { enableItem.setChecked(true); createSelectionMenu(stateMenu); + + stateMenu.addItem("Set focus", item -> grid.focus()); + MenuItem tabIndexMenu = stateMenu.addItem("Tab index", null); + addGridMethodMenu(tabIndexMenu, "0", 0, grid::setTabIndex); + addGridMethodMenu(tabIndexMenu, "-1", -1, grid::setTabIndex); + addGridMethodMenu(tabIndexMenu, "10", 10, grid::setTabIndex); } private void createRowStyleMenu(MenuItem rowStyleMenu) { diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/AbstractFocusableComponentTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/AbstractFocusableComponentTest.java new file mode 100644 index 0000000000..61d22ae647 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/AbstractFocusableComponentTest.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.focusable; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public abstract class AbstractFocusableComponentTest extends MultiBrowserTest { + + @Before + public void setUp() { + openTestURL(); + } + + @Test + public void testProgrammaticFocus() { + selectMenuPath("Component", "State", "Set focus"); + assertTrue("Component should be focused", isFocused()); + } + + @Test + public void testTabIndex() { + assertEquals("0", getTabIndex()); + + selectMenuPath("Component", "State", "Tab index", "-1"); + assertEquals("-1", getTabIndex()); + + selectMenuPath("Component", "State", "Tab index", "10"); + assertEquals("10", getTabIndex()); + } + + protected String getTabIndex() { + return getFocusElement().getAttribute("tabindex"); + } + + protected boolean isFocused() { + return getFocusElement().equals(getDriver().switchTo().activeElement()); + } + + protected abstract WebElement getFocusElement(); +} diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/CheckBoxGroupFocusableTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/CheckBoxGroupFocusableTest.java new file mode 100644 index 0000000000..a99b3be9fe --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/CheckBoxGroupFocusableTest.java @@ -0,0 +1,19 @@ +package com.vaadin.tests.focusable; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.components.checkbox.CheckBoxGroupTestUI; + +public class CheckBoxGroupFocusableTest extends AbstractFocusableComponentTest { + + @Override + protected Class<?> getUIClass() { + return CheckBoxGroupTestUI.class; + } + + @Override + protected WebElement getFocusElement() { + return findElement(By.xpath("//input[@type='checkbox']")); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/GridFocusableTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/GridFocusableTest.java new file mode 100644 index 0000000000..96a19902eb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/GridFocusableTest.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.focusable; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.components.grid.basics.GridBasics; + +public class GridFocusableTest extends AbstractFocusableComponentTest { + + @Override + protected Class<?> getUIClass() { + return GridBasics.class; + } + + @Override + protected String getTabIndex() { + return $(GridElement.class).first().getAttribute("tabindex"); + } + + @Override + protected boolean isFocused() { + return getFocusElement().isFocused(); + } + + @Override + protected GridCellElement getFocusElement() { + return $(GridElement.class).first().getCell(0, 0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/ListSelectFocusableTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/ListSelectFocusableTest.java new file mode 100644 index 0000000000..5a4fc4f870 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/ListSelectFocusableTest.java @@ -0,0 +1,19 @@ +package com.vaadin.tests.focusable; + +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.components.listselect.ListSelectTestUI; + +public class ListSelectFocusableTest extends AbstractFocusableComponentTest { + + @Override + protected Class<?> getUIClass() { + return ListSelectTestUI.class; + } + + @Override + protected WebElement getFocusElement() { + return findElement(By.className("v-select-select")); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/NativeSelectFocusableTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/NativeSelectFocusableTest.java new file mode 100644 index 0000000000..530972b8a6 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/NativeSelectFocusableTest.java @@ -0,0 +1,19 @@ +package com.vaadin.tests.focusable; + +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.components.nativeselect.NativeSelects; + +public class NativeSelectFocusableTest extends AbstractFocusableComponentTest { + + @Override + protected Class<?> getUIClass() { + return NativeSelects.class; + } + + @Override + protected WebElement getFocusElement() { + return findElement(By.className("v-select-select")); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/RadioButtonGroupFocusableTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/RadioButtonGroupFocusableTest.java new file mode 100644 index 0000000000..c84d606ac3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/RadioButtonGroupFocusableTest.java @@ -0,0 +1,19 @@ +package com.vaadin.tests.focusable; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.components.radiobutton.RadioButtonGroupTestUI; + +public class RadioButtonGroupFocusableTest extends AbstractFocusableComponentTest { + + @Override + protected Class<?> getUIClass() { + return RadioButtonGroupTestUI.class; + } + + @Override + protected WebElement getFocusElement() { + return findElement(By.xpath("//input[@type='radio']")); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/focusable/TwinColSelectFocusableTest.java b/uitest/src/test/java/com/vaadin/tests/focusable/TwinColSelectFocusableTest.java new file mode 100644 index 0000000000..826647129a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/focusable/TwinColSelectFocusableTest.java @@ -0,0 +1,20 @@ +package com.vaadin.tests.focusable; + +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.components.twincolselect.TwinColSelectTestUI; + +public class TwinColSelectFocusableTest + extends AbstractFocusableComponentTest { + + @Override + protected Class<?> getUIClass() { + return TwinColSelectTestUI.class; + } + + @Override + protected WebElement getFocusElement() { + return findElement(By.className("v-select-twincol-options")); + } +} |