Search in sources :

Example 21 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class GwtTemplateBinderTest method testUnregisterOverrideNode.

public void testUnregisterOverrideNode() {
    int id = 83;
    StateNode overrideNode = createSimpleOverrideNode(id, 2);
    // Must register so that we can fire an unregister event later on
    tree.registerNode(stateNode);
    tree.registerNode(overrideNode);
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    MapProperty idProperty = overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("id");
    idProperty.setValue("override");
    Element element = createElement(templateNode, id);
    Reactive.flush();
    tree.unregisterNode(stateNode);
    tree.unregisterNode(overrideNode);
    Reactive.flush();
    // Updating override node after unregistering the nodes should not
    // cause the element to update
    idProperty.setValue("new");
    Reactive.flush();
    assertEquals("override", element.getId());
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode)

Example 22 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class GwtTemplateBinderTest method testClassNameBinding.

public void testClassNameBinding() {
    MapProperty property = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(MODEL_KEY);
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    templateNode.addClassName("static", "true");
    templateNode.addClassName("dynamic", TestBinding.createBinding(ModelValueBindingProvider.TYPE, MODEL_KEY));
    Element element = createElement(templateNode);
    property.setValue(Boolean.TRUE);
    Reactive.flush();
    assertEquals("static dynamic", element.getClassName());
    property.setValue(Boolean.FALSE);
    Reactive.flush();
    assertEquals("static", element.getClassName());
    // Test that the evaluation logic is based on thruthishness instead of
    // strict boolean evaluation
    // trueish value
    property.setValue("yes");
    Reactive.flush();
    assertEquals("static dynamic", element.getClassName());
    // falseish value
    property.setValue("");
    Reactive.flush();
    assertEquals("static", element.getClassName());
    // trueish value
    property.setValue(Double.valueOf(1));
    Reactive.flush();
    assertEquals("static dynamic", element.getClassName());
    property.removeValue();
    Reactive.flush();
    assertEquals("static", element.getClassName());
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Element(elemental.dom.Element)

Example 23 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class GwtPolymerModelTest method testInitialUpdateModelProperty_propertyIsUpdatable_propertyIsSynced.

public void testInitialUpdateModelProperty_propertyIsUpdatable_propertyIsSynced() {
    addMockMethods(element);
    String propertyName = "black";
    String propertyValue = "coffee";
    setModelProperty(node, propertyName, propertyValue);
    node.setNodeData(new UpdatableModelProperties(JsCollections.array(propertyName)));
    Binder.bind(node, element);
    Reactive.flush();
    assertEquals("Expected to have property with name " + propertyName + " defined after initial binding", propertyValue, WidgetUtil.getJsProperty(element, propertyName));
    String newPropertyValue = "bubblegum";
    emulatePolymerPropertyChange(element, propertyName, newPropertyValue);
    Reactive.flush();
    assertEquals("Expected to have property with name " + propertyName + " updated from client side", newPropertyValue, WidgetUtil.getJsProperty(element, propertyName));
    MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty(propertyName);
    assertEquals(newPropertyValue, property.getValue());
    assertEquals(newPropertyValue, tree.synchronizedProperties.get(node).get(propertyName));
}
Also used : UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty)

Example 24 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class PollConfiguratorTest method listensToProperty.

@Test
public void listensToProperty() {
    PollConfigurator.observe(stateTree.getRootNode(), new Poller(registry) {

        @Override
        public void setInterval(int interval) {
            pollerSetIntervalCalled.incrementAndGet();
            pollerInterval.set(interval);
        }
    });
    Assert.assertEquals(-2, pollerInterval.get());
    Assert.assertEquals(0, pollerSetIntervalCalled.get());
    MapProperty pollIntervalProperty = stateTree.getRootNode().getMap(NodeFeatures.POLL_CONFIGURATION).getProperty(PollConfigurationMap.POLL_INTERVAL_KEY);
    pollIntervalProperty.setValue(100.0);
    Assert.assertEquals(100, pollerInterval.get());
    Assert.assertEquals(1, pollerSetIntervalCalled.get());
    pollIntervalProperty.setValue(-1.0);
    Assert.assertEquals(-1, pollerInterval.get());
    Assert.assertEquals(2, pollerSetIntervalCalled.get());
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Test(org.junit.Test)

Example 25 with MapProperty

use of com.vaadin.client.flow.nodefeature.MapProperty in project flow by vaadin.

the class StateTreeTest method sendNodePropertySyncToServer_notInitialProperty_propertyIsSent.

@Test
public void sendNodePropertySyncToServer_notInitialProperty_propertyIsSent() {
    tree.registerNode(node);
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty property = new MapProperty("foo", map);
    property.setValue("bar");
    connector.clear();
    tree.sendNodePropertySyncToServer(property);
    connector.assertMessage(node, "foo", "bar");
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

Aggregations

MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)40 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)18 StateNode (com.vaadin.client.flow.StateNode)12 Test (org.junit.Test)8 Element (elemental.dom.Element)7 JsonObject (elemental.json.JsonObject)6 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)5 JsonValue (elemental.json.JsonValue)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)2 SchedulerImpl (com.google.gwt.core.client.impl.SchedulerImpl)1 Computation (com.vaadin.client.flow.reactive.Computation)1 FlushListener (com.vaadin.client.flow.reactive.FlushListener)1 Node (elemental.dom.Node)1 NodeList (elemental.dom.NodeList)1 Text (elemental.dom.Text)1 EventRemover (elemental.events.EventRemover)1 MouseEvent (elemental.events.MouseEvent)1 JsonArray (elemental.json.JsonArray)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1