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());
}
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());
}
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));
}
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());
}
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());
}
Aggregations