Search in sources :

Example 1 with KeyMapper

use of com.vaadin.flow.data.provider.KeyMapper in project flow-components by vaadin.

the class NativeButtonRendererTest method templateRenderered_containerIsDisabled_buttonIsDisabled.

@Test
public void templateRenderered_containerIsDisabled_buttonIsDisabled() {
    NativeButtonRenderer<String> renderer = new NativeButtonRenderer<>("Label");
    Element container = new Element("div");
    KeyMapper<String> keyMapper = new KeyMapper<>();
    Rendering<String> rendering = renderer.render(container, keyMapper);
    mockAttach(renderer, container, rendering, keyMapper);
    Assert.assertTrue("The DataGenerator should be present", rendering.getDataGenerator().isPresent());
    DataGenerator<String> dataGenerator = rendering.getDataGenerator().get();
    JsonObject json = Json.createObject();
    dataGenerator.generateData("something", json);
    Assert.assertFalse("The button shouldn't be disabled", json.getBoolean(renderer.getTemplatePropertyName(rendering) + "_disabled"));
    mockDisabled(container);
    json = Json.createObject();
    dataGenerator.generateData("something", json);
    Assert.assertTrue("The button should be disabled", json.getBoolean(renderer.getTemplatePropertyName(rendering) + "_disabled"));
}
Also used : KeyMapper(com.vaadin.flow.data.provider.KeyMapper) DataKeyMapper(com.vaadin.flow.data.provider.DataKeyMapper) Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

Example 2 with KeyMapper

use of com.vaadin.flow.data.provider.KeyMapper in project flow-components by vaadin.

the class ComponentRendererTest method templateRenderered_parentAttachedBeforeChild.

@Test
public void templateRenderered_parentAttachedBeforeChild() {
    UI ui = new TestUI();
    TestUIInternals internals = (TestUIInternals) ui.getInternals();
    ComponentRenderer<TestDiv, String> renderer = new ComponentRenderer<>(e -> (new TestDiv()));
    Element containerParent = new Element("div");
    Element container = new Element("div");
    KeyMapper<String> keyMapper = new KeyMapper<>();
    ComponentDataGenerator<String> rendering = (ComponentDataGenerator<String>) renderer.render(container, keyMapper);
    // simulate a call from the grid to refresh data - template is not setup
    containerParent.getNode().runWhenAttached(ui2 -> ui2.getInternals().getStateTree().beforeClientResponse(containerParent.getNode(), context -> {
        Assert.assertNotNull("NodeIdPropertyName should not be null", rendering.getNodeIdPropertyName());
        JsonObject value = Json.createObject();
        rendering.generateData("item", value);
        Assert.assertEquals("generateData should add one element in the jsonobject", 1, value.keys().length);
    }));
    // attach the parent (ex: grid) before the child (ex: column)
    attachElement(ui, containerParent);
    attachElement(ui, container);
    internals.getStateTree().runExecutionsBeforeClientResponse();
}
Also used : KeyMapper(com.vaadin.flow.data.provider.KeyMapper) Component(com.vaadin.flow.component.Component) PendingJavaScriptInvocation(com.vaadin.flow.component.internal.PendingJavaScriptInvocation) Json(elemental.json.Json) Test(org.junit.Test) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) UI(com.vaadin.flow.component.UI) UIInternals(com.vaadin.flow.component.internal.UIInternals) Assert(org.junit.Assert) KeyMapper(com.vaadin.flow.data.provider.KeyMapper) Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) UI(com.vaadin.flow.component.UI) Test(org.junit.Test)

Example 3 with KeyMapper

use of com.vaadin.flow.data.provider.KeyMapper in project flow-components by vaadin.

the class ComponentRendererTest method templateRenderered_childAttachedBeforeParent.

@Test
public void templateRenderered_childAttachedBeforeParent() {
    UI ui = new TestUI();
    TestUIInternals internals = (TestUIInternals) ui.getInternals();
    ComponentRenderer<TestDiv, String> renderer = new ComponentRenderer<>(e -> (new TestDiv()));
    Element containerParent = new Element("div");
    Element container = new Element("div");
    KeyMapper<String> keyMapper = new KeyMapper<>();
    ComponentDataGenerator<String> rendering = (ComponentDataGenerator<String>) renderer.render(container, keyMapper);
    containerParent.getNode().runWhenAttached(ui2 -> ui2.getInternals().getStateTree().beforeClientResponse(containerParent.getNode(), context -> {
        // if nodeid is null then the component
        // won't be rendered correctly
        Assert.assertNotNull("NodeIdPropertyName should not be null", rendering.getNodeIdPropertyName());
        JsonObject value = Json.createObject();
        rendering.generateData("item", value);
        Assert.assertEquals("generateData should add one element in the jsonobject", 1, value.keys().length);
    }));
    // attach the child (ex: container) before the parent (ex: grid)
    attachElement(ui, container);
    attachElement(ui, containerParent);
    internals.getStateTree().runExecutionsBeforeClientResponse();
}
Also used : KeyMapper(com.vaadin.flow.data.provider.KeyMapper) Component(com.vaadin.flow.component.Component) PendingJavaScriptInvocation(com.vaadin.flow.component.internal.PendingJavaScriptInvocation) Json(elemental.json.Json) Test(org.junit.Test) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) UI(com.vaadin.flow.component.UI) UIInternals(com.vaadin.flow.component.internal.UIInternals) Assert(org.junit.Assert) KeyMapper(com.vaadin.flow.data.provider.KeyMapper) Element(com.vaadin.flow.dom.Element) JsonObject(elemental.json.JsonObject) UI(com.vaadin.flow.component.UI) Test(org.junit.Test)

Aggregations

KeyMapper (com.vaadin.flow.data.provider.KeyMapper)3 Element (com.vaadin.flow.dom.Element)3 JsonObject (elemental.json.JsonObject)3 Test (org.junit.Test)3 Component (com.vaadin.flow.component.Component)2 UI (com.vaadin.flow.component.UI)2 PendingJavaScriptInvocation (com.vaadin.flow.component.internal.PendingJavaScriptInvocation)2 UIInternals (com.vaadin.flow.component.internal.UIInternals)2 Json (elemental.json.Json)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Assert (org.junit.Assert)2 DataKeyMapper (com.vaadin.flow.data.provider.DataKeyMapper)1