Search in sources :

Example 41 with TemplateNode

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

the class TemplateElementStateProviderTest method setRegularAttribute_templateHasDifferentAttribute_hasAttributeAndHasProperValue.

@Test
public void setRegularAttribute_templateHasDifferentAttribute_hasAttributeAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div foo='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("attr", "foo");
    Assert.assertTrue(element.hasAttribute("attr"));
    Assert.assertTrue(element.hasAttribute("foo"));
    Assert.assertEquals("foo", element.getAttribute("attr"));
    Assert.assertEquals("bar", element.getAttribute("foo"));
    Set<String> attrs = element.getAttributeNames().collect(Collectors.toSet());
    Assert.assertEquals(2, attrs.size());
    Assert.assertTrue(attrs.contains("foo"));
    Assert.assertTrue(attrs.contains("attr"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 42 with TemplateNode

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

the class TemplateElementStateProviderTest method removeAttribute_regularAttributeAndTemplateHasChildren_hasNoAttributeAndNoException.

@Test
public void removeAttribute_regularAttributeAndTemplateHasChildren_hasNoAttributeAndNoException() {
    TemplateNode node = TemplateParser.parse("<div><span></span></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("attr", "foo");
    element.removeAttribute("attr");
    Assert.assertFalse(element.hasAttribute("attr"));
    List<String> props = element.getAttributeNames().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)

Example 43 with TemplateNode

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

the class TemplateElementStateProviderTest method setRegularAttribute_templateHasAttribute_hasAttributeAndHasProperValue.

@Test
public void setRegularAttribute_templateHasAttribute_hasAttributeAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div foo='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("foo", "newValue");
    Assert.assertTrue(element.hasAttribute("foo"));
    Assert.assertEquals("newValue", element.getAttribute("foo"));
    Set<String> attrs = element.getAttributeNames().collect(Collectors.toSet());
    Assert.assertEquals(1, attrs.size());
    Assert.assertTrue(attrs.contains("foo"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 44 with TemplateNode

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

the class TemplateElementStateProviderTest method setAttribute_regularAttributeAndTemplateHasChildren_hasAttributeAndHasProperValueAndNoException.

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

Example 45 with TemplateNode

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

the class TemplateElementStateProviderTest method setRegularProperty_templateHasAttribute_hasPropertyAndHasProperValue.

@Test
public void setRegularProperty_templateHasAttribute_hasPropertyAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div foo='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("foo", "newValue");
    Assert.assertTrue(element.hasProperty("foo"));
    Assert.assertEquals("newValue", element.getProperty("foo"));
    Set<String> props = element.getPropertyNames().collect(Collectors.toSet());
    Assert.assertEquals(1, props.size());
    Assert.assertTrue(props.contains("foo"));
}
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