Search in sources :

Example 1 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class ScriptParsingTest method inlineStyles.

@Test
public void inlineStyles() {
    String contents = // 
    ".foo {\n" + // 
    "  font-weight: bold;\n" + "}\n";
    TemplateNode templateNode = parse(// 
    "<style>" + contents + // 
    "</style>");
    // 
    Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
    ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
    Assert.assertEquals("style", elementTemplate.getTag());
    TextTemplateNode textNode = ((TextTemplateNode) elementTemplate.getChild(0));
    String nodeContents = (String) textNode.getTextBinding().getValue(new StateNode());
    Assert.assertEquals(contents, nodeContents);
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 2 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class ScriptParsingTest method inlineScript.

@Test
public void inlineScript() {
    String script = "window.alert('hello');\n" + "window.alert('world');\n";
    TemplateNode templateNode = parse(// 
    "<script>" + script + // 
    "</script>");
    // 
    Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
    ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
    Assert.assertEquals("script", elementTemplate.getTag());
    TextTemplateNode textNode = ((TextTemplateNode) elementTemplate.getChild(0));
    String nodeContents = (String) textNode.getTextBinding().getValue(new StateNode());
    Assert.assertEquals(script, nodeContents);
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 3 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class ScriptParsingTest method emptyInlineScript.

@Test
public void emptyInlineScript() {
    TemplateNode templateNode = parse("<script></script>");
    Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
    ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
    Assert.assertEquals("script", 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 4 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class TemplateBuilderTest method testBasicTemplate.

@Test
public void testBasicTemplate() {
    // <div baz="lorem" foo="bar">baz</div> where baz is an attribute and
    // foo a property
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("foo", new StaticBindingValueProvider("bar")).setAttribute("baz", new StaticBindingValueProvider("lorem")).setClassName("a-name", new StaticBindingValueProvider("a-value")).addChild(new TextTemplateBuilder(new StaticBindingValueProvider("baz")));
    List<TemplateNode> nodes = builder.build(null);
    Assert.assertFalse(nodes.isEmpty());
    ElementTemplateNode node = (ElementTemplateNode) nodes.get(0);
    Assert.assertFalse(node.getParent().isPresent());
    Assert.assertEquals("div", node.getTag());
    Assert.assertArrayEquals(new String[] { "foo" }, node.getPropertyNames().toArray());
    Assert.assertEquals("bar", node.getPropertyBinding("foo").get().getValue(null));
    Assert.assertArrayEquals(new String[] { "baz" }, node.getAttributeNames().toArray());
    Assert.assertEquals("lorem", node.getAttributeBinding("baz").get().getValue(null));
    Assert.assertArrayEquals(new String[] { "a-name" }, node.getClassNames().toArray());
    Assert.assertEquals("a-value", node.getClassNameBinding("a-name").get().getValue(null));
    Assert.assertEquals(1, node.getChildCount());
    TextTemplateNode child = (TextTemplateNode) node.getChild(0);
    Assert.assertSame(node, child.getParent().get());
    Assert.assertEquals("baz", child.getTextBinding().getValue(null));
    Assert.assertEquals(0, child.getChildCount());
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateBuilder(com.vaadin.flow.template.angular.TextTemplateBuilder) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider) Test(org.junit.Test)

Example 5 with TemplateNode

use of com.vaadin.flow.template.angular.TemplateNode in project flow by vaadin.

the class DefaultTextModelBuiderFactoryTest method parseNotInclude.

@Test
public void parseNotInclude() {
    TemplateNode node = TemplateParser.parse("<div>foo@include.com, baz@foo.com</div>", null);
    Assert.assertEquals(1, node.getChildCount());
    TemplateNode child = node.getChild(0);
    Assert.assertTrue(child instanceof TextTemplateNode);
    TextTemplateNode text = (TextTemplateNode) child;
    Assert.assertEquals("foo@include.com, baz@foo.com", text.getTextBinding().getValue(null));
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) Test(org.junit.Test)

Aggregations

TemplateNode (com.vaadin.flow.template.angular.TemplateNode)48 Test (org.junit.Test)42 Element (com.vaadin.flow.dom.Element)29 StateNode (com.vaadin.flow.internal.StateNode)18 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)13 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)12 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)11 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)4 HashMap (java.util.HashMap)4 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)3 TemplateMap (com.vaadin.flow.internal.nodefeature.TemplateMap)2 Component (com.vaadin.flow.component.Component)1 UIInternals (com.vaadin.flow.component.internal.UIInternals)1 StateTree (com.vaadin.flow.internal.StateTree)1 MapPutChange (com.vaadin.flow.internal.change.MapPutChange)1 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)1 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)1 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)1 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)1 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)1