Search in sources :

Example 16 with Registry

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

the class ExecuteJavaScriptProcessorTest method execute_nodeParameterIsHidden.

@Test
public void execute_nodeParameterIsHidden() {
    CollectingExecuteJavaScriptProcessor processor = new CollectingExecuteJavaScriptProcessor();
    Registry registry = processor.getRegistry();
    StateNode node = new StateNode(31, registry.getStateTree());
    processor.isBound = false;
    registry.getStateTree().registerNode(node);
    JsonArray json = JsonUtils.createArray(Json.create(JsonCodec.NODE_TYPE), Json.create(node.getId()));
    JsonArray invocation = Stream.of(json, Json.create("$0")).collect(JsonUtils.asArray());
    processor.execute(JsonUtils.createArray(invocation));
    Assert.assertEquals(0, processor.nodeParametersList.size());
    // emulate binding
    JsElement element = new JsElement() {
    };
    node.setDomNode(element);
    processor.isBound = true;
    Reactive.flush();
    Assert.assertEquals(1, processor.nodeParametersList.size());
    Assert.assertEquals(1, processor.nodeParametersList.get(0).size());
    JsMap<Object, StateNode> map = processor.nodeParametersList.get(0);
    StateNode stateNode = map.get(element);
    Assert.assertEquals(node, stateNode);
}
Also used : JsonArray(elemental.json.JsonArray) JsElement(elemental.js.dom.JsElement) JsonObject(elemental.json.JsonObject) Registry(com.vaadin.client.Registry) Test(org.junit.Test)

Example 17 with Registry

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

the class ExecuteJavaScriptProcessorTest method isBound_hasElementHasNoFeatureAndBoundParent_bound.

@Test
public void isBound_hasElementHasNoFeatureAndBoundParent_bound() {
    TestJsProcessor processor = new TestJsProcessor();
    Registry registry = processor.getRegistry();
    StateNode node = new StateNode(37, registry.getStateTree());
    StateNode parent = new StateNode(43, registry.getStateTree());
    node.setParent(parent);
    // emulate binding
    JsElement element = new JsElement() {
    };
    node.setDomNode(element);
    parent.setDomNode(element);
    Assert.assertTrue(processor.isBound(node));
}
Also used : JsElement(elemental.js.dom.JsElement) Registry(com.vaadin.client.Registry) Test(org.junit.Test)

Example 18 with Registry

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

the class ExecuteJavaScriptProcessorTest method execute_nodeParameterIsVirtualChildAwaitingInit.

@Test
public void execute_nodeParameterIsVirtualChildAwaitingInit() {
    CollectingExecuteJavaScriptProcessor processor = new CollectingExecuteJavaScriptProcessor();
    Registry registry = processor.getRegistry();
    StateNode node = new StateNode(11, registry.getStateTree());
    JsonObject object = Json.createObject();
    object.put(NodeProperties.TYPE, NodeProperties.INJECT_BY_ID);
    node.getMap(NodeFeatures.ELEMENT_DATA).getProperty(NodeProperties.PAYLOAD).setValue(object);
    registry.getStateTree().registerNode(node);
    JsonArray json = JsonUtils.createArray(Json.create(JsonCodec.NODE_TYPE), Json.create(node.getId()));
    JsonArray invocation = Stream.of(json, Json.create("$0")).collect(JsonUtils.asArray());
    processor.execute(JsonUtils.createArray(invocation));
    // The invocation has not been executed
    Assert.assertEquals(0, processor.nodeParametersList.size());
    // emulate binding
    JsElement element = new JsElement() {
    };
    node.setDomNode(element);
    Reactive.flush();
    Assert.assertEquals(1, processor.nodeParametersList.size());
    Assert.assertEquals(1, processor.nodeParametersList.get(0).size());
    JsMap<Object, StateNode> map = processor.nodeParametersList.get(0);
    StateNode stateNode = map.get(element);
    Assert.assertEquals(node, stateNode);
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) JsElement(elemental.js.dom.JsElement) JsonObject(elemental.json.JsonObject) Registry(com.vaadin.client.Registry) Test(org.junit.Test)

Aggregations

Registry (com.vaadin.client.Registry)18 Test (org.junit.Test)11 JsElement (elemental.js.dom.JsElement)9 ExistingElementMap (com.vaadin.client.ExistingElementMap)4 JsonArray (elemental.json.JsonArray)4 JsonObject (elemental.json.JsonObject)4 InitialPropertiesHandler (com.vaadin.client.InitialPropertiesHandler)2 UILifecycle (com.vaadin.client.UILifecycle)2 MessageHandler (com.vaadin.client.communication.MessageHandler)2 RequestResponseTracker (com.vaadin.client.communication.RequestResponseTracker)2 ServerConnector (com.vaadin.client.communication.ServerConnector)2 DependencyLoader (com.vaadin.client.DependencyLoader)1 ResourceLoader (com.vaadin.client.ResourceLoader)1 ScrollPositionHandler (com.vaadin.client.ScrollPositionHandler)1 ServerRpcQueue (com.vaadin.client.communication.ServerRpcQueue)1 ConstantPool (com.vaadin.client.flow.ConstantPool)1 StateNode (com.vaadin.client.flow.StateNode)1 StateTree (com.vaadin.client.flow.StateTree)1 JsArray (com.vaadin.client.flow.collection.JsArray)1 TemplateRegistry (com.vaadin.client.flow.template.TemplateRegistry)1