diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-10-26 16:22:00 +0300 |
---|---|---|
committer | Denis Anisimov <denis@vaadin.com> | 2016-10-31 14:53:57 +0200 |
commit | 25013128a7e2eb80b565d28abcc0af26219098db (patch) | |
tree | 5995aebdf009bae579caf37845d5f8018bffdd98 /uitest | |
parent | c276c9d02ef96162d4076045ba56ed342375f4ed (diff) | |
download | vaadin-framework-25013128a7e2eb80b565d28abcc0af26219098db.tar.gz vaadin-framework-25013128a7e2eb80b565d28abcc0af26219098db.zip |
Implement focus/blur listeners for NativeSelect.
Fixes vaadin/framework8-issues#332
Change-Id: I19996ea83ed1fbe2b115d92d6be5e6a5e158f283
Diffstat (limited to 'uitest')
2 files changed, 105 insertions, 0 deletions
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 new file mode 100644 index 0000000000..b665e52fcb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlur.java @@ -0,0 +1,42 @@ +/* + * 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.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.ui.NativeSelect; + +/** + * @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")); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlurTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlurTest.java new file mode 100644 index 0000000000..7b21465632 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectFocusBlurTest.java @@ -0,0 +1,63 @@ +/* + * 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.nativeselect; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.customelements.NativeSelectElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * @author Vaadin Ltd + * + */ +public class NativeSelectFocusBlurTest extends MultiBrowserTest { + + @Test + public void focusBlurEvents() { + openTestURL(); + + NativeSelectElement nativeSelect = $(NativeSelectElement.class).first(); + nativeSelect.click(); + + // Focus event is fired + Assert.assertTrue(logContainsText("1. Focus Event")); + + List<TestBenchElement> options = nativeSelect.getOptions(); + options.get(1).click(); + // No any new event + Assert.assertFalse(logContainsText("2.")); + + // click on log label => blur + $(LabelElement.class).first().click(); + // blur event is fired + Assert.assertTrue(logContainsText("2. Blur Event")); + + nativeSelect.click(); + // Focus event is fired + Assert.assertTrue(logContainsText("3. Focus Event")); + + options.get(1).sendKeys(Keys.ARROW_UP, Keys.ENTER); + // No any new event + Assert.assertFalse(logContainsText("4.")); + } +} |