use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class RouterLink method getRouter.
private Router getRouter() {
Router router = null;
if (getElement().getNode().isAttached()) {
StateTree tree = (StateTree) getElement().getNode().getOwner();
router = tree.getUI().getInternals().getRouter();
}
if (router == null) {
router = VaadinService.getCurrent().getRouter();
}
if (router == null) {
throw new IllegalStateException("Implicit router instance is not available. " + "Use overloaded method with explicit router parameter.");
}
return router;
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class JavaScriptBootstrapUITest method should_update_pushState_when_navigationHasBeenAlreadyStarted.
@Test
public void should_update_pushState_when_navigationHasBeenAlreadyStarted() {
ui = Mockito.spy(ui);
Page page = mockPage();
UIInternals internals = mockUIInternals();
Mockito.when(internals.hasLastHandledLocation()).thenReturn(true);
Location lastLocation = new Location("clean");
Mockito.when(internals.getLastHandledLocation()).thenReturn(lastLocation);
StateTree stateTree = Mockito.mock(StateTree.class);
Mockito.when(internals.getStateTree()).thenReturn(stateTree);
Mockito.when(internals.getTitle()).thenReturn("");
StateNode stateNode = BasicElementStateProvider.createStateNode("foo-element");
Mockito.when(stateTree.getRootNode()).thenReturn(stateNode);
ArgumentCaptor<String> execJs = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> execArg = ArgumentCaptor.forClass(String.class);
ui.navigate("clean/1");
Mockito.verify(page).executeJs(execJs.capture(), execArg.capture());
assertEquals(CLIENT_PUSHSTATE_TO, execJs.getValue());
final List<String> execValues = execArg.getAllValues();
assertEquals(2, execValues.size());
assertNull(execValues.get(0));
assertEquals("clean/1", execArg.getValue());
}
use of com.vaadin.flow.internal.StateTree 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.internal.StateTree 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));
}
use of com.vaadin.flow.internal.StateTree in project flow by vaadin.
the class ServerRpcHandlerTest method setup.
@Before
public void setup() {
request = Mockito.mock(VaadinRequest.class);
service = Mockito.mock(VaadinService.class);
session = Mockito.mock(VaadinSession.class);
ui = Mockito.mock(UI.class);
uiInternals = Mockito.mock(UIInternals.class);
dependencyList = Mockito.mock(DependencyList.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(session.getService()).thenReturn(service);
Mockito.when(ui.getInternals()).thenReturn(uiInternals);
Mockito.when(ui.getSession()).thenReturn(session);
Mockito.when(ui.getCsrfToken()).thenReturn(csrfToken);
DeploymentConfiguration deploymentConfiguration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(deploymentConfiguration);
uiTree = new StateTree(uiInternals);
Mockito.when(uiInternals.getStateTree()).thenReturn(uiTree);
Mockito.when(uiInternals.getDependencyList()).thenReturn(dependencyList);
serverRpcHandler = new ServerRpcHandler();
}
Aggregations