use of com.vaadin.flow.dom.DomEvent in project flow by vaadin.
the class ElementListenersTest method addEventDataElement_eventTarget_usesMapEventTargetInstead.
@Test
public void addEventDataElement_eventTarget_usesMapEventTargetInstead() {
Element parent = new Element("parent");
Element child = new Element("child");
parent.appendChild(child);
new StateTree(new UI().getInternals(), ElementChildrenList.class).getUI().getElement().appendChild(parent);
final String eventType = "click";
AtomicReference<DomEvent> capturedTarget = new AtomicReference<>();
final DomListenerRegistration registration = parent.addEventListener(eventType, capturedTarget::set);
final ElementListenerMap listenerMap = parent.getNode().getFeature(ElementListenerMap.class);
registration.addEventDataElement("event.target");
Set<String> expressions = getExpressions(listenerMap, eventType);
Assert.assertEquals(1, expressions.size());
Assert.assertEquals(JsonConstants.MAP_STATE_NODE_EVENT_DATA, expressions.iterator().next());
final JsonObject eventData = Json.createObject();
eventData.put(JsonConstants.MAP_STATE_NODE_EVENT_DATA, child.getNode().getId());
listenerMap.fireEvent(new DomEvent(parent, eventType, eventData));
Assert.assertEquals(child, capturedTarget.get().getEventTarget().get());
Assert.assertEquals(child, capturedTarget.get().getEventDataElement("event.target").get());
}
use of com.vaadin.flow.dom.DomEvent in project flow by vaadin.
the class ElementListenersTest method disabledElement_listenerWithAlwaysUpdateModeReceivesEvent.
@Test
public void disabledElement_listenerWithAlwaysUpdateModeReceivesEvent() {
AtomicInteger eventCount = new AtomicInteger();
ns.add("foo", e -> eventCount.incrementAndGet()).setDisabledUpdateMode(DisabledUpdateMode.ALWAYS);
Assert.assertEquals(0, eventCount.get());
DomEvent event = createEvent("foo");
event.getSource().setEnabled(false);
ns.fireEvent(event);
Assert.assertEquals(1, eventCount.get());
}
use of com.vaadin.flow.dom.DomEvent in project flow by vaadin.
the class ElementListenersTest method disabledElement_listenerDoesntReceiveEvent.
@Test
public void disabledElement_listenerDoesntReceiveEvent() {
AtomicInteger eventCount = new AtomicInteger();
ns.add("foo", e -> eventCount.incrementAndGet());
Assert.assertEquals(0, eventCount.get());
DomEvent event = createEvent("foo");
event.getSource().setEnabled(false);
ns.fireEvent(event);
Assert.assertEquals(0, eventCount.get());
}
Aggregations