use of com.vaadin.flow.template.angular.StaticBindingValueProvider 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.StaticBindingValueProvider in project flow by vaadin.
the class DefaultTextModelBuilderFactory method collectBuilders.
private void collectBuilders(String text, List<TemplateNodeBuilder> builders) {
if (text.isEmpty()) {
return;
}
int bindingIndex = text.indexOf(TEXT_BINDING_PREFIX);
int childIndex = text.indexOf(CHILD);
if (bindingIndex < 0 && childIndex < 0) {
builders.add(new TextTemplateBuilder(new StaticBindingValueProvider(text)));
} else {
Map<Integer, Runnable> handlers = new HashMap<>();
handlers.put(bindingIndex, createBindingHandler(text, builders, bindingIndex));
handlers.put(childIndex, createChildHandler(text, builders, childIndex));
Optional<Runnable> handler = handlers.keySet().stream().filter(index -> index.compareTo(0) >= 0).sorted().map(handlers::get).filter(Objects::nonNull).findFirst();
if (handler.isPresent()) {
handler.get().run();
} else {
builders.add(new TextTemplateBuilder(new StaticBindingValueProvider(text)));
}
}
}
use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.
the class TemplateElementStateProviderTest method testTextNode.
@Test
public void testTextNode() {
TextTemplateBuilder builder = new TextTemplateBuilder(new StaticBindingValueProvider("Hello"));
Element element = createElement(builder);
Assert.assertTrue(element.isTextNode());
Assert.assertEquals("Hello", element.getTextRecursively());
}
use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.
the class TemplateElementStateProviderTest method testTextNodeInParent.
@Test
public void testTextNodeInParent() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").addChild(new TextTemplateBuilder(new StaticBindingValueProvider("Hello")));
Element element = createElement(builder);
Assert.assertEquals("div", element.getTag());
Assert.assertEquals("Hello", element.getTextRecursively());
Element child = element.getChild(0);
Assert.assertTrue(child.isTextNode());
Assert.assertEquals(element, child.getParent());
}
use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.
the class TemplateElementStateProviderTest method testElementStringProperties.
@Test
public void testElementStringProperties() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a1", new StaticBindingValueProvider("v1")).setProperty("a2", new StaticBindingValueProvider("v2"));
Element element = createElement(builder);
Assert.assertEquals("v1", element.getProperty("a1"));
Assert.assertEquals("v2", element.getProperty("a2"));
Assert.assertEquals(new HashSet<>(Arrays.asList("a1", "a2")), element.getPropertyNames().collect(Collectors.toSet()));
}
Aggregations