Search in sources :

Example 31 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class TemplateModelTest method setListWithExclude.

@Test
public void setListWithExclude() {
    TemplateWithExcludeOnList template = new TemplateWithExcludeOnList();
    List<Bean> beans = new ArrayList<>();
    beans.add(new Bean(1));
    beans.add(new Bean(2));
    template.getModel().setBeans(beans);
    ModelList modelList = getModelList(template, "beans");
    ModelMap bean1 = ModelMap.get(modelList.get(0));
    ModelMap bean2 = ModelMap.get(modelList.get(1));
    Set<String> bean1InMap = getKeys(bean1);
    Set<String> bean2InMap = getKeys(bean2);
    Assert.assertFalse("Bean1 in model should not have an 'intValue' property", bean1InMap.contains("intValue"));
    Assert.assertFalse("Bean2 in model should not have an 'intValue' property", bean2InMap.contains("intValue"));
    Assert.assertEquals("All other properties should have been included", 6, bean1InMap.size());
    Assert.assertEquals("All other properties should have been included", 6, bean2InMap.size());
}
Also used : ModelList(com.vaadin.flow.internal.nodefeature.ModelList) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ArrayList(java.util.ArrayList) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 32 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap 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)

Example 33 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class TemplateElementStateProviderTest method dynamicClassNames.

@Test
public void dynamicClassNames() {
    Element element = createElement("<div class='foo' [class.bar]=hasBar [class.baz]=hasBaz></div>");
    ClassList classList = element.getClassList();
    // Explicitly set "hasBar" and "hasBaz" properties to null. So model has
    // properties "hasBar" and "hasBaz".
    // See #970
    element.getNode().getFeature(ModelMap.class).setValue("hasBar", null);
    element.getNode().getFeature(ModelMap.class).setValue("hasBaz", null);
    Assert.assertEquals("foo", element.getAttribute("class"));
    assertClassList(classList, "foo");
    assertNotClassList(classList, "bar", "baz");
    ModelMap modelMap = element.getNode().getFeature(ModelMap.class);
    modelMap.setValue("hasBar", "");
    modelMap.setValue("hasBaz", "yes");
    assertClassList(classList, "foo", "baz");
    assertNotClassList(classList, "bar");
    modelMap.setValue("hasBar", 5);
    modelMap.setValue("hasBaz", 0);
    assertClassList(classList, "foo", "bar");
    assertNotClassList(classList, "baz");
    modelMap.setValue("hasBar", false);
    modelMap.setValue("hasBaz", true);
    assertClassList(classList, "foo", "baz");
    assertNotClassList(classList, "bar");
}
Also used : Element(com.vaadin.flow.dom.Element) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ClassList(com.vaadin.flow.dom.ClassList) Test(org.junit.Test)

Example 34 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class ModelMapTest method getParentMapAndAssertMapping.

private ModelMap getParentMapAndAssertMapping(ModelMap child, String childKey) {
    assert child != null;
    assert child.getNode() != null;
    ModelMap parentMap = ModelMap.get(child.getNode().getParent());
    assert parentMap != null;
    Assert.assertEquals(child.getNode(), parentMap.getValue(childKey));
    return parentMap;
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap)

Example 35 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class ModelMapTest method putGet.

@Test
public void putGet() {
    ModelMap map = new ModelMap(new StateNode());
    map.setValue("foo", "bar");
    Assert.assertEquals("bar", map.get("foo"));
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Aggregations

ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)41 Test (org.junit.Test)30 StateNode (com.vaadin.flow.internal.StateNode)18 Bean (com.vaadin.flow.templatemodel.Bean)18 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)9 ModelType (com.vaadin.flow.templatemodel.ModelType)5 PropertyFilter (com.vaadin.flow.templatemodel.PropertyFilter)5 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Assert (org.junit.Assert)5 Arrays (java.util.Arrays)4 Date (java.util.Date)4 BeanContainingBeans (com.vaadin.flow.templatemodel.BeanContainingBeans)3 InvalidTemplateModelException (com.vaadin.flow.templatemodel.InvalidTemplateModelException)3 ReflectTools (com.vaadin.flow.internal.ReflectTools)2 NodeChange (com.vaadin.flow.internal.change.NodeChange)2 BasicModelType (com.vaadin.flow.templatemodel.BasicModelType)2 Serializable (java.io.Serializable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClassList (com.vaadin.flow.dom.ClassList)1