Search in sources :

Example 31 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class PolymerTemplateTest method doParseTemplte_hasChildTemplateOutsideDomRepeat_elementIsCreated.

private void doParseTemplte_hasChildTemplateOutsideDomRepeat_elementIsCreated(TemplateWithDomRepeat template) {
    UI ui = new UI();
    ui.add(template);
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    List<StateNode> templateNodes = new ArrayList<>();
    feature.forEachChild(templateNodes::add);
    assertEquals(1, templateNodes.size());
}
Also used : UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 32 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementJsonProperties.

@Test
public void testElementJsonProperties() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    JsonObject json = Json.createObject();
    json.put("foo", "bar");
    ModelMap.get(stateNode).setValue("key", json);
    Assert.assertEquals(json, element.getPropertyRaw("a"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Example 33 with StateNode

use of com.vaadin.flow.internal.StateNode 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 34 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementDoubleProperties.

@Test
public void testElementDoubleProperties() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    ModelMap.get(stateNode).setValue("key", 1.1d);
    Assert.assertEquals(1.1d, element.getPropertyRaw("a"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Example 35 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class TemplateElementStateProviderTest method setProperty_regularProperty_elementDelegatesPropertyToOverrideNode.

@Test
public void setProperty_regularProperty_elementDelegatesPropertyToOverrideNode() {
    TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("prop", "foo");
    StateNode overrideNode = element.getNode().getFeature(TemplateOverridesMap.class).get(node, false);
    Assert.assertTrue(BasicElementStateProvider.get().hasProperty(overrideNode, "prop"));
    Assert.assertEquals("foo", BasicElementStateProvider.get().getProperty(overrideNode, "prop"));
    List<String> props = BasicElementStateProvider.get().getPropertyNames(overrideNode).collect(Collectors.toList());
    Assert.assertEquals(1, props.size());
    Assert.assertEquals("prop", props.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)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)196 Test (org.junit.Test)122 Element (com.vaadin.flow.dom.Element)32 JsonObject (elemental.json.JsonObject)24 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)22 UI (com.vaadin.flow.component.UI)19 StateTree (com.vaadin.flow.internal.StateTree)18 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ArrayList (java.util.ArrayList)18 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)17 Serializable (java.io.Serializable)17 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)9 VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9