Skip to content

Commit

Permalink
It demonstrating #5480 (#6432)
Browse files Browse the repository at this point in the history
* Verify #5480
  • Loading branch information
ujoni committed Sep 12, 2019
1 parent a9dbe94 commit aa915fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -155,5 +158,17 @@ public ShortcutsView() {
wrapper1.add(clickInput1, clickButton1);
wrapper2.add(clickInput2, clickButton2);
add(wrapper1, wrapper2);

// removingShortcutCleansJavascriptEventSettingsItUsed
AtomicReference<ShortcutRegistration> 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);
}
}
Expand Up @@ -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"));
Expand Down

0 comments on commit aa915fb

Please sign in to comment.