use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class StateNodeNodeListTest method testIndexOf.
@Test
public void testIndexOf() {
StateNode one = StateNodeTest.createEmptyNode("one");
StateNode two = StateNodeTest.createEmptyNode("two");
StateNode three = StateNodeTest.createEmptyNode("three");
nodeList.add(one);
nodeList.add(two);
Assert.assertEquals(0, nodeList.indexOf(one));
Assert.assertEquals(1, nodeList.indexOf(two));
Assert.assertEquals(-1, nodeList.indexOf(three));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class VisibilityDataTest method setVisible.
@Test
public void setVisible() {
StateNode node = new StateNode(VisibilityData.class);
VisibilityData data = node.getFeature(VisibilityData.class);
Assert.assertNull(data.getValue());
Assert.assertTrue(data.isVisible());
data.setValue(true);
Assert.assertTrue(data.isVisible());
data.setValue(false);
Assert.assertFalse(data.isVisible());
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AttachExistingElementRpcHandlerTest method handleNode_requestedIdAndAssignedIdAreDifferent.
@Test
public void handleNode_requestedIdAndAssignedIdAreDifferent() {
AttachExistingElementRpcHandler handler = new AttachExistingElementRpcHandler();
int requestedId = 1;
int assignedId = 2;
int index = 3;
JsonObject object = Json.createObject();
object.put(JsonConstants.RPC_ATTACH_REQUESTED_ID, requestedId);
object.put(JsonConstants.RPC_ATTACH_ASSIGNED_ID, assignedId);
object.put(JsonConstants.RPC_ATTACH_TAG_NAME, "div");
object.put(JsonConstants.RPC_ATTACH_INDEX, index);
StateNode node = Mockito.mock(StateNode.class);
StateNode requested = Mockito.mock(StateNode.class);
StateNode assigned = Mockito.mock(StateNode.class);
StateTree tree = Mockito.mock(StateTree.class);
Mockito.when(node.getOwner()).thenReturn(tree);
Mockito.when(tree.getNodeById(requestedId)).thenReturn(requested);
Mockito.when(tree.getNodeById(assignedId)).thenReturn(assigned);
Mockito.when(assigned.hasFeature(Mockito.any())).thenReturn(true);
AttachExistingElementFeature feature = new AttachExistingElementFeature(node);
Node<?> parentNode = Mockito.mock(Node.class);
ChildElementConsumer consumer = Mockito.mock(ChildElementConsumer.class);
Element sibling = Mockito.mock(Element.class);
feature.register(parentNode, sibling, requested, consumer);
Mockito.when(node.getFeature(AttachExistingElementFeature.class)).thenReturn(feature);
handler.handleNode(node, object);
assertNodeIsUnregistered(node, requested, feature);
Mockito.verify(parentNode, Mockito.times(0)).insertChild(index, Element.get(assigned));
Mockito.verify(consumer).accept(Element.get(assigned));
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class AttachTemplateChildRpcHandlerTest method assertHandleNode.
private void assertHandleNode(int assignedId, JsonValue id) {
AttachTemplateChildRpcHandler handler = new AttachTemplateChildRpcHandler();
int requestedId = 1;
JsonObject object = Json.createObject();
object.put(JsonConstants.RPC_ATTACH_REQUESTED_ID, requestedId);
object.put(JsonConstants.RPC_ATTACH_ASSIGNED_ID, assignedId);
object.put(JsonConstants.RPC_ATTACH_ID, id);
StateNode node = Mockito.mock(StateNode.class);
StateNode parentNode = Mockito.mock(StateNode.class);
StateTree tree = Mockito.mock(StateTree.class);
Mockito.when(node.getOwner()).thenReturn(tree);
Mockito.when(node.getParent()).thenReturn(parentNode);
Mockito.when(tree.getNodeById(requestedId)).thenReturn(node);
ElementData data = new ElementData(node);
data.setTag("foo");
Mockito.when(node.getFeature(ElementData.class)).thenReturn(data);
Mockito.when(parentNode.getId()).thenReturn(3);
handler.handleNode(node, object);
}
use of com.vaadin.flow.internal.StateNode in project flow by vaadin.
the class MapSyncRpcHandlerTest method syncJSON_jsonIsForStateNodeInList_propertySetToStateNodeCopy.
@Test
public void syncJSON_jsonIsForStateNodeInList_propertySetToStateNodeCopy() throws Exception {
// Let's use element's ElementPropertyMap for testing.
TestComponent component = new TestComponent();
Element element = component.getElement();
UI ui = new UI();
ui.add(component);
StateNode node = element.getNode();
// Set model value directly via ElementPropertyMap
ElementPropertyMap propertyMap = node.getFeature(ElementPropertyMap.class);
propertyMap.setUpdateFromClientFilter(name -> true);
ModelList modelList = propertyMap.resolveModelList("foo");
// fake StateNode has been created for the model
StateNode item = new StateNode(ElementPropertyMap.class);
modelList.add(item);
item.getFeature(ElementPropertyMap.class).setProperty("bar", "baz");
// Use the model node id for JSON object which represents a value to
// update
JsonObject json = Json.createObject();
json.put("nodeId", item.getId());
// send sync request
sendSynchronizePropertyEvent(element, ui, TEST_PROPERTY, json);
// Now the model node should be copied and available as the
// TEST_PROPERTY value
Serializable testPropertyValue = propertyMap.getProperty(TEST_PROPERTY);
Assert.assertTrue(testPropertyValue instanceof StateNode);
StateNode newNode = (StateNode) testPropertyValue;
Assert.assertNotEquals(item.getId(), newNode.getId());
Assert.assertEquals("baz", newNode.getFeature(ElementPropertyMap.class).getProperty("bar"));
}
Aggregations