use of com.vaadin.flow.template.angular.BindingValueProvider in project flow by vaadin.
the class AngularTemplateParserTest method parseClassName.
@Test
public void parseClassName() {
ElementTemplateNode rootNode = (ElementTemplateNode) parse("<input [class.foo]=bar [class.camelCase]=baz></input>");
Assert.assertEquals(0, rootNode.getAttributeNames().count());
Assert.assertEquals(0, rootNode.getPropertyNames().count());
Assert.assertEquals(2, rootNode.getClassNames().count());
Optional<BindingValueProvider> fooBinding = rootNode.getClassNameBinding("foo");
Assert.assertTrue(fooBinding.isPresent());
Optional<BindingValueProvider> camelCaseBinding = rootNode.getClassNameBinding("camelCase");
Assert.assertTrue(camelCaseBinding.isPresent());
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(fooBinding.get().getValue(node));
Assert.assertNull(camelCaseBinding.get().getValue(node));
ModelMap.get(node).setValue("bar", "value");
ModelMap.get(node).setValue("baz", "value2");
Assert.assertEquals("value", fooBinding.get().getValue(node));
Assert.assertEquals("value2", camelCaseBinding.get().getValue(node));
}
use of com.vaadin.flow.template.angular.BindingValueProvider in project flow by vaadin.
the class AngularTemplateParserTest method parseMixedCaseAttributeStyle.
@Test
public void parseMixedCaseAttributeStyle() {
ElementTemplateNode node = (ElementTemplateNode) parse("<button someTag='value'>");
Assert.assertEquals(1, node.getAttributeNames().count());
Assert.assertEquals("sometag", node.getAttributeNames().findFirst().get());
Assert.assertEquals(0, node.getPropertyNames().count());
Assert.assertEquals(0, node.getClassNames().count());
Optional<BindingValueProvider> binding = node.getAttributeBinding("sometag");
Assert.assertTrue(binding.isPresent());
Assert.assertEquals("value", binding.get().getValue(null));
}
use of com.vaadin.flow.template.angular.BindingValueProvider 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.BindingValueProvider 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.BindingValueProvider 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));
}
Aggregations