Search in sources :

Example 6 with TemplateNode

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

the class DefaultTextModelBuiderFactoryTest method getNodesAndCheckIncludePath.

private List<TemplateNode> getNodesAndCheckIncludePath(String includeText, boolean verify, String... expected) {
    TestTemplateResolver resolver = new TestTemplateResolver();
    TemplateNode rootNode = TemplateParser.parse("<div>" + includeText + "</div>", resolver);
    List<TemplateNode> nodes = new ArrayList<>();
    for (int i = 0; i < rootNode.getChildCount(); i++) {
        nodes.add(rootNode.getChild(i));
    }
    if (verify) {
        resolver.verify(expected);
    }
    return nodes;
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) ArrayList(java.util.ArrayList)

Example 7 with TemplateNode

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

the class AngularTemplateNodeTest method childElementLookup.

@Test
public void childElementLookup() {
    TemplateNode templateNode = parse("<span><div id='foo'><div></span>");
    Element div = getElement(templateNode).getChild(0);
    Element foundDiv = templateNode.findElement(div.getNode(), "foo").get();
    Assert.assertEquals(div, foundDiv);
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 8 with TemplateNode

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

the class AngularTemplateNodeTest method forLoopElement.

@Test
public void forLoopElement() {
    TemplateNode templateNode = parse("<span><div *ngFor='let item of items' id='foo'><div></span>");
    StateNode node = TemplateElementStateProvider.createRootNode();
    StateNode listNode = new StateNode(ModelList.class);
    ModelMap.get(node).setValue("items", listNode);
    StateNode item1 = TemplateElementStateProvider.createSubModelNode(ModelMap.class);
    StateNode item2 = TemplateElementStateProvider.createSubModelNode(ModelMap.class);
    listNode.getFeature(ModelList.class).add(item1);
    listNode.getFeature(ModelList.class).add(item2);
    Assert.assertEquals(Optional.empty(), templateNode.findElement(node, "foo"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) ModelList(com.vaadin.flow.internal.nodefeature.ModelList) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 9 with TemplateNode

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

the class AngularTemplateNodeTest method elementInIncludedFile.

@Test
public void elementInIncludedFile() {
    MainWithSubTemplate template = new MainWithSubTemplate();
    StateNode stateNode = template.getElement().getNode();
    TemplateNode templateNode = stateNode.getFeature(TemplateMap.class).getRootTemplate();
    Assert.assertEquals("<span id=\"main\">Main template</span>", templateNode.findElement(stateNode, "main").get().getOuterHTML());
    Assert.assertEquals("<span id=\"sub\">Sub template</span>", templateNode.findElement(stateNode, "sub").get().getOuterHTML());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 10 with TemplateNode

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

the class AngularTemplateNodeTest method singleElementLookup.

@Test
public void singleElementLookup() {
    TemplateNode templateNode = parse("<div id='foo'><div>");
    Element div = getElement(templateNode);
    Element foundDiv = templateNode.findElement(div.getNode(), "foo").get();
    Assert.assertEquals(div, foundDiv);
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Aggregations

TemplateNode (com.vaadin.flow.template.angular.TemplateNode)48 Test (org.junit.Test)42 Element (com.vaadin.flow.dom.Element)29 StateNode (com.vaadin.flow.internal.StateNode)18 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)13 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)12 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)11 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)4 HashMap (java.util.HashMap)4 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)3 TemplateMap (com.vaadin.flow.internal.nodefeature.TemplateMap)2 Component (com.vaadin.flow.component.Component)1 UIInternals (com.vaadin.flow.component.internal.UIInternals)1 StateTree (com.vaadin.flow.internal.StateTree)1 MapPutChange (com.vaadin.flow.internal.change.MapPutChange)1 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)1 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)1 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)1 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)1 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)1