Search in sources :

Example 6 with ElementTemplateBuilder

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

the class TemplateElementStateProviderTest method testEmptyElement.

@Test
public void testEmptyElement() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div");
    Element element = createElement(builder);
    Assert.assertEquals("div", element.getTag());
    Assert.assertFalse(element.isTextNode());
    Assert.assertNull(element.getParent());
    Assert.assertEquals(0, element.getChildCount());
    Assert.assertEquals(0, element.getPropertyNames().count());
    Assert.assertEquals(0, element.getAttributeNames().count());
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 7 with ElementTemplateBuilder

use of com.vaadin.flow.template.angular.ElementTemplateBuilder 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());
}
Also used : TextTemplateBuilder(com.vaadin.flow.template.angular.TextTemplateBuilder) ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider) Test(org.junit.Test)

Example 8 with ElementTemplateBuilder

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

the class TemplateElementStateProviderTest method testTemplateInBasicElement.

@Test
public void testTemplateInBasicElement() {
    Element templateElement = createElement(new ElementTemplateBuilder("template"));
    Element basicElement = new Element("basic");
    basicElement.appendChild(templateElement);
    Element child = basicElement.getChild(0);
    Assert.assertEquals("template", child.getTag());
    Assert.assertEquals(templateElement, child);
    Element parent = templateElement.getParent();
    Assert.assertEquals("basic", parent.getTag());
    Assert.assertEquals(basicElement, parent);
}
Also used : Element(com.vaadin.flow.dom.Element) ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Test(org.junit.Test)

Example 9 with ElementTemplateBuilder

use of com.vaadin.flow.template.angular.ElementTemplateBuilder 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()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider) Test(org.junit.Test)

Example 10 with ElementTemplateBuilder

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

the class TemplateElementStateProviderTest method testElementSubProperty.

@Test
public void testElementSubProperty() {
    String modelPath = "bean.name";
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("prop", new ModelValueBindingProvider(modelPath));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    ModelMap.get(stateNode).resolveModelMap("bean").setValue("name", "John");
    Assert.assertEquals("John", element.getProperty("prop"));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Aggregations

ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)12 Test (org.junit.Test)11 Element (com.vaadin.flow.dom.Element)10 StateNode (com.vaadin.flow.internal.StateNode)4 ModelValueBindingProvider (com.vaadin.flow.template.angular.ModelValueBindingProvider)4 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)4 TextTemplateBuilder (com.vaadin.flow.template.angular.TextTemplateBuilder)2 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)1 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)1 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)1 JsonObject (elemental.json.JsonObject)1 Optional (java.util.Optional)1