Search in sources :

Example 31 with StateNode

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

the class MapPropertyTest method syncToServer_nodeIsInactive_propertyIsNotSent_eventIsFiredAndFlushed.

@Test
public void syncToServer_nodeIsInactive_propertyIsNotSent_eventIsFiredAndFlushed() {
    TestTree tree = new TestTree();
    tree.isActive = false;
    StateNode node = new StateNode(7, tree);
    MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo");
    AtomicReference<MapPropertyChangeEvent> event = new AtomicReference<MapPropertyChangeEvent>();
    property.addChangeListener(event::set);
    AtomicBoolean flushListener = new AtomicBoolean();
    Reactive.addFlushListener(() -> flushListener.set(true));
    property.syncToServer("bar");
    Assert.assertNull(tree.sentProperty);
    Assert.assertNotNull(event.get());
    MapPropertyChangeEvent propertyChangeEvent = event.get();
    Assert.assertNull(propertyChangeEvent.getNewValue());
    Assert.assertTrue(flushListener.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StateNode(com.vaadin.client.flow.StateNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 32 with StateNode

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

the class MapPropertyTest method setValue_updateFromServerIsAppliedViaSyncToServer_syncToServerUpdatesValue.

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

Example 33 with StateNode

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

the class MapPropertyTest method syncToServer_nodeIsActive_propertyIsSent.

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

Example 34 with StateNode

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

the class MapPropertyTest method removeValue_updateFromServerIsNoCompleted_syncToServerDoesntUpdateValue.

@Test
public void removeValue_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.removeValue();
    property.syncToServer("baz");
    Assert.assertNull(property.getValue());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) Test(org.junit.Test)

Example 35 with StateNode

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

the class MapPropertyTest method syncToServer_propertyHasNoValue_propertyIsSync.

@Test
public void syncToServer_propertyHasNoValue_propertyIsSync() {
    TestTree tree = new TestTree();
    StateNode node = new StateNode(11, tree);
    MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo");
    property.syncToServer(null);
    Assert.assertEquals(property, tree.sentProperty);
}
Also used : StateNode(com.vaadin.client.flow.StateNode) 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