From 242ee1c15a17bed92245a02fac944bddb425dc3e Mon Sep 17 00:00:00 2001 From: Sun Zhe <31067185+ZheSun88@users.noreply.github.com> Date: Fri, 26 Oct 2018 15:55:38 +0300 Subject: Refactor the usage of KeyMapper in ActionManager. (#11265) * Add Test for closing window with focused textfield verify issue #10642 * Refactor the code about using keyMapper --- .../window/CloseWindowWithFocusedTextField.java | 37 ++++++++++++++++++++++ .../CloseWindowWithFocusedTextFieldTest.java | 29 +++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextField.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextFieldTest.java (limited to 'uitest') diff --git a/uitest/src/main/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextField.java b/uitest/src/main/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextField.java new file mode 100644 index 0000000000..2c0b2e4acf --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextField.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.components.window; + +import com.vaadin.event.ShortcutAction; +import com.vaadin.event.ShortcutListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ValueChangeMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; + +public class CloseWindowWithFocusedTextField extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout layout = new VerticalLayout(); + + Button button1 = new Button("open window"); + button1.addClickListener(event -> { + + Window window = new Window(); + window.setModal(true); + + TextField textField = new TextField("focus me"); + textField.focus(); + + window.setContent(textField); + getUI().addWindow(window); + }); + + layout.addComponents(button1); + + addComponent(layout); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextFieldTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextFieldTest.java new file mode 100644 index 0000000000..898e15ce51 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/window/CloseWindowWithFocusedTextFieldTest.java @@ -0,0 +1,29 @@ +package com.vaadin.tests.components.window; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.annotations.RunLocally; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.MultiBrowserTest; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class CloseWindowWithFocusedTextFieldTest extends MultiBrowserTest { + + @Test + public void OpenWindow_CloseWithEscapeKey_WindowClosed() { + openTestURL(); + $(ButtonElement.class).first().click(); + assertTrue("Window should be opened", $(WindowElement.class).exists()); + + new Actions(getDriver()).sendKeys(Keys.ESCAPE).build().perform(); + assertFalse("Window found when there should be none.", + $(WindowElement.class).exists()); + } + +} -- cgit v1.2.3