Search in sources :

Example 11 with TemplateNode

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

the class AngularTemplateParserTest method ngForElement.

@Test
public void ngForElement() {
    TemplateNode node = parse("<div><a class='item' *ngFor='let  item      of list'>{{item.text}}</a></div>");
    ForTemplateNode forNode = (ForTemplateNode) node.getChild(0);
    Assert.assertEquals("list", forNode.getCollectionVariable());
    Assert.assertEquals("item", forNode.getLoopVariable());
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) ForTemplateNode(com.vaadin.flow.template.angular.ForTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) ForTemplateNode(com.vaadin.flow.template.angular.ForTemplateNode) Test(org.junit.Test)

Example 12 with TemplateNode

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

the class AngularTemplateParserTest method parseChildSlot.

@Test
public void parseChildSlot() {
    // intentional whitespace
    TemplateNode rootNode = parse("<div> @child@</div>");
    Assert.assertEquals(2, rootNode.getChildCount());
    Assert.assertEquals(TextTemplateNode.class, rootNode.getChild(0).getClass());
    TemplateNode childSlot = rootNode.getChild(1);
    Assert.assertEquals(ChildSlotNode.class, childSlot.getClass());
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) ForTemplateNode(com.vaadin.flow.template.angular.ForTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Test(org.junit.Test)

Example 13 with TemplateNode

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

the class ForElementTemplateNodeTest method noChildren.

@Test
public void noChildren() {
    TemplateNode templateNode = parse("<div><li *ngFor='let item of items'></li></div>");
    Element div = getElement(templateNode);
    StateNode model = createModel(div, "items");
    Assert.assertEquals(1, templateNode.getGeneratedElementCount(model));
    Assert.assertEquals(0, templateNode.getChild(0).getGeneratedElementCount(model));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 14 with TemplateNode

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

the class ForElementTemplateNodeTest method oneChildNoDataBinding.

@Test
public void oneChildNoDataBinding() {
    TemplateNode divTemplateNode = parse("<div><li *ngFor='let item of items' foo='static' /></div>");
    Element div = getElement(divTemplateNode);
    TemplateNode forTemplateNode = divTemplateNode.getChild(0);
    StateNode model = createModel(div, "items", Collections.emptyMap());
    Assert.assertEquals(1, forTemplateNode.getGeneratedElementCount(model));
    Assert.assertEquals(1, div.getChildCount());
    Element li = div.getChild(0);
    Assert.assertEquals("static", li.getAttribute("foo"));
    Assert.assertEquals(div, li.getParent());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 15 with TemplateNode

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

the class ForElementTemplateNodeTest method twoChildrenWithTextBinding.

@Test
public void twoChildrenWithTextBinding() {
    TemplateNode divTemplateNode = parse("<div><li *ngFor='let item of items' foo='static'>{{item.text}}</li></div>");
    TemplateNode templateNode = divTemplateNode.getChild(0);
    Element div = getElement(divTemplateNode);
    Map<String, String> data1 = new HashMap<>();
    data1.put("text", "textValue1");
    Map<String, String> data2 = new HashMap<>();
    data2.put("text", "textValue2");
    StateNode model = createModel(div, "items", data1, data2);
    Assert.assertEquals(2, templateNode.getGeneratedElementCount(model));
    Assert.assertEquals("textValue1", templateNode.getElement(0, model).getText());
    Assert.assertEquals("textValue2", templateNode.getElement(1, model).getText());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) HashMap(java.util.HashMap) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) 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