use of com.vaadin.flow.template.angular.ElementTemplateBuilder 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.ElementTemplateBuilder in project flow by vaadin.
the class TemplateElementStateProviderTest method testNestedTemplateElements.
@Test
public void testNestedTemplateElements() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("parent").addChild(new ElementTemplateBuilder("child0")).addChild(new ElementTemplateBuilder("child1"));
Element element = createElement(builder);
Assert.assertEquals(2, element.getChildCount());
Element child0 = element.getChild(0);
Assert.assertEquals("child0", child0.getTag());
Assert.assertEquals(element, child0.getParent());
Element child1 = element.getChild(1);
Assert.assertEquals("child1", child1.getTag());
Assert.assertEquals(element, child1.getParent());
}
use of com.vaadin.flow.template.angular.ElementTemplateBuilder in project flow by vaadin.
the class TemplateElementStateProviderTest method testElementJsonProperties.
@Test
public void testElementJsonProperties() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
Element element = createElement(builder);
StateNode stateNode = element.getNode();
JsonObject json = Json.createObject();
json.put("foo", "bar");
ModelMap.get(stateNode).setValue("key", json);
Assert.assertEquals(json, element.getPropertyRaw("a"));
Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
use of com.vaadin.flow.template.angular.ElementTemplateBuilder in project flow by vaadin.
the class TemplateElementStateProviderTest method testElementDoubleProperties.
@Test
public void testElementDoubleProperties() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
Element element = createElement(builder);
StateNode stateNode = element.getNode();
ModelMap.get(stateNode).setValue("key", 1.1d);
Assert.assertEquals(1.1d, element.getPropertyRaw("a"));
Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
use of com.vaadin.flow.template.angular.ElementTemplateBuilder in project flow by vaadin.
the class TemplateElementStateProviderTest method testElementBooleanProperties.
@Test
public void testElementBooleanProperties() {
ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
Element element = createElement(builder);
StateNode stateNode = element.getNode();
ModelMap.get(stateNode).setValue("key", Boolean.TRUE);
Assert.assertEquals(Boolean.TRUE, element.getPropertyRaw("a"));
Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Aggregations