]> source.dussan.org Git - vaadin-framework.git/commitdiff
Initialize VRichTextArea.client in RichTextAreaConnector
authorMarco Collovati <mcollovati@gmail.com>
Mon, 19 Mar 2018 16:44:59 +0000 (17:44 +0100)
committerIlia Motornyi <elmot@vaadin.com>
Mon, 19 Mar 2018 16:44:59 +0000 (18:44 +0200)
Fixes #10536

client/src/main/java/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java
uitest/src/main/java/com/vaadin/tests/components/richtextarea/RichTextAreaDelegateToShortcutHandler.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/richtextarea/RichTextAreaDelegateToShortcutHandlerTest.java [new file with mode: 0644]

index 77a69874fbdb3f83c754dfd91c68039b8fd6a547..9c9d1c70f3484c963424a088cf3cefcc041ed23d 100644 (file)
@@ -46,6 +46,7 @@ public class RichTextAreaConnector extends AbstractFieldConnector
 
     @Override
     protected void init() {
+        getWidget().client = getConnection();
         getWidget().addBlurHandler(event -> flush());
         getWidget().addInputHandler(
                 () -> valueChangeHandler.scheduleValueChange());
diff --git a/uitest/src/main/java/com/vaadin/tests/components/richtextarea/RichTextAreaDelegateToShortcutHandler.java b/uitest/src/main/java/com/vaadin/tests/components/richtextarea/RichTextAreaDelegateToShortcutHandler.java
new file mode 100644 (file)
index 0000000..ead2ebc
--- /dev/null
@@ -0,0 +1,25 @@
+package com.vaadin.tests.components.richtextarea;
+
+import com.vaadin.event.ShortcutAction;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.RichTextArea;
+import com.vaadin.ui.VerticalLayout;
+
+public class RichTextAreaDelegateToShortcutHandler extends AbstractTestUIWithLog {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final VerticalLayout layout = new VerticalLayout();
+        final RichTextArea name = new RichTextArea();
+        name.setCaption("Type your name here:");
+
+        Button button = new Button("Click Me");
+        button.setClickShortcut(ShortcutAction.KeyCode.ENTER);
+        button.addClickListener(e -> log("ShortcutHandler invoked " + name.getValue()));
+
+        layout.addComponents(name, button);
+        addComponent(layout);
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/richtextarea/RichTextAreaDelegateToShortcutHandlerTest.java b/uitest/src/test/java/com/vaadin/tests/components/richtextarea/RichTextAreaDelegateToShortcutHandlerTest.java
new file mode 100644 (file)
index 0000000..0fc2c63
--- /dev/null
@@ -0,0 +1,40 @@
+package com.vaadin.tests.components.richtextarea;
+
+import java.util.List;
+
+import com.vaadin.testbench.elements.RichTextAreaElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+
+public class RichTextAreaDelegateToShortcutHandlerTest extends MultiBrowserTest {
+
+    @Override
+    public List<DesiredCapabilities> getBrowsersToTest() {
+        return getBrowsersExcludingPhantomJS();
+    }
+
+    @Test
+    public void shouldDelegateToShortcutActionHandler() {
+        openTestURL();
+
+        WebElement textAreaEditor = $(RichTextAreaElement.class).first().getEditorIframe();
+        textAreaEditor.sendKeys("Test");
+        textAreaEditor.sendKeys(Keys.ENTER);
+
+        assertThat("Shortcut handler has not been invoked",
+            getLogRow(0), containsString("ShortcutHandler invoked Test"));
+
+        textAreaEditor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER));
+        textAreaEditor.sendKeys("another row");
+        textAreaEditor.sendKeys(Keys.ENTER);
+
+        assertThat("Shortcut handler has not been invoked",
+            getLogRow(0), containsString("ShortcutHandler invoked Test\nanother row"));
+    }
+}