Search in sources :

Example 1 with TestModelDescriptor

use of com.vaadin.flow.template.angular.model.TestModelDescriptor in project flow by vaadin.

the class JsExpressionBindingProviderTest method setTemplateProperty_useJsExpression.

@Test
public void setTemplateProperty_useJsExpression() {
    JsExpressionBindingProvider binding = new JsExpressionBindingProvider("bar +'foo'");
    StateNode node = new StateNode(ModelMap.class, TemplateMap.class);
    node.getFeature(TemplateMap.class).setModelDescriptor(new TestModelDescriptor(Collections.singletonMap("bar", BasicModelType.get(String.class).get())));
    ModelMap.get(node).setValue("bar", "modelValue");
    Assert.assertEquals("modelValuefoo", binding.getValue(node));
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) StateNode(com.vaadin.flow.internal.StateNode) JsExpressionBindingProvider(com.vaadin.flow.template.angular.JsExpressionBindingProvider) TestModelDescriptor(com.vaadin.flow.template.angular.model.TestModelDescriptor) Test(org.junit.Test)

Example 2 with TestModelDescriptor

use of com.vaadin.flow.template.angular.model.TestModelDescriptor in project flow by vaadin.

the class JsExpressionBindingProviderTest method jsExpressionWithSubProperty.

@Test
public void jsExpressionWithSubProperty() {
    JsExpressionBindingProvider binding = new JsExpressionBindingProvider("bean.property");
    StateNode beanNode = new StateNode(ModelMap.class);
    ModelMap beanModel = ModelMap.get(beanNode);
    beanModel.setValue("property", "foo");
    StateNode rootNode = new StateNode(TemplateMap.class, ModelMap.class);
    Map<String, ModelType> beanProperties = Collections.singletonMap("property", BasicModelType.get(String.class).get());
    Map<String, ModelType> modelProperties = Collections.singletonMap("bean", new BeanModelType<>(Object.class, beanProperties));
    rootNode.getFeature(TemplateMap.class).setModelDescriptor(new TestModelDescriptor(modelProperties));
    ModelMap.get(rootNode).setValue("bean", beanNode);
    Assert.assertEquals("foo", binding.getValue(rootNode));
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) JsExpressionBindingProvider(com.vaadin.flow.template.angular.JsExpressionBindingProvider) BasicModelType(com.vaadin.flow.templatemodel.BasicModelType) ModelType(com.vaadin.flow.templatemodel.ModelType) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) TestModelDescriptor(com.vaadin.flow.template.angular.model.TestModelDescriptor) Test(org.junit.Test)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)2 TemplateMap (com.vaadin.flow.internal.nodefeature.TemplateMap)2 JsExpressionBindingProvider (com.vaadin.flow.template.angular.JsExpressionBindingProvider)2 TestModelDescriptor (com.vaadin.flow.template.angular.model.TestModelDescriptor)2 Test (org.junit.Test)2 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)1 BeanModelType (com.vaadin.flow.template.angular.model.BeanModelType)1 BasicModelType (com.vaadin.flow.templatemodel.BasicModelType)1 ModelType (com.vaadin.flow.templatemodel.ModelType)1