use of com.vaadin.flow.internal.nodefeature.ElementListenerMap in project flow by vaadin.
the class ComponentTest method declarativeSyncProperties_propertiesAreRegisteredWithProperDisabledUpdateMode.
@Test
public void declarativeSyncProperties_propertiesAreRegisteredWithProperDisabledUpdateMode() {
TestDiv div = new TestDiv();
ElementListenerMap feature = div.getElement().getNode().getFeature(ElementListenerMap.class);
Set<String> props = feature.getExpressions("bar");
Assert.assertEquals(1, props.size());
Assert.assertTrue(props.contains("}baz"));
Assert.assertEquals(DisabledUpdateMode.ALWAYS, feature.getPropertySynchronizationMode("baz"));
props = feature.getExpressions("foo");
Assert.assertEquals(1, props.size());
Assert.assertTrue(props.contains("}bar"));
Assert.assertEquals(DisabledUpdateMode.ONLY_WHEN_ENABLED, feature.getPropertySynchronizationMode("bar"));
}
use of com.vaadin.flow.internal.nodefeature.ElementListenerMap in project flow by vaadin.
the class ElementTest method domPropertyListener_unregisterCleansEverything.
@Test
public void domPropertyListener_unregisterCleansEverything() {
Element element = ElementFactory.createDiv();
DomListenerRegistration registration = element.addPropertyChangeListener("property", "event", event -> {
Assert.fail("Unexpected event");
});
registration.remove();
Assert.assertNull("The property should not be synchronized", element.getNode().getFeature(ElementListenerMap.class).getPropertySynchronizationMode("property"));
ElementListenerMap listenerMap = element.getNode().getFeature(ElementListenerMap.class);
Assert.assertEquals("There should be no DOM listener", Collections.emptySet(), ElementListenersTest.getExpressions(listenerMap, "event"));
// Should not trigger assert in the listener
element.setProperty("property", "value");
}
use of com.vaadin.flow.internal.nodefeature.ElementListenerMap in project flow by vaadin.
the class ElementTest method domPropertyListener_registersListenerAndDomTrigger.
@Test
public void domPropertyListener_registersListenerAndDomTrigger() {
Element element = ElementFactory.createDiv();
AtomicReference<Serializable> listenerValue = new AtomicReference<>();
element.addPropertyChangeListener("property", "event", event -> {
if (listenerValue.getAndSet(event.getValue()) != null) {
Assert.fail("Unexpected event");
}
});
Assert.assertEquals("The property should be synchronized", DisabledUpdateMode.ONLY_WHEN_ENABLED, element.getNode().getFeature(ElementListenerMap.class).getPropertySynchronizationMode("property"));
ElementListenerMap listenerMap = element.getNode().getFeature(ElementListenerMap.class);
Assert.assertEquals("A DOM event synchronization should be defined", Collections.singleton(JsonConstants.SYNCHRONIZE_PROPERTY_TOKEN + "property"), ElementListenersTest.getExpressions(listenerMap, "event"));
element.setProperty("property", "value");
Assert.assertEquals("Listener shold be registered", listenerValue.get(), "value");
}
use of com.vaadin.flow.internal.nodefeature.ElementListenerMap in project flow by vaadin.
the class ShortcutRegistrationTest method hasKeyAInKeyDownExpression.
private boolean hasKeyAInKeyDownExpression(Component component) {
ElementListenerMap map = component.getElement().getNode().getFeature(ElementListenerMap.class);
// Once the shortcut listener is registered the expression should
// contain KeyA
boolean hasKeyA = false;
for (String expression : map.getExpressions("keydown")) {
if (expression.contains(Key.KEY_A.getKeys().get(0))) {
hasKeyA = true;
}
}
return hasKeyA;
}
use of com.vaadin.flow.internal.nodefeature.ElementListenerMap 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;
}
Aggregations