Search in sources :

Example 16 with TemplateNode

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

the class ForElementTemplateNodeTest method oneChildWithTextBinding.

@Test
public void oneChildWithTextBinding() {
    TemplateNode divTemplateNode = parse("<div><li *ngFor='let item of items' foo='static'>{{item.text}}</li></div>");
    TemplateNode forTemplateNode = divTemplateNode.getChild(0);
    Element div = getElement(divTemplateNode);
    Map<String, String> data = new HashMap<>();
    data.put("text", "textValue");
    StateNode model = createModel(div, "items", data);
    Assert.assertEquals(1, forTemplateNode.getGeneratedElementCount(model));
    Assert.assertEquals("textValue", forTemplateNode.getElement(0, 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)

Example 17 with TemplateNode

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

the class TemplateElementStateProviderTest method removeAttribute_templateHasBoundAttribute_hasNoAttributeAndHasBoundAttribute.

@Test
public void removeAttribute_templateHasBoundAttribute_hasNoAttributeAndHasBoundAttribute() {
    TemplateNode node = TemplateParser.parse("<div [attr.foo]='bar' attr='foo'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.removeAttribute("attr");
    Assert.assertFalse(element.hasAttribute("attr"));
    Assert.assertTrue(element.hasAttribute("foo"));
    List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
    Assert.assertEquals(1, attrs.size());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 18 with TemplateNode

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

the class TemplateElementStateProviderTest method removeAttribute_templateHasAttribute_hasNoAttribute.

@Test
public void removeAttribute_templateHasAttribute_hasNoAttribute() {
    TemplateNode node = TemplateParser.parse("<div foo='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.removeAttribute("foo");
    Assert.assertFalse(element.hasAttribute("foo"));
    List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
    Assert.assertEquals(0, attrs.size());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 19 with TemplateNode

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

the class TemplateElementStateProviderTest method getBoundAttribute_setRegularAttribute_hasAttributeAndHasProperValue.

@Test
public void getBoundAttribute_setRegularAttribute_hasAttributeAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div [attr.attr]='foo'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("foo", "bar");
    element.getNode().getFeature(ModelMap.class).setValue("foo", "someValue");
    Assert.assertTrue(element.hasAttribute("foo"));
    Assert.assertTrue(element.hasAttribute("attr"));
    Assert.assertEquals("bar", element.getAttribute("foo"));
    Assert.assertEquals("someValue", element.getAttribute("attr"));
    List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
    Assert.assertEquals(2, attrs.size());
    Assert.assertTrue(attrs.contains("attr"));
    Assert.assertTrue(attrs.contains("foo"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) Test(org.junit.Test)

Example 20 with TemplateNode

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

the class TemplateElementStateProviderTest method removeProperty_templateHasAttribute_hasNoProperty.

@Test
public void removeProperty_templateHasAttribute_hasNoProperty() {
    TemplateNode node = TemplateParser.parse("<div foo='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    Assert.assertFalse(element.hasProperty("foo"));
    element.setProperty("foo", "bar");
    element.removeProperty("foo");
    Assert.assertFalse(element.hasProperty("foo"));
    List<String> props = element.getPropertyNames().collect(Collectors.toList());
    Assert.assertEquals(0, props.size());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

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