JavaScriptBootstrapUI extends UI { @ClientCallable public void connectClient(String clientElementTag, String clientElementId, String flowRoute) { if (wrapperElement == null) { wrapperElement = new Element(clientElementTag); getElement().getStateProvider().appendVirtualChild( getElement().getNode(), wrapperElement, NodeProperties.INJECT_BY_ID, clientElementId); } final String trimmedRoute = PathUtil.trimPath(flowRoute); if (!trimmedRoute.equals(flowRoute)) { getPage().getHistory().replaceState(null, trimmedRoute); } renderViewForRoute(new Location(trimmedRoute), NavigationTrigger.CLIENT_SIDE); if (getForwardToClientUrl() != null) { navigateToClient(getForwardToClientUrl()); acknowledgeClient(); } else if (isPostponed()) { cancelClient(); } else { acknowledgeClient(); } getSession().setAttribute(SERVER_ROUTING, Boolean.FALSE); } JavaScriptBootstrapUI(); @Override Stream<Component> getChildren(); String getForwardToClientUrl(); @ClientCallable void connectClient(String clientElementTag, String clientElementId,
            String flowRoute); @ClientCallable void leaveNavigation(String route); @Override void navigate(String pathname, QueryParameters queryParameters); static final String SERVER_ROUTING; }
@Test public void should_allow_navigation() { ui.connectClient("foo", "bar", "/clean"); assertEquals(Tag.HEADER, ui.wrapperElement.getChild(0).getTag()); assertEquals(Tag.H2, ui.wrapperElement.getChild(0).getChild(0).getTag()); ui.connectClient("foo", "bar", "/dirty"); assertEquals(Tag.SPAN, ui.wrapperElement.getChild(0).getTag()); assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()); }
@Test public void should_navigate_when_endingSlash() { ui.connectClient("foo", "bar", "/clean/"); assertEquals(Tag.HEADER, ui.wrapperElement.getChild(0).getTag()); assertEquals(Tag.H2, ui.wrapperElement.getChild(0).getChild(0).getTag()); }
@Test public void should_prevent_navigation_on_dirty() { ui.connectClient("foo", "bar", "/dirty"); assertEquals(Tag.SPAN, ui.wrapperElement.getChild(0).getTag()); assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()); ui.connectClient("foo", "bar", "/clean"); assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()); ui.connectClient("foo", "bar", "/errr"); assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()); }
@Test public void should_show_error_page() { ui.connectClient("foo", "bar", "/err"); assertEquals(Tag.DIV, ui.wrapperElement.getChild(0).getTag()); assertTrue(ui.wrapperElement.toString().contains("Available routes:")); }