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());
}
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));
}
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");
}
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;
}
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"));
}
Aggregations