Search in sources :

Example 6 with ConstantPoolKey

use of com.vaadin.flow.internal.ConstantPoolKey in project flow by vaadin.

the class DomEventTest method getEventSettings.

private <T extends ComponentEvent<Component>> JsonObject getEventSettings(Class<T> eventType) {
    Component component = new Component(new Element("element")) {
    };
    component.addListener(eventType, e -> {
    });
    ElementListenerMap elementListenerMap = component.getElement().getNode().getFeature(ElementListenerMap.class);
    List<NodeChange> changes = new ArrayList<>();
    elementListenerMap.collectChanges(changes::add);
    Assert.assertEquals(1, changes.size());
    MapPutChange change = (MapPutChange) changes.get(0);
    Assert.assertEquals("event", change.getKey());
    ConstantPoolKey value = (ConstantPoolKey) change.getValue();
    JsonObject constantPoolUpdate = Json.createObject();
    value.export(constantPoolUpdate);
    String[] keys = constantPoolUpdate.keys();
    Assert.assertEquals(1, keys.length);
    JsonObject eventSettings = constantPoolUpdate.getObject(keys[0]);
    return eventSettings;
}
Also used : MapPutChange(com.vaadin.flow.internal.change.MapPutChange) NodeChange(com.vaadin.flow.internal.change.NodeChange) ElementListenerMap(com.vaadin.flow.internal.nodefeature.ElementListenerMap) Element(com.vaadin.flow.dom.Element) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) ConstantPoolKey(com.vaadin.flow.internal.ConstantPoolKey)

Aggregations

ConstantPoolKey (com.vaadin.flow.internal.ConstantPoolKey)6 JsonObject (elemental.json.JsonObject)3 Test (org.junit.Test)2 Element (com.vaadin.flow.dom.Element)1 MapPutChange (com.vaadin.flow.internal.change.MapPutChange)1 NodeChange (com.vaadin.flow.internal.change.NodeChange)1 ElementListenerMap (com.vaadin.flow.internal.nodefeature.ElementListenerMap)1 ArrayList (java.util.ArrayList)1