Search in sources :

Example 1 with FlushListener

use of com.vaadin.client.flow.reactive.FlushListener in project flow by vaadin.

the class InitialPropertiesHandlerTest method flushPropertyUpdates_updateIsNotInProgress_flushForEechProperty.

@Test
public void flushPropertyUpdates_updateIsNotInProgress_flushForEechProperty() {
    Mockito.when(tree.isUpdateInProgress()).thenReturn(false);
    StateNode node = new StateNode(1, tree);
    NodeMap properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty property1 = properties.getProperty("foo");
    property1.setValue("bar");
    MapProperty property2 = properties.getProperty("other");
    property2.setValue("value");
    handler.nodeRegistered(node);
    Mockito.when(tree.getNode(node.getId())).thenReturn(node);
    handler.flushPropertyUpdates();
    property1.setValue("baz");
    property2.setValue("foo");
    handler.handlePropertyUpdate(property1);
    handler.handlePropertyUpdate(property2);
    AtomicInteger count = new AtomicInteger();
    FlushListener listener = () -> count.incrementAndGet();
    property1.addChangeListener(event -> Reactive.addFlushListener(listener));
    property2.addChangeListener(event -> Reactive.addFlushListener(listener));
    Reactive.flush();
    Assert.assertEquals(2, count.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FlushListener(com.vaadin.client.flow.reactive.FlushListener) 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)1 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)1 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)1 FlushListener (com.vaadin.client.flow.reactive.FlushListener)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1