Search in sources :

Example 1 with ElementTemplateNode

use of com.vaadin.flow.template.angular.ElementTemplateNode 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 ElementTemplateNode

use of com.vaadin.flow.template.angular.ElementTemplateNode 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 ElementTemplateNode

use of com.vaadin.flow.template.angular.ElementTemplateNode 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 ElementTemplateNode

use of com.vaadin.flow.template.angular.ElementTemplateNode 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 ElementTemplateNode

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

the class AngularTemplateIncludeBuilderTest method templateWithInclude.

@Test
public void templateWithInclude() {
    // <div>
    // <span>Main template</span>
    // @include sub.html@
    // </div>
    // <div>
    // <span>Sub template</span>
    // </div>
    IncludeTemplate template = new IncludeTemplate();
    ElementTemplateNode parentTemplateNode = ((TemplateElementStateProvider) template.getElement().getStateProvider()).getTemplateNode();
    Element element = template.getElement();
    Assert.assertEquals("div", element.getTag());
    List<Element> children = filterOutTextChildren(element);
    Assert.assertEquals("span", children.get(0).getTag());
    Assert.assertEquals("Main template", element.getChild(1).getTextRecursively());
    Element subTemplateElement = children.get(1);
    Assert.assertEquals("div", subTemplateElement.getTag());
    // template node should have the main template as the parent #1176
    ElementTemplateNode includedTemplateNode = ((TemplateElementStateProvider) subTemplateElement.getStateProvider()).getTemplateNode();
    Assert.assertEquals(parentTemplateNode, includedTemplateNode.getParent().get());
    Element span = filterOutTextChildren(subTemplateElement).get(0);
    Assert.assertEquals("span", span.getTag());
    Assert.assertEquals("Sub template", span.getTextRecursively());
}
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