Search in sources :

Example 1 with TestElementTemplateNode

use of com.vaadin.client.flow.template.TestElementTemplateNode in project flow by vaadin.

the class GwtBasicElementBinderTest method testAddTemplateChild.

public void testAddTemplateChild() {
    final int templateId = 43;
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("child");
    TemplateRegistry templates = new TemplateRegistry();
    templates.register(templateId, templateNode);
    Registry registry = new Registry() {

        {
            set(TemplateRegistry.class, templates);
            set(ExistingElementMap.class, new ExistingElementMap());
        }
    };
    StateTree stateTree = new StateTree(registry);
    StateNode templateStateNode = new StateNode(345, stateTree);
    templateStateNode.getMap(NodeFeatures.TEMPLATE).getProperty(NodeProperties.ROOT_TEMPLATE_ID).setValue(Double.valueOf(templateId));
    StateNode parentElementNode = new StateNode(94, stateTree);
    parentElementNode.getMap(NodeFeatures.ELEMENT_DATA).getProperty(NodeProperties.TAG).setValue("div");
    parentElementNode.getList(NodeFeatures.ELEMENT_CHILDREN).add(0, templateStateNode);
    Element element = Browser.getDocument().createElement("div");
    Binder.bind(parentElementNode, element);
    Reactive.flush();
    assertEquals(1, element.getChildElementCount());
    assertEquals("CHILD", element.getFirstElementChild().getTagName());
}
Also used : TemplateRegistry(com.vaadin.client.flow.template.TemplateRegistry) TestElementTemplateNode(com.vaadin.client.flow.template.TestElementTemplateNode) Element(elemental.dom.Element) ExistingElementMap(com.vaadin.client.ExistingElementMap) Registry(com.vaadin.client.Registry) TemplateRegistry(com.vaadin.client.flow.template.TemplateRegistry)

Aggregations

ExistingElementMap (com.vaadin.client.ExistingElementMap)1 Registry (com.vaadin.client.Registry)1 TemplateRegistry (com.vaadin.client.flow.template.TemplateRegistry)1 TestElementTemplateNode (com.vaadin.client.flow.template.TestElementTemplateNode)1 Element (elemental.dom.Element)1