use of com.vaadin.flow.template.angular.ElementTemplateNode 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.template.angular.ElementTemplateNode 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.template.angular.ElementTemplateNode in project flow by vaadin.
the class AngularTemplateParserTest method parseStyle.
@Test
public void parseStyle() {
ElementTemplateNode node = (ElementTemplateNode) parse("<button style='background-color:red'>");
Assert.assertEquals(1, node.getAttributeNames().count());
Assert.assertEquals(0, node.getPropertyNames().count());
Assert.assertEquals(0, node.getClassNames().count());
Optional<BindingValueProvider> binding = node.getAttributeBinding("style");
Assert.assertTrue(binding.isPresent());
Assert.assertEquals("background-color:red", binding.get().getValue(null));
}
use of com.vaadin.flow.template.angular.ElementTemplateNode 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