use of com.vaadin.client.flow.StateNode 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.StateNode in project flow by vaadin.
the class GwtTemplateBinderTest method testUnregisterOverrideNode.
public void testUnregisterOverrideNode() {
int id = 83;
StateNode overrideNode = createSimpleOverrideNode(id, 2);
// Must register so that we can fire an unregister event later on
tree.registerNode(stateNode);
tree.registerNode(overrideNode);
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
MapProperty idProperty = overrideNode.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("id");
idProperty.setValue("override");
Element element = createElement(templateNode, id);
Reactive.flush();
tree.unregisterNode(stateNode);
tree.unregisterNode(overrideNode);
Reactive.flush();
// Updating override node after unregistering the nodes should not
// cause the element to update
idProperty.setValue("new");
Reactive.flush();
assertEquals("override", element.getId());
}
use of com.vaadin.client.flow.StateNode in project flow by vaadin.
the class GwtTemplateBinderTest method createSimpleOverrideNode.
private StateNode createSimpleOverrideNode(int mainNodeTemplateId, int overrideNodeId) {
StateNode overrideNode = new StateNode(overrideNodeId, tree);
// make it recognizable as an override element
overrideNode.getMap(NodeFeatures.OVERRIDE_DATA);
stateNode.getMap(NodeFeatures.TEMPLATE_OVERRIDES).getProperty(String.valueOf(mainNodeTemplateId)).setValue(overrideNode);
return overrideNode;
}
use of com.vaadin.client.flow.StateNode 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.StateNode in project flow by vaadin.
the class GwtTemplateBinderTest method testChildSlotAfterUnregister.
public void testChildSlotAfterUnregister() {
StateNode childContentNode = new StateNode(79, stateNode.getTree());
// Must register so that we can fire an unregister event later on
tree.registerNode(stateNode);
tree.registerNode(childContentNode);
TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
TestTemplateNode childSlot = TestTemplateNode.create(ChildSlotNode.TYPE);
int childId = 67;
registry.getTemplateRegistry().register(childId, childSlot);
templateNode.setChildrenIds(new double[] { childId });
childContentNode.getMap(NodeFeatures.ELEMENT_DATA).getProperty(NodeProperties.TAG).setValue("span");
stateNode.getMap(NodeFeatures.TEMPLATE).getProperty(TemplateMap.CHILD_SLOT_CONTENT).setValue(childContentNode);
Reactive.flush();
Element element = createElement(templateNode);
assertEquals(1, element.getChildNodes().getLength());
tree.unregisterNode(stateNode);
tree.unregisterNode(childContentNode);
Reactive.flush();
stateNode.getMap(NodeFeatures.TEMPLATE).getProperty(TemplateMap.CHILD_SLOT_CONTENT).setValue(null);
Reactive.flush();
// Emptying child slot should have not effect when node is unregistered
assertEquals(1, element.getChildNodes().getLength());
}
Aggregations