Search in sources :

Example 11 with ElementTemplateNode

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));
}
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 12 with ElementTemplateNode

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

Example 13 with ElementTemplateNode

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

Example 14 with ElementTemplateNode

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

Example 15 with ElementTemplateNode

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());
}
Also used : Element(com.vaadin.flow.dom.Element) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateElementStateProvider(com.vaadin.flow.dom.impl.TemplateElementStateProvider) 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