From 4f5b89e1ce1127d32383144fe7f1c56420c0e312 Mon Sep 17 00:00:00 2001 From: Joni <45562391+ujoni@users.noreply.github.com> Date: Thu, 12 Sep 2019 14:39:36 +0300 Subject: [PATCH] It demonstrating #5480 (#6432) * Verify #5480 (cherry picked from commit aa915fbf8167df4bebca23823281fb2afbea4442) --- .../vaadin/flow/uitest/ui/ShortcutsView.java | 17 +++++++++++++++- .../vaadin/flow/uitest/ui/ShortcutsIT.java | 20 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ShortcutsView.java b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ShortcutsView.java index 35530ad3790..95cae663d8d 100644 --- a/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ShortcutsView.java +++ b/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ShortcutsView.java @@ -16,6 +16,8 @@ package com.vaadin.flow.uitest.ui; +import java.util.concurrent.atomic.AtomicReference; + import com.vaadin.flow.component.Key; import com.vaadin.flow.component.KeyModifier; import com.vaadin.flow.component.ShortcutRegistration; @@ -25,6 +27,7 @@ import com.vaadin.flow.component.html.Input; import com.vaadin.flow.component.html.NativeButton; import com.vaadin.flow.component.html.Paragraph; +import com.vaadin.flow.data.value.ValueChangeMode; import com.vaadin.flow.router.Route; import com.vaadin.flow.uitest.servlet.ViewTestLayout; @@ -112,7 +115,7 @@ public ShortcutsView() { actual.setValue("toggled!"); }, Key.KEY_Y, KeyModifier.ALT); - // modifyingShortcutShouldChangeShortcutEvent + // modifyingShortcutShouldChangeShortcutEvent flipFloppingRegistration = UI.getCurrent().addShortcutListener(event -> { if (event.getKeyModifiers().contains(KeyModifier.ALT)) { @@ -155,5 +158,17 @@ public ShortcutsView() { wrapper1.add(clickInput1, clickButton1); wrapper2.add(clickInput2, clickButton2); add(wrapper1, wrapper2); + + // removingShortcutCleansJavascriptEventSettingsItUsed + AtomicReference removalAtomicReference = new AtomicReference<>(); + final Input removalInput = new Input(ValueChangeMode.EAGER); + removalInput.setId("removal-input"); + ShortcutRegistration removalRegistration = Shortcuts + .addShortcutListener(removalInput, () -> { + removalInput.setValue(removalInput.getValue().toUpperCase()); + removalAtomicReference.get().remove(); + }, Key.KEY_D); + removalAtomicReference.set(removalRegistration); + add(removalInput); } } diff --git a/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/ShortcutsIT.java b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/ShortcutsIT.java index ecffab2ab4c..dcbaae79fce 100644 --- a/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/ShortcutsIT.java +++ b/flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/ShortcutsIT.java @@ -160,6 +160,26 @@ public void clickShortcutAllowsKeyDefaults() { assertActualEquals("click: "); } + @Test + public void removingShortcutCleansJavascriptEventSettingsItUsed() { + WebElement removalInput = findElement(By.id("removal-input")); + + Assert.assertEquals("removalInput should be empty", "", + removalInput.getAttribute("value")); + + // the removalInput has a shortcut bound on 'd'. When 'd' is typed, + // instead of printing the letter, the contents are capitalized instead. + // The shortcut is removed at the same time, so another 'd' should be + // printed out. + + removalInput.sendKeys("abcd abcd"); + + Assert.assertEquals( + "removalInput should have text, with some letters" + + " capitalized and only one 'd' letter", + "ABC abcd", removalInput.getAttribute("value")); + } + private void assertActualEquals(String expected) { Assert.assertEquals(expected, findElement(By.id("actual")).getAttribute("value"));