summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-10-30 18:11:21 +0200
committerVaadin Code Review <review@vaadin.com>2016-10-31 14:45:13 +0000
commit287614dbabc4ec8f2e72f56067312ad47ce46f5d (patch)
tree2f4811c2de5dd2aa4cf10b3a50b6ac484764f866 /uitest
parentee47a94e17aadae18fbee6ad804e35ab12446df5 (diff)
downloadvaadin-framework-287614dbabc4ec8f2e72f56067312ad47ce46f5d.tar.gz
vaadin-framework-287614dbabc4ec8f2e72f56067312ad47ce46f5d.zip
Implement focus/blur events for RadioButtonGroup.
Fixes vaadin/framework8-issues#333 Change-Id: I55f5d6a0cd690f2c0b5e757318a5f528a67ef34e
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java68
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java25
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java26
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java34
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlurTest.java86
5 files changed, 206 insertions, 33 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java b/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java
new file mode 100644
index 0000000000..0b94b8fecb
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/AbstractListingFocusBlurTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.googlecode.gentyref.GenericTypeReflector;
+import com.vaadin.event.FieldEvents.BlurNotifier;
+import com.vaadin.event.FieldEvents.FocusNotifier;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.data.selection.SelectionModel;
+import com.vaadin.ui.AbstractListing;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Integer, S> & FocusNotifier & BlurNotifier, S extends SelectionModel<Integer>>
+ extends AbstractTestUIWithLog {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setup(VaadinRequest request) {
+ Type valueType = GenericTypeReflector.getTypeParameter(getClass(),
+ AbstractListingFocusBlurTest.class.getTypeParameters()[0]);
+ if (valueType instanceof ParameterizedType) {
+ valueType = ((ParameterizedType) valueType).getRawType();
+ }
+ if (valueType instanceof Class<?>) {
+ Class<?> clazz = (Class<?>) valueType;
+ try {
+ AbstractListing<Integer, ?> select = (AbstractListing<Integer, ?>) clazz
+ .newInstance();
+ select.setItems(
+ IntStream.range(1, 10).mapToObj(Integer::valueOf)
+ .collect(Collectors.toList()));
+
+ addComponent(select);
+ ((FocusNotifier) select)
+ .addFocusListener(event -> log("Focus Event"));
+ ((BlurNotifier) select)
+ .addBlurListener(event -> log("Blur Event"));
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ throw new RuntimeException(
+ "Unexpected component type " + valueType.getTypeName());
+ }
+ }
+
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java
index 2b43a8134e..92efed09e7 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlur.java
@@ -15,27 +15,20 @@
*/
package com.vaadin.tests.components.checkboxgroup;
-import java.util.stream.IntStream;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.shared.data.selection.SelectionModel.Multi;
+import com.vaadin.tests.components.AbstractListingFocusBlurTest;
import com.vaadin.ui.CheckBoxGroup;
/**
+ * This class only provides a component type. The initialization code is inside
+ * the AbstractListingFocusBlurTest class.
+ *
+ * @see AbstractListingFocusBlurTest
+ *
* @author Vaadin Ltd
*
*/
-public class CheckBoxGroupFocusBlur extends AbstractTestUIWithLog {
-
- @Override
- protected void setup(VaadinRequest request) {
- CheckBoxGroup<Integer> group = new CheckBoxGroup<>();
- group.setItems(IntStream.range(1, 10).mapToObj(Integer::valueOf)
- .toArray(Integer[]::new));
- addComponent(group);
-
- group.addFocusListener(event -> log("Focus Event"));
- group.addBlurListener(event -> log("Blur Event"));
- }
+public class CheckBoxGroupFocusBlur extends
+ AbstractListingFocusBlurTest<CheckBoxGroup<Integer>, Multi<Integer>> {
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java
index b665e52fcb..b2664f892b 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java
@@ -15,28 +15,20 @@
*/
package com.vaadin.tests.components.nativeselect;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.components.AbstractListingFocusBlurTest;
+import com.vaadin.ui.AbstractSingleSelect;
import com.vaadin.ui.NativeSelect;
/**
+ * This class only provides a component type. The initialization code is inside
+ * the AbstractListingFocusBlurTest class.
+ *
+ * @see AbstractListingFocusBlurTest
+ *
* @author Vaadin Ltd
*
*/
-public class NativeSelectFocusBlur extends AbstractTestUIWithLog {
-
- @Override
- protected void setup(VaadinRequest request) {
- NativeSelect<Integer> select = new NativeSelect<>();
- select.setItems(IntStream.range(1, 10).mapToObj(Integer::valueOf)
- .collect(Collectors.toList()));
-
- addComponent(select);
- select.addFocusListener(event -> log("Focus Event"));
- select.addBlurListener(event -> log("Blur Event"));
- }
+public class NativeSelectFocusBlur extends
+ AbstractListingFocusBlurTest<NativeSelect<Integer>, AbstractSingleSelect<Integer>.AbstractSingleSelection> {
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java
new file mode 100644
index 0000000000..02238e5ef4
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlur.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.radiobuttongroup;
+
+import com.vaadin.tests.components.AbstractListingFocusBlurTest;
+import com.vaadin.ui.AbstractSingleSelect;
+import com.vaadin.ui.RadioButtonGroup;
+
+/**
+ * This class only provides a component type. The initialization code is inside
+ * the AbstractListingFocusBlurTest class.
+ *
+ * @see AbstractListingFocusBlurTest
+ *
+ * @author Vaadin Ltd
+ *
+ */
+public class RadioButtonGroupFocusBlur extends
+ AbstractListingFocusBlurTest<RadioButtonGroup<Integer>, AbstractSingleSelect<Integer>.AbstractSingleSelection> {
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlurTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlurTest.java
new file mode 100644
index 0000000000..77fde84f54
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupFocusBlurTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.radiobuttongroup;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.customelements.RadioButtonGroupElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class RadioButtonGroupFocusBlurTest extends MultiBrowserTest {
+
+ @Test
+ public void focusBlurEvents() {
+ openTestURL();
+
+ List<WebElement> radioButtons = $(RadioButtonGroupElement.class).first()
+ .findElements(By.tagName("input"));
+ radioButtons.get(0).click();
+
+ // Focus event is fired
+ Assert.assertTrue(logContainsText("1. Focus Event"));
+
+ radioButtons.get(1).click();
+ // click on the second radio button doesn't fire anything
+ Assert.assertFalse(logContainsText("2."));
+
+ // click in the middle between the first and the second (inside group).
+ WebElement first = radioButtons.get(0);
+ int middle = (first.getLocation().y + first.getSize().height
+ + radioButtons.get(1).getLocation().y) / 2;
+ new Actions(getDriver()).moveByOffset(first.getLocation().x, middle)
+ .click().build().perform();
+ // no new events
+ Assert.assertFalse(logContainsText("2."));
+
+ // click to label of a radio button
+ $(RadioButtonGroupElement.class).first()
+ .findElements(By.tagName("label")).get(2).click();
+ // no new events
+ Assert.assertFalse(logContainsText("2."));
+
+ // click on log label => blur
+ $(LabelElement.class).first().click();
+ // blur event is fired
+ Assert.assertTrue(logContainsText("2. Blur Event"));
+
+ radioButtons.get(3).click();
+ // Focus event is fired
+ Assert.assertTrue(logContainsText("3. Focus Event"));
+
+ // move keyboard focus to the next radio button
+ radioButtons.get(3).sendKeys(Keys.ARROW_DOWN);
+ // no new events
+ Assert.assertFalse(logContainsText("4."));
+
+ // select the next radio button
+ radioButtons.get(4).sendKeys(Keys.TAB);
+ // focus has gone away
+ waitUntil(driver -> logContainsText("4. Blur Event"), 5);
+ }
+}