use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class MapSyncRpcHandlerTest method createSyncPropertyInvocation.
private static JsonObject createSyncPropertyInvocation(Element element, String property, Serializable value) {
StateNode node = EventRpcHandlerTest.getInvocationNode(element);
// Copied from ServerConnector
JsonObject message = Json.createObject();
message.put(JsonConstants.RPC_NODE, node.getId());
message.put(JsonConstants.RPC_FEATURE, NodeFeatureRegistry.getId(ElementPropertyMap.class));
message.put(JsonConstants.RPC_PROPERTY, property);
message.put(JsonConstants.RPC_PROPERTY_VALUE, JsonCodec.encodeWithoutTypeInfo(value));
return message;
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsPropertyValueOfStateNode_propertySetToNode.
@Test
public void syncJSON_jsonIsPropertyValueOfStateNode_propertySetToNode() throws Exception {
// Let's use element's ElementPropertyMap for testing.
TestComponent component = new TestComponent();
Element element = component.getElement();
UI ui = new UI();
ui.add(component);
StateNode node = element.getNode();
// Set model value directly via ElementPropertyMap
ElementPropertyMap propertyMap = node.getFeature(ElementPropertyMap.class);
propertyMap.setUpdateFromClientFilter(name -> true);
ElementPropertyMap modelMap = propertyMap.resolveModelMap("foo");
// fake StateNode has been created for the model
StateNode model = modelMap.getNode();
modelMap.setProperty("bar", "baz");
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", model.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, "foo", json);
Serializable testPropertyValue = propertyMap.getProperty("foo");
Assert.assertTrue(testPropertyValue instanceof StateNode);
StateNode newNode = (StateNode) testPropertyValue;
Assert.assertSame(model, newNode);
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AngularTemplateParserTest method parseTemplateProperty.
@Test
public void parseTemplateProperty() {
ElementTemplateNode rootNode = (ElementTemplateNode) parse("<input [value]='foo'></input>");
Assert.assertEquals("input", rootNode.getTag());
Assert.assertEquals(0, rootNode.getAttributeNames().count());
Assert.assertEquals(0, rootNode.getClassNames().count());
Assert.assertEquals(1, rootNode.getPropertyNames().count());
Optional<BindingValueProvider> binding = rootNode.getPropertyBinding("value");
Assert.assertTrue(binding.isPresent());
StateNode node = new StateNode(ModelMap.class);
// Explicitly set "foo" property to null. So model has property "foo".
// See #970
ModelMap.get(node).setValue("foo", null);
Assert.assertNull(binding.get().getValue(node));
ModelMap.get(node).setValue("foo", "bar");
Assert.assertEquals("bar", binding.get().getValue(node));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AngularTemplateParserTest method parseParameterizedTextTemplate.
@Test
public void parseParameterizedTextTemplate() {
ElementTemplateNode rootNode = (ElementTemplateNode) parse("<div id='foo'>{{bar}}<input></div>");
Assert.assertEquals("div", rootNode.getTag());
Assert.assertEquals(1, rootNode.getAttributeNames().count());
Assert.assertEquals("foo", rootNode.getAttributeBinding("id").get().getValue(null));
Assert.assertEquals(2, rootNode.getChildCount());
TextTemplateNode textChild = (TextTemplateNode) rootNode.getChild(0);
BindingValueProvider binding = textChild.getTextBinding();
StateNode node = new StateNode(ModelMap.class);
// Explicitly set "bar" property to null. So model has property "bar".
// See #970
ModelMap.get(node).setValue("bar", null);
Assert.assertNull(binding.getValue(node));
String value = "someValue";
ModelMap.get(node).setValue("bar", value);
Assert.assertEquals(value, binding.getValue(node));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AngularTemplateParserTest method parseTemplateAttribute.
@Test
public void parseTemplateAttribute() {
ElementTemplateNode rootNode = (ElementTemplateNode) parse("<input [attr.value]='foo'></input>");
Assert.assertEquals("input", rootNode.getTag());
Assert.assertEquals(1, rootNode.getAttributeNames().count());
Assert.assertEquals(0, rootNode.getClassNames().count());
Assert.assertEquals(0, rootNode.getPropertyNames().count());
Optional<BindingValueProvider> binding = rootNode.getAttributeBinding("value");
Assert.assertTrue(binding.isPresent());
StateNode node = new StateNode(ModelMap.class);
// Explicitly set "foo" property to null. So model has property "foo".
// See #970
ModelMap.get(node).setValue("foo", null);
Assert.assertNull(binding.get().getValue(node));
ModelMap.get(node).setValue("foo", "bar");
Assert.assertEquals("bar", binding.get().getValue(node));
}
Aggregations