Search in sources :

Example 21 with TemplateNode

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

the class TemplateElementStateProviderTest method setProperty_regularProperty_hasPropertyAndHasProperValue.

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

Example 22 with TemplateNode

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

the class TemplateElementStateProviderTest method setRegularProperty_templateHasBoundProperty_hasPropertyAndHasProperValue.

@Test
public void setRegularProperty_templateHasBoundProperty_hasPropertyAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div [foo]='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("prop", "foo");
    Assert.assertTrue(element.hasProperty("prop"));
    Assert.assertEquals("foo", element.getProperty("prop"));
    Set<String> props = element.getPropertyNames().collect(Collectors.toSet());
    Assert.assertEquals(2, props.size());
    Assert.assertTrue(props.contains("foo"));
    Assert.assertTrue(props.contains("prop"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 23 with TemplateNode

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

the class TemplateElementStateProviderTest method removeRegularProperty_templateHasBoundProperty_hasPropertyAndHasProperValue.

@Test
public void removeRegularProperty_templateHasBoundProperty_hasPropertyAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div [foo]='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("prop", "foo");
    element.removeProperty("prop");
    Assert.assertFalse(element.hasProperty("prop"));
    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)

Example 24 with TemplateNode

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

the class TemplateElementStateProviderTest method setAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode.

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

Example 25 with TemplateNode

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

the class TemplateElementStateProviderTest method removeAttribute_regularAttribute_hasNoAttribute.

@Test
public void removeAttribute_regularAttribute_hasNoAttribute() {
    TemplateNode node = TemplateParser.parse("<div></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)

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