use of com.vaadin.flow.template.angular.TextTemplateNode 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.TextTemplateNode 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.TextTemplateNode 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.TextTemplateNode 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));
}
use of com.vaadin.flow.template.angular.TextTemplateNode in project flow by vaadin.
the class AngularTemplateParserTest method parseBasicTemplate.
@Test
public void parseBasicTemplate() {
ElementTemplateNode rootNode = (ElementTemplateNode) parse("<div id=bar>baz<input></div>");
Assert.assertEquals("div", rootNode.getTag());
Assert.assertEquals(0, rootNode.getPropertyNames().count());
Assert.assertEquals(0, rootNode.getClassNames().count());
Assert.assertEquals(1, rootNode.getAttributeNames().count());
Assert.assertEquals("bar", rootNode.getAttributeBinding("id").get().getValue(null));
Assert.assertEquals(2, rootNode.getChildCount());
TextTemplateNode textChild = (TextTemplateNode) rootNode.getChild(0);
Assert.assertEquals("baz", textChild.getTextBinding().getValue(null));
ElementTemplateNode inputChild = (ElementTemplateNode) rootNode.getChild(1);
Assert.assertEquals("input", inputChild.getTag());
Assert.assertEquals(0, inputChild.getAttributeNames().count());
Assert.assertEquals(0, inputChild.getChildCount());
}
Aggregations