Search in sources :

Example 16 with ElementTemplateNode

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));
}
Also used : BindingValueProvider(com.vaadin.flow.template.angular.BindingValueProvider) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 17 with ElementTemplateNode

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));
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) BindingValueProvider(com.vaadin.flow.template.angular.BindingValueProvider) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 18 with ElementTemplateNode

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));
}
Also used : BindingValueProvider(com.vaadin.flow.template.angular.BindingValueProvider) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) Test(org.junit.Test)

Example 19 with ElementTemplateNode

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));
}
Also used : BindingValueProvider(com.vaadin.flow.template.angular.BindingValueProvider) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Aggregations

ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)19 Test (org.junit.Test)19 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)8 StateNode (com.vaadin.flow.internal.StateNode)7 BindingValueProvider (com.vaadin.flow.template.angular.BindingValueProvider)6 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)6 Element (com.vaadin.flow.dom.Element)2 TemplateElementStateProvider (com.vaadin.flow.dom.impl.TemplateElementStateProvider)2 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)1 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)1 TextTemplateBuilder (com.vaadin.flow.template.angular.TextTemplateBuilder)1