use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testBindOverrideNode_attributes_afterBind.
public void testBindOverrideNode_attributes_afterBind() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
int id = 45;
StateNode overrideNode = createSimpleOverrideNode(id);
Element element = createElement(templateNode, id);
NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
props.getProperty("foo").setValue("bar");
Reactive.flush();
assertEquals("bar", element.getAttribute("foo"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testUnregister_textBinsingUpdateIsNotDone.
public void testUnregister_textBinsingUpdateIsNotDone() {
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);
assertEquals("", domNode.getTextContent());
stateNode.unregister();
Reactive.flush();
assertEquals("", domNode.getTextContent());
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method createNgForModelNode.
/**
* Creates 3 children for the {@code parent}: the first one is defined via
* the {@code firstChildTag}, the second is defined via the {@code ngForTag}
* (this is the template which represents *ngFor) and the
* {@code lastChildTag} defines the third child.
* <p>
* {@code collectionVar} is an outer scope collection variable name and
* {@code textVar} is text template parameter name. It's used inside *ngFor
* template.
* <p>
* So the result is:
*
* <pre>
* parent
* |
* ________________________________________________________
* | | |
* <firstChildTag> <ngForTag>{{textVar}}</ngForTag> <lastChildTag>
* </pre>
*/
private StateNode createNgForModelNode(TestElementTemplateNode parent, String firstChildTag, String ngForTag, String lastChildTag, String collectionVar, String textVar) {
TestElementTemplateNode child1 = TestElementTemplateNode.create(firstChildTag);
int child1Id = 57;
registry.getTemplateRegistry().register(child1Id, child1);
TestForTemplateNode templateNode = TestTemplateNode.create(ForTemplateNode.TYPE);
int templateId = 42;
registry.getTemplateRegistry().register(templateId, templateNode);
TestElementTemplateNode forChild = TestElementTemplateNode.create(ngForTag);
templateNode.setCollectionVariable(collectionVar);
TestTextTemplate text = TestTextTemplate.create(TestBinding.createTextValueBinding(textVar));
int textChildId = 85;
registry.getTemplateRegistry().register(textChildId, text);
forChild.setChildrenIds(new double[] { textChildId });
int forChildId = 11;
registry.getTemplateRegistry().register(forChildId, forChild);
templateNode.setChildrenIds(new double[] { forChildId });
TestElementTemplateNode child2 = TestElementTemplateNode.create(lastChildTag);
int child2Id = 84;
registry.getTemplateRegistry().register(child2Id, child2);
parent.setChildrenIds(new double[] { child1Id, templateId, child2Id });
NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
MapProperty property = model.getProperty(collectionVar);
StateNode modelNode = new StateNode(1, tree);
property.setValue(modelNode);
return modelNode;
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testAttributeBindingNoValueTemplate.
public void testAttributeBindingNoValueTemplate() {
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
templateNode.addAttribute("attr", TestBinding.createBinding(ModelValueBindingProvider.TYPE, MODEL_KEY));
Element domNode = createElement(templateNode);
NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
map.getProperty(MODEL_KEY).setValue(null);
Reactive.flush();
assertEquals(null, domNode.getAttribute("attr"));
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtTemplateBinderTest method testNgFor_updateModel.
public void testNgFor_updateModel() {
TestElementTemplateNode parent = TestElementTemplateNode.create("div");
String textVar = "text";
String collectionVar = "items";
// create 3 children for the parent: <div/><li
// *ngFor>{{text}}</li><span/>
StateNode modelNode = createNgForModelNode(parent, "div", "li", "span", collectionVar, textVar);
StateNode varNode = new StateNode(2, tree);
varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("foo");
modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST).add(0, varNode);
Element element = createElement(parent);
Reactive.flush();
NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
MapProperty property = model.getProperty(collectionVar);
modelNode = new StateNode(3, tree);
property.setValue(modelNode);
varNode = new StateNode(4, tree);
varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("bar");
modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST).add(0, varNode);
Reactive.flush();
assertEquals("DIV", element.getTagName());
NodeList childNodes = element.getChildNodes();
assertTrue(childNodes.getLength() > 1);
assertEquals("DIV", ((Element) childNodes.item(0)).getTagName());
assertEquals("SPAN", ((Element) childNodes.item(childNodes.getLength() - 1)).getTagName());
Element li = ((Element) childNodes.item(childNodes.getLength() - 2));
assertEquals("LI", li.getTagName());
assertEquals(4, childNodes.getLength());
// comment
assertEquals(Node.COMMENT_NODE, childNodes.item(1).getNodeType());
assertEquals("bar", li.getTextContent());
}
Aggregations