Search in sources :

Example 16 with StateNode

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

the class ClientDelegteHandlersTest method attach_noFeature.

@Test
public void attach_noFeature() {
    StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
    StateNode stateNode = new StateNode(ClientDelegateHandlers.class);
    tree.getRootNode().getFeature(ElementChildrenList.class).add(stateNode);
    Assert.assertEquals(0, stateNode.getFeature(ClientDelegateHandlers.class).size());
}
Also used : StateTree(com.vaadin.flow.internal.StateTree) UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ElementChildrenList(com.vaadin.flow.internal.nodefeature.ElementChildrenList) Test(org.junit.Test)

Example 17 with StateNode

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

the class ClientDelegteHandlersTest method attach_noComponent.

@Test
public void attach_noComponent() {
    StateTree tree = new StateTree(new UI(), ElementChildrenList.class);
    StateNode stateNode = new StateNode(ComponentMapping.class, ClientDelegateHandlers.class);
    tree.getRootNode().getFeature(ElementChildrenList.class).add(stateNode);
    Assert.assertEquals(0, stateNode.getFeature(ClientDelegateHandlers.class).size());
}
Also used : StateTree(com.vaadin.flow.internal.StateTree) UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ElementChildrenList(com.vaadin.flow.internal.nodefeature.ElementChildrenList) Test(org.junit.Test)

Example 18 with StateNode

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

the class ElementPropertyMapTest method listenerIsNotified.

private void listenerIsNotified(boolean clientEvent) {
    ElementPropertyMap map = createSimplePropertyMap();
    StateNode node = map.getNode();
    AtomicReference<PropertyChangeEvent> event = new AtomicReference<>();
    PropertyChangeListener listener = ev -> {
        Assert.assertNull(event.get());
        event.set(ev);
    };
    map.addPropertyChangeListener("foo", listener);
    map.setProperty("foo", "bar", !clientEvent);
    Assert.assertNull(event.get().getOldValue());
    Assert.assertEquals("bar", event.get().getValue());
    Assert.assertEquals("foo", event.get().getPropertyName());
    Assert.assertEquals(Element.get(node), event.get().getSource());
    Assert.assertEquals(clientEvent, event.get().isUserOriginated());
    // listener is not called. Otherwise its assertion fails.
    map.setProperty("bar", "foo");
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) BasicElementStateProvider(com.vaadin.flow.dom.impl.BasicElementStateProvider) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) Registration(com.vaadin.flow.shared.Registration) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Element(com.vaadin.flow.dom.Element) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent) Assert(org.junit.Assert) PropertyChangeEvent(com.vaadin.flow.dom.PropertyChangeEvent) PropertyChangeListener(com.vaadin.flow.dom.PropertyChangeListener) StateNode(com.vaadin.flow.internal.StateNode) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 19 with StateNode

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

the class ElementPropertyMapTest method resolveModelList_modelListStateNodeHasReportedFeature.

@Test
public void resolveModelList_modelListStateNodeHasReportedFeature() {
    ElementPropertyMap map = createSimplePropertyMap();
    map.resolveModelList("foo");
    StateNode stateNode = (StateNode) map.get("foo");
    Assert.assertTrue(stateNode.isReportedFeature(ModelList.class));
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 20 with StateNode

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

the class ElementPropertyMapTest method childPropertyUpdateFilter_setFilterAfterChild.

@Test
public void childPropertyUpdateFilter_setFilterAfterChild() {
    ElementPropertyMap map = createSimplePropertyMap();
    StateNode child = new StateNode(ElementPropertyMap.class);
    ElementPropertyMap childModel = ElementPropertyMap.getModel(child);
    map.put("foo", child);
    map.setUpdateFromClientFilter("foo.bar"::equals);
    Assert.assertTrue(childModel.mayUpdateFromClient("bar", "a"));
    Assert.assertFalse(childModel.mayUpdateFromClient("baz", "a"));
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)160 Test (org.junit.Test)99 Element (com.vaadin.flow.dom.Element)29 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)19 JsonObject (elemental.json.JsonObject)19 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ArrayList (java.util.ArrayList)14 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)13 Serializable (java.io.Serializable)13 StateTree (com.vaadin.flow.internal.StateTree)10 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 UI (com.vaadin.flow.component.UI)9 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 ChildElementConsumer (com.vaadin.flow.dom.ChildElementConsumer)8 AttachExistingElementFeature (com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature)8 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)8 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)6