Search in sources :

Example 1 with DomListenerRegistration

use of com.vaadin.flow.dom.DomListenerRegistration in project flow by vaadin.

the class ValueChangeModeTest method assertDebounceEquals.

private void assertDebounceEquals(ValueChangeModeField field, EnumSet<DebouncePhase> phases, int timeout) {
    DomListenerRegistration reg = field.getSynchronizationRegistration();
    Assert.assertEquals(timeout, reg.getDebounceTimeout());
    Assert.assertEquals(phases, reg.getDebouncePhases());
}
Also used : DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration)

Example 2 with DomListenerRegistration

use of com.vaadin.flow.dom.DomListenerRegistration in project flow by vaadin.

the class ElementListenersTest method synchronizeProperty_nullArgument_illegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void synchronizeProperty_nullArgument_illegalArgumentException() {
    DomListenerRegistration registration = ns.add("foo", noOp);
    registration.synchronizeProperty(null);
}
Also used : DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) Test(org.junit.Test)

Example 3 with DomListenerRegistration

use of com.vaadin.flow.dom.DomListenerRegistration in project flow by vaadin.

the class ElementListenersTest method addEventDataElement_targetNodeInJsonData_elementMapped.

@Test
public void addEventDataElement_targetNodeInJsonData_elementMapped() {
    Element parent = new Element("parent");
    Element child = new Element("child");
    Element sibling = new Element("sibling");
    parent.appendChild(child);
    new StateTree(new UI().getInternals(), ElementChildrenList.class).getUI().getElement().appendChild(parent, sibling);
    final String eventType = "click";
    final String expression = "expression";
    final String key = JsonConstants.MAP_STATE_NODE_EVENT_DATA + expression;
    AtomicReference<DomEvent> capturedTarget = new AtomicReference<>();
    final DomListenerRegistration registration = parent.addEventListener(eventType, capturedTarget::set);
    final ElementListenerMap listenerMap = parent.getNode().getFeature(ElementListenerMap.class);
    Set<String> expressions = getExpressions(listenerMap, eventType);
    Assert.assertEquals(0, expressions.size());
    registration.addEventDataElement(expression);
    expressions = getExpressions(listenerMap, eventType);
    Assert.assertEquals(1, expressions.size());
    Assert.assertEquals(key, expressions.iterator().next());
    final JsonObject eventData = Json.createObject();
    eventData.put(key, child.getNode().getId());
    listenerMap.fireEvent(new DomEvent(parent, eventType, eventData));
    Assert.assertEquals(child, capturedTarget.get().getEventDataElement(expression).get());
    // nothing reported -> empty optional
    listenerMap.fireEvent(new DomEvent(parent, eventType, Json.createObject()));
    Assert.assertFalse("no element should be reported", capturedTarget.get().getEventDataElement(expression).isPresent());
    // sibling
    eventData.put(key, sibling.getNode().getId());
    listenerMap.fireEvent(new DomEvent(parent, eventType, eventData));
    Assert.assertEquals(sibling, capturedTarget.get().getEventDataElement(expression).get());
}
Also used : Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) StateTree(com.vaadin.flow.internal.StateTree) UI(com.vaadin.flow.component.UI) DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) DomEvent(com.vaadin.flow.dom.DomEvent) Test(org.junit.Test)

Example 4 with DomListenerRegistration

use of com.vaadin.flow.dom.DomListenerRegistration in project flow by vaadin.

the class ElementListenersTest method synchronizeProperty_emptyArgument_illegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void synchronizeProperty_emptyArgument_illegalArgumentException() {
    DomListenerRegistration registration = ns.add("foo", noOp);
    registration.synchronizeProperty("");
}
Also used : DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) Test(org.junit.Test)

Example 5 with DomListenerRegistration

use of com.vaadin.flow.dom.DomListenerRegistration in project flow by vaadin.

the class ElementListenersTest method eventDataKeyNotPresentNotFail.

@Test
public void eventDataKeyNotPresentNotFail() {
    AtomicInteger eventCount = new AtomicInteger();
    DomListenerRegistration registration = ns.add("foo", e -> eventCount.incrementAndGet());
    registration.setFilter("filterKey");
    ns.fireEvent(createEvent("foo"));
    Assert.assertEquals(0, eventCount.get());
    JsonObject eventData = Json.createObject();
    eventData.put("filterKey", true);
    ns.fireEvent(new DomEvent(new Element("element"), "foo", eventData));
    Assert.assertEquals(1, eventCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) DomListenerRegistration(com.vaadin.flow.dom.DomListenerRegistration) DomEvent(com.vaadin.flow.dom.DomEvent) Test(org.junit.Test)

Aggregations

DomListenerRegistration (com.vaadin.flow.dom.DomListenerRegistration)17 Test (org.junit.Test)12 Element (com.vaadin.flow.dom.Element)7 DomEvent (com.vaadin.flow.dom.DomEvent)5 StateTree (com.vaadin.flow.internal.StateTree)4 JsonObject (elemental.json.JsonObject)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 UI (com.vaadin.flow.component.UI)3 Registration (com.vaadin.flow.shared.Registration)2 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Component (com.vaadin.flow.component.Component)1 HtmlComponent (com.vaadin.flow.component.HtmlComponent)1 Label (com.vaadin.flow.component.html.Label)1 DebouncePhase (com.vaadin.flow.dom.DebouncePhase)1 DisabledUpdateMode (com.vaadin.flow.dom.DisabledUpdateMode)1 DomEventListener (com.vaadin.flow.dom.DomEventListener)1 PropertyChangeEvent (com.vaadin.flow.dom.PropertyChangeEvent)1