use of com.vaadin.flow.server.communication.rpc.AttachExistingElementRpcHandler 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.server.communication.rpc.AttachExistingElementRpcHandler in project flow by vaadin.
the class AttachExistingElementRpcHandlerTest method handleNode_error.
@Test
public void handleNode_error() {
AttachExistingElementRpcHandler handler = new AttachExistingElementRpcHandler();
int requestedId = 1;
JsonObject object = Json.createObject();
object.put(JsonConstants.RPC_ATTACH_REQUESTED_ID, requestedId);
object.put(JsonConstants.RPC_ATTACH_ASSIGNED_ID, -1);
object.put(JsonConstants.RPC_ATTACH_TAG_NAME, "div");
object.put(JsonConstants.RPC_ATTACH_INDEX, -1);
StateNode node = Mockito.mock(StateNode.class);
StateNode requested = Mockito.mock(StateNode.class);
StateTree tree = Mockito.mock(StateTree.class);
Mockito.when(node.getOwner()).thenReturn(tree);
Mockito.when(tree.getNodeById(requestedId)).thenReturn(requested);
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);
Mockito.verify(consumer).onError(parentNode, "div", sibling);
assertNodeIsUnregistered(node, requested, feature);
}
use of com.vaadin.flow.server.communication.rpc.AttachExistingElementRpcHandler in project flow by vaadin.
the class AttachExistingElementRpcHandlerTest method handleNode_requestedIdEqualsAssignedId.
@Test
public void handleNode_requestedIdEqualsAssignedId() {
AttachExistingElementRpcHandler handler = new AttachExistingElementRpcHandler();
int requestedId = 1;
int index = 2;
JsonObject object = Json.createObject();
object.put(JsonConstants.RPC_ATTACH_REQUESTED_ID, requestedId);
object.put(JsonConstants.RPC_ATTACH_ASSIGNED_ID, requestedId);
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);
StateTree tree = Mockito.mock(StateTree.class);
Mockito.when(node.getOwner()).thenReturn(tree);
Mockito.when(tree.getNodeById(requestedId)).thenReturn(requested);
Mockito.when(requested.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).insertChild(index, Element.get(requested));
Mockito.verify(consumer).accept(Element.get(requested));
}
Aggregations