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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations