use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class ViewRendererTest method showNestedView.
@Test
public void showNestedView() {
new TestViewRenderer(TestView.class, ParentView.class, AnotherParentView.class).handle(dummyEvent);
List<View> viewChain = ui.getInternals().getActiveViewChain();
Assert.assertEquals(3, viewChain.size());
Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), viewChain.stream().map(Object::getClass).collect(Collectors.toList()));
Element element = null;
for (View view : viewChain) {
Assert.assertEquals(Arrays.asList(dummyEvent.getLocation()), ((TestView) view).locations);
Element viewElement = view.getElement();
if (element != null) {
Assert.assertEquals(viewElement, element.getParent());
}
element = viewElement;
}
Assert.assertEquals(ui.getElement(), element.getParent());
Assert.assertEquals(1, ui.getElement().getChildCount());
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class ViewRendererTest method showNestedView.
@Test
public void showNestedView() {
new TestViewRenderer(TestView.class, ParentView.class, AnotherParentView.class).handle(dummyEvent);
List<View> viewChain = ui.getInternals().getActiveViewChain();
Assert.assertEquals(3, viewChain.size());
Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), viewChain.stream().map(Object::getClass).collect(Collectors.toList()));
Element element = null;
for (View view : viewChain) {
Assert.assertEquals(Arrays.asList(dummyEvent.getLocation()), ((TestView) view).locations);
Element viewElement = view.getElement();
if (element != null) {
Assert.assertEquals(viewElement, element.getParent());
}
element = viewElement;
}
Assert.assertEquals(ui.getElement(), element.getParent());
Assert.assertEquals(1, ui.getElement().getChildCount());
}
use of com.vaadin.flow.dom.Element in project flow by vaadin.
the class AbstractRpcInvocationHandlerTest method handleVisibleNode_nodeIsHandled.
@Test
public void handleVisibleNode_nodeIsHandled() {
UI ui = new UI();
Element element = createRpcInvocationData(ui, null);
Assert.assertSame(element.getNode(), handler.node);
}
use of com.vaadin.flow.dom.Element 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.dom.Element 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