use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class GwtPolymerModelTest method setupSetMethod.
private void setupSetMethod(Element element, String prefix) {
NativeFunction function = NativeFunction.create("this['" + prefix + "'+arguments[0]]=arguments[1]");
WidgetUtil.setJsProperty(element, "set", function);
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class GwtEventHandlerTest method testPolymerMockedEventHandlerWithEventData.
public void testPolymerMockedEventHandlerWithEventData() {
String methodName = "eventHandler";
String methodId = "handlerId";
String eventData = "event.button";
node.getList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS).add(0, methodName);
node.getMap(NodeFeatures.POLYMER_EVENT_LISTENERS).getProperty(methodName).setValue(methodId);
JsonObject json = Json.createObject();
JsonArray array = Json.createArray();
array.set(0, eventData);
json.put(methodId, array);
node.getTree().getRegistry().getConstantPool().importFromJson(json);
Binder.bind(node, element);
Reactive.flush();
NativeFunction mockedFunction = new NativeFunction("this." + methodName + "({button: 2, altKey: false, clientX: 50, clientY: 100})");
mockedFunction.apply(element, JsCollections.array());
assertEquals("The amount of server methods was not as expected", 1, serverMethods.size());
assertEquals("Expected method did not match", methodName, serverMethods.keySet().iterator().next());
assertEquals("Wrong amount of method arguments", 1, serverMethods.get(methodName).length());
assertEquals("Gotten argument wasn't as expected", "2", serverMethods.get(methodName).get(0).toString());
assertEquals("Method node did not match the expected node.", node, serverRpcNodes.get(methodName));
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class GwtEventHandlerTest method testPolymerMockedEventHandlerWithDefaultImplementation.
public void testPolymerMockedEventHandlerWithDefaultImplementation() {
String methodName = "eventHandler";
node.getList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS).add(0, methodName);
Binder.bind(node, element);
Reactive.flush();
setPrototypeEventHandler(element, methodName);
NativeFunction mockedFunction = new NativeFunction("this." + methodName + "({button: 2}, 'Extra String argument')");
mockedFunction.apply(element, JsCollections.array());
JsonObject expectedResult = Json.createObject();
expectedResult.put("button", 2);
expectedResult.put("result", "Extra String argument");
assertEquals("The amount of server methods was not as expected", 1, serverMethods.size());
assertEquals("Expected method did not match", methodName, serverMethods.keySet().iterator().next());
assertEquals("Wrong amount of method arguments", 2, serverMethods.get(methodName).length());
assertEquals("Gotten argument wasn't as expected", WidgetUtil.toPrettyJson(expectedResult), WidgetUtil.toPrettyJson(WidgetUtil.crazyJsoCast(serverMethods.get(methodName).get(0))));
assertEquals("Method node did not match the expected node.", node, serverRpcNodes.get(methodName));
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class GwtEventHandlerTest method testEventHandlerModelItem.
public void testEventHandlerModelItem() {
String methodName = "eventHandlerModelItem";
String methodId = "handlerModelId";
String eventData = "event.model.item";
node.getList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS).add(0, methodName);
node.getMap(NodeFeatures.POLYMER_EVENT_LISTENERS).getProperty(methodName).setValue(methodId);
JsonObject json = Json.createObject();
JsonArray array = Json.createArray();
array.set(0, eventData);
json.put(methodId, array);
node.getTree().getRegistry().getConstantPool().importFromJson(json);
Binder.bind(node, element);
Reactive.flush();
NativeFunction mockedFunction = new NativeFunction("this." + methodName + "({button: 0, model:{item: {nodeId: 2, value: 'test value'}}})");
mockedFunction.apply(element, JsCollections.array());
assertEquals("The amount of server methods was not as expected", 1, serverMethods.size());
assertEquals("Expected method did not match", methodName, serverMethods.keySet().iterator().next());
assertEquals("Wrong amount of method arguments", 1, serverMethods.get(methodName).length());
assertTrue("Received value was not a JsonObject", serverMethods.get(methodName).get(0) instanceof JsonObject);
JsonObject expectedResult = Json.createObject();
expectedResult.put("nodeId", 2);
assertEquals("Gotten argument wasn't as expected", expectedResult.toJson(), ((JsonObject) serverMethods.get(methodName).get(0)).toJson());
assertEquals("Method node did not match the expected node.", node, serverRpcNodes.get(methodName));
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class GwtEventHandlerTest method testEventHandlerModelItemSingleItem.
public void testEventHandlerModelItemSingleItem() {
String methodName = "eventHandlerSingleModelItem";
String methodId = "handlerSingleModelId";
String eventData = "item";
node.getList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS).add(0, methodName);
node.getMap(NodeFeatures.POLYMER_EVENT_LISTENERS).getProperty(methodName).setValue(methodId);
JsonObject json = Json.createObject();
JsonArray array = Json.createArray();
array.set(0, eventData);
json.put(methodId, array);
node.getTree().getRegistry().getConstantPool().importFromJson(json);
node.setDomNode(element);
Binder.bind(node, element);
// Add the node property for getPolymerPropertyObject functionality
setNodeProperty(node.getDomNode(), eventData, "nodeId", "1");
Reactive.flush();
NativeFunction mockedFunction = new NativeFunction("this." + methodName + "({button: 0})");
mockedFunction.apply(element, JsCollections.array());
assertEquals("The amount of server methods was not as expected", 1, serverMethods.size());
assertEquals("Expected method did not match", methodName, serverMethods.keySet().iterator().next());
assertEquals("Wrong amount of method arguments", 1, serverMethods.get(methodName).length());
assertTrue("Received value was not a JsonObject", serverMethods.get(methodName).get(0) instanceof JsonObject);
JsonObject expectedResult = Json.createObject();
expectedResult.put("nodeId", 1);
assertEquals("Gotten argument wasn't as expected", expectedResult.toJson(), ((JsonObject) serverMethods.get(methodName).get(0)).toJson());
assertEquals("Method node did not match the expected node.", node, serverRpcNodes.get(methodName));
}
Aggregations