use of com.vaadin.flow.template.angular.ElementTemplateNode 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.ElementTemplateNode 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.ElementTemplateNode in project flow by vaadin.
the class ScriptParsingTest method scriptWithAttributes.
@Test
public void scriptWithAttributes() {
TemplateNode templateNode = parse("<script type='text/javascript' src='file://foobar'/>");
Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
Assert.assertEquals("script", elementTemplate.getTag());
Assert.assertEquals("text/javascript", elementTemplate.getAttributeBinding("type").get().getValue(new StateNode()));
Assert.assertEquals("file://foobar", elementTemplate.getAttributeBinding("src").get().getValue(new StateNode()));
}
use of com.vaadin.flow.template.angular.ElementTemplateNode in project flow by vaadin.
the class ScriptParsingTest method emptyInlineStyle.
@Test
public void emptyInlineStyle() {
TemplateNode templateNode = parse("<style></style>");
Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
Assert.assertEquals("style", elementTemplate.getTag());
Assert.assertEquals(0, elementTemplate.getChildCount());
}
use of com.vaadin.flow.template.angular.ElementTemplateNode in project flow by vaadin.
the class AngularTemplateIncludeBuilderTest method templateWithMultipleIncludes.
@Test
public void templateWithMultipleIncludes() {
// <div>
// <span>Main template</span>
// @include subfolder/includes-from-parent.html@
// </div>
// <div>
// @include ../sub.html @
// </div>
// <div>
// <span>Sub template</span>
// </div>
MultipleIncludeTemplate template = new MultipleIncludeTemplate();
ElementTemplateNode node = ((TemplateElementStateProvider) template.getElement().getStateProvider()).getTemplateNode();
Element element = template.getElement();
Assert.assertEquals("root-template", element.getTag());
Element firstSubTemplateElement = filterOutTextChildren(element).get(0);
ElementTemplateNode firstSubTemplateElementNode = ((TemplateElementStateProvider) firstSubTemplateElement.getStateProvider()).getTemplateNode();
Assert.assertEquals("includes-from-parent", firstSubTemplateElement.getTag());
Assert.assertEquals(node, firstSubTemplateElementNode.getParent().get());
Element secondSubTemplateElement = filterOutTextChildren(firstSubTemplateElement).get(0);
ElementTemplateNode secondSubTemplateElementNode = ((TemplateElementStateProvider) secondSubTemplateElement.getStateProvider()).getTemplateNode();
Assert.assertEquals("div", secondSubTemplateElement.getTag());
Assert.assertEquals(firstSubTemplateElementNode, secondSubTemplateElementNode.getParent().get());
Element span = filterOutTextChildren(secondSubTemplateElement).get(0);
Assert.assertEquals("span", span.getTag());
Assert.assertEquals("Sub template", span.getTextRecursively());
Assert.assertEquals(secondSubTemplateElementNode, ((TemplateElementStateProvider) span.getStateProvider()).getTemplateNode().getParent().get());
}
Aggregations