Search in sources :

Example 6 with MouseEvent

use of elemental.events.MouseEvent in project flow by vaadin.

the class GwtTemplateBinderTest method testClientDelegateHandler_noArgs.

public void testClientDelegateHandler_noArgs() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    String operation = "operation";
    templateNode.addEventHandler("click", "$server." + operation + "()");
    stateNode.getList(NodeFeatures.CLIENT_DELEGATE_HANDLERS).set(0, operation);
    Element element = createElement(templateNode);
    MouseEvent event = (MouseEvent) Browser.getDocument().createEvent(Events.MOUSE);
    event.initMouseEvent("click", true, true, Browser.getWindow(), 0, 0, 0, 0, 0, false, false, false, false, 0, element);
    Browser.getDocument().getBody().appendChild(element);
    element.dispatchEvent(event);
    assertEquals(1, serverMethods.size());
    JsArray<?> args = serverMethods.get(operation);
    assertNotNull(args);
    assertEquals(0, args.length());
}
Also used : MouseEvent(elemental.events.MouseEvent) Element(elemental.dom.Element)

Example 7 with MouseEvent

use of elemental.events.MouseEvent in project flow by vaadin.

the class GwtTemplateBinderTest method testClientDelegateHandler_args.

public void testClientDelegateHandler_args() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    String operation = "operation";
    templateNode.addEventHandler("click", "$server." + operation + "($wnd.booleanprop, $wnd.stringprop, $wnd.numberprop, $wnd.objectprop)");
    stateNode.getList(NodeFeatures.CLIENT_DELEGATE_HANDLERS).set(0, operation);
    Element element = createElement(templateNode);
    WidgetUtil.setJsProperty(Browser.getWindow(), "booleanprop", true);
    WidgetUtil.setJsProperty(Browser.getWindow(), "stringprop", "foo");
    WidgetUtil.setJsProperty(Browser.getWindow(), "numberprop", 11);
    JsonObject obj = Json.createObject();
    obj.put("foo", "bar");
    WidgetUtil.setJsProperty(Browser.getWindow(), "objectprop", obj);
    MouseEvent event = (MouseEvent) Browser.getDocument().createEvent(Events.MOUSE);
    event.initMouseEvent("click", true, true, Browser.getWindow(), 0, 0, 0, 0, 0, false, false, false, false, 0, element);
    Browser.getDocument().getBody().appendChild(element);
    element.dispatchEvent(event);
    assertEquals(1, serverMethods.size());
    JsArray<?> args = serverMethods.get(operation);
    assertNotNull(args);
    assertEquals(4, args.length());
    assertEquals(true, args.get(0));
    assertEquals("foo", args.get(1));
    assertEquals(11, args.get(2));
    assertTrue(args.get(3) instanceof JsonObject);
    assertEquals(obj, args.get(3));
}
Also used : MouseEvent(elemental.events.MouseEvent) Element(elemental.dom.Element) JsonObject(elemental.json.JsonObject)

Aggregations

MouseEvent (elemental.events.MouseEvent)7 Element (elemental.dom.Element)5 StateNode (com.vaadin.client.flow.StateNode)1 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)1 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 EventRemover (elemental.events.EventRemover)1 EventTarget (elemental.events.EventTarget)1 JsonObject (elemental.json.JsonObject)1 ArrayList (java.util.ArrayList)1