use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testServerEventHandlerInNgFor.
public void testServerEventHandlerInNgFor() {
TestElementTemplateNode parent = TestElementTemplateNode.create("div");
String operation = "operation";
// ============= create <li *ngFor> ===============================
String collectionVar = "items";
TestForTemplateNode templateNode = TestTemplateNode.create(ForTemplateNode.TYPE);
int templateId = 42;
registry.getTemplateRegistry().register(templateId, templateNode);
TestElementTemplateNode forChild = TestElementTemplateNode.create("li");
templateNode.setCollectionVariable(collectionVar);
forChild.addEventHandler("click", "$server." + operation + "()");
int forChildId = 11;
registry.getTemplateRegistry().register(forChildId, forChild);
templateNode.setChildrenIds(new double[] { forChildId });
parent.setChildrenIds(new double[] { templateId });
NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
MapProperty property = model.getProperty(collectionVar);
StateNode modelNode = new StateNode(1, tree);
property.setValue(modelNode);
// ================== now modelNode is NG FOR model node ==========
StateNode varNode = new StateNode(2, tree);
com.vaadin.client.flow.nodefeature.NodeList modelList = modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST);
// add one item to the "collection" model
modelList.add(0, varNode);
stateNode.getList(NodeFeatures.CLIENT_DELEGATE_HANDLERS).set(0, operation);
Element element = createElement(parent);
Reactive.flush();
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.getElementsByTagName("li").item(0).dispatchEvent(event);
assertEquals(1, serverMethods.size());
assertNotNull(serverMethods.get(operation));
assertEquals(stateNode.getId(), serverRpcNodes.get(operation).getId());
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testBindOverrideNode_properties_beforeBind.
public void testBindOverrideNode_properties_beforeBind() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
int id = 83;
StateNode overrideNode = createSimpleOverrideNode(id);
NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
props.getProperty("foo").setValue("bar");
Element element = createElement(templateNode, id);
Reactive.flush();
assertEquals("bar", WidgetUtil.getJsProperty(element, "foo"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testUpdateTextValueTemplate.
public void testUpdateTextValueTemplate() {
TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY));
NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
map.getProperty(MODEL_KEY).setValue("foo");
Node domNode = createText(templateNode);
Reactive.flush();
map.getProperty(MODEL_KEY).setValue("bar");
Reactive.flush();
assertEquals("bar", domNode.getTextContent());
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testBindOverrideNode_attributes_beforeBind.
public void testBindOverrideNode_attributes_beforeBind() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
int id = 48;
StateNode overrideNode = createSimpleOverrideNode(id);
NodeMap attrs = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
attrs.getProperty("foo").setValue("bar");
Element element = createElement(templateNode, id);
Reactive.flush();
assertEquals("bar", element.getAttribute("foo"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testTextValueTemplate.
public void testTextValueTemplate() {
TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY));
NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
map.getProperty(MODEL_KEY).setValue("foo");
Node domNode = createText(templateNode);
Reactive.flush();
assertEquals("foo", domNode.getTextContent());
}
Aggregations