Search in sources :

Example 56 with StateNode

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

the class MapPropertyTest method setValue_updateFromServerIsApplied_syncToServerUpdatesValue.

@Test
public void setValue_updateFromServerIsApplied_syncToServerUpdatesValue() {
    TestTree tree = new TestTree();
    StateNode node = new StateNode(7, tree);
    MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo");
    property.setValue("bar");
    Reactive.flush();
    property.syncToServer("baz");
    Assert.assertEquals("baz", property.getValue());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) Test(org.junit.Test)

Example 57 with StateNode

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

the class MapPropertyTest method setValue_updateFromServerIsNoCompleted_syncToServerDoesntUpdateValue.

@Test
public void setValue_updateFromServerIsNoCompleted_syncToServerDoesntUpdateValue() {
    TestTree tree = new TestTree();
    StateNode node = new StateNode(7, tree);
    MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo");
    property.setValue("bar");
    property.syncToServer("baz");
    Assert.assertEquals("bar", property.getValue());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) Test(org.junit.Test)

Example 58 with StateNode

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

the class MapPropertyTest method removeValue_updateFromServerIsApplied_syncToServerUpdatesValue.

@Test
public void removeValue_updateFromServerIsApplied_syncToServerUpdatesValue() {
    TestTree tree = new TestTree();
    StateNode node = new StateNode(7, tree);
    MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo");
    property.setValue("bar");
    property.removeValue();
    Reactive.flush();
    property.syncToServer("baz");
    Assert.assertEquals("baz", property.getValue());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) Test(org.junit.Test)

Example 59 with StateNode

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

the class NodeMapTest method getProperty_returnPropertyWhichAlwaysUpdatesTheValue.

@Test
public void getProperty_returnPropertyWhichAlwaysUpdatesTheValue() {
    NodeMap map = new NodeMap(NodeFeatures.ELEMENT_PROPERTIES, new StateNode(0, new StateTree(null)));
    MapProperty property = map.getProperty("innerHTML");
    AtomicReference<MapPropertyChangeEvent> capture = new AtomicReference<>();
    property.addChangeListener(capture::set);
    property.setValue("foo");
    Assert.assertNotNull(capture.get());
    // reset
    capture.set(null);
    // set the same value again
    property.setValue("foo");
    Assert.assertNotNull(capture.get());
}
Also used : StateTree(com.vaadin.client.flow.StateTree) StateNode(com.vaadin.client.flow.StateNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 60 with StateNode

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

the class InitialPropertiesHandlerTest method flushPropertyUpdates_updateIsNotInProgress_collectInitialProperties.

@Test
public void flushPropertyUpdates_updateIsNotInProgress_collectInitialProperties() {
    Mockito.when(tree.isUpdateInProgress()).thenReturn(false);
    StateNode node = new StateNode(1, tree);
    NodeMap properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty serverSidePropertyUpdatedByClient = properties.getProperty("foo");
    serverSidePropertyUpdatedByClient.setValue("bar");
    MapProperty serverSideProperty = properties.getProperty("other");
    serverSideProperty.setValue("value");
    handler.nodeRegistered(node);
    Mockito.when(tree.getNode(node.getId())).thenReturn(node);
    handler.flushPropertyUpdates();
    serverSidePropertyUpdatedByClient.setValue("updated");
    MapProperty clientSideProperty = properties.getProperty("client");
    clientSideProperty.setValue("baz");
    handler.handlePropertyUpdate(serverSidePropertyUpdatedByClient);
    handler.handlePropertyUpdate(clientSideProperty);
    Reactive.flush();
    Assert.assertEquals("bar", properties.getProperty("foo").getValue());
    Assert.assertEquals("value", properties.getProperty("other").getValue());
    Assert.assertEquals("baz", properties.getProperty("client").getValue());
    Mockito.verify(tree, Mockito.times(0)).sendNodePropertySyncToServer(serverSidePropertyUpdatedByClient);
    Mockito.verify(tree, Mockito.times(0)).sendNodePropertySyncToServer(serverSideProperty);
    Mockito.verify(tree).sendNodePropertySyncToServer(clientSideProperty);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Aggregations

StateNode (com.vaadin.client.flow.StateNode)73 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)21 Element (elemental.dom.Element)21 Test (org.junit.Test)16 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)14 Node (elemental.dom.Node)13 JsonObject (elemental.json.JsonObject)11 StateTree (com.vaadin.client.flow.StateTree)9 DomNode (com.vaadin.client.flow.dom.DomNode)9 NodeList (com.vaadin.client.flow.nodefeature.NodeList)7 JsonValue (elemental.json.JsonValue)5 ExistingElementMap (com.vaadin.client.ExistingElementMap)4 JsArray (com.vaadin.client.flow.collection.JsArray)4 NativeFunction (com.vaadin.client.flow.util.NativeFunction)4 JsonArray (elemental.json.JsonArray)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 Command (com.vaadin.client.Command)2 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)2