Search in sources :

Example 1 with ModelValueBindingProvider

use of com.vaadin.flow.template.angular.ModelValueBindingProvider in project flow by vaadin.

the class ModelValueBindingTest method getValue.

public void getValue() {
    ModelValueBindingProvider binding = new ModelValueBindingProvider("bar");
    StateNode node = new StateNode(ModelMap.class);
    ModelMap.get(node).setValue("bar", "someValue");
    Assert.assertEquals("someValue", binding.getValue(node));
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider)

Example 2 with ModelValueBindingProvider

use of com.vaadin.flow.template.angular.ModelValueBindingProvider in project flow by vaadin.

the class ModelValueBindingTest method toJson.

@Test
public void toJson() {
    ModelValueBindingProvider binding = new ModelValueBindingProvider("bar");
    JsonValue json = binding.toJson();
    Assert.assertTrue(json instanceof JsonObject);
    JsonObject object = (JsonObject) json;
    Assert.assertEquals(ModelValueBindingProvider.TYPE, object.get(BindingValueProvider.TYPE_PROPERTY).asString());
    Assert.assertEquals("bar", object.get(BindingValueProvider.VALUE_PROPERTY).asString());
}
Also used : JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Example 3 with ModelValueBindingProvider

use of com.vaadin.flow.template.angular.ModelValueBindingProvider in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementJsonProperties.

@Test
public void testElementJsonProperties() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    JsonObject json = Json.createObject();
    json.put("foo", "bar");
    ModelMap.get(stateNode).setValue("key", json);
    Assert.assertEquals(json, element.getPropertyRaw("a"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Example 4 with ModelValueBindingProvider

use of com.vaadin.flow.template.angular.ModelValueBindingProvider in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementDoubleProperties.

@Test
public void testElementDoubleProperties() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    ModelMap.get(stateNode).setValue("key", 1.1d);
    Assert.assertEquals(1.1d, element.getPropertyRaw("a"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Example 5 with ModelValueBindingProvider

use of com.vaadin.flow.template.angular.ModelValueBindingProvider in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementBooleanProperties.

@Test
public void testElementBooleanProperties() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    ModelMap.get(stateNode).setValue("key", Boolean.TRUE);
    Assert.assertEquals(Boolean.TRUE, element.getPropertyRaw("a"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Aggregations

ModelValueBindingProvider (com.vaadin.flow.template.angular.ModelValueBindingProvider)6 StateNode (com.vaadin.flow.internal.StateNode)5 Test (org.junit.Test)5 Element (com.vaadin.flow.dom.Element)4 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)4 JsonObject (elemental.json.JsonObject)2 JsonValue (elemental.json.JsonValue)1