"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "flow-server/src/test/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUITest.java" between
vaadin-flow-4.0.5.tar.gz and vaadin-flow-4.0.6.tar.gz

About: Vaadin flow is a Java framework binding Vaadin web components to Java.

JavaScriptBootstrapUITest.java  (vaadin-flow-4.0.5):JavaScriptBootstrapUITest.java  (vaadin-flow-4.0.6)
package com.vaadin.flow.component.internal; package com.vaadin.flow.component.internal;
import static com.vaadin.flow.component.internal.JavaScriptBootstrapUI.CLIENT_NA
VIGATE_TO;
import static com.vaadin.flow.component.internal.JavaScriptBootstrapUI.SERVER_RO
UTING;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasComponents; import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.Tag; import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.UI; import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.component.page.History; import com.vaadin.flow.component.page.History;
import com.vaadin.flow.component.page.Page; import com.vaadin.flow.component.page.Page;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.impl.BasicElementStateProvider; import com.vaadin.flow.dom.impl.BasicElementStateProvider;
import com.vaadin.flow.internal.CurrentInstance; import com.vaadin.flow.internal.CurrentInstance;
import com.vaadin.flow.internal.StateNode; import com.vaadin.flow.internal.StateNode;
import com.vaadin.flow.internal.StateTree; import com.vaadin.flow.internal.StateTree;
import com.vaadin.flow.router.BeforeEnterEvent; import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver; import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.BeforeLeaveEvent; import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver; import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.InternalServerError; import com.vaadin.flow.router.InternalServerError;
import com.vaadin.flow.router.Location; import com.vaadin.flow.router.Location;
import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route; import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLink;
import com.vaadin.flow.server.InvalidRouteConfigurationException; import com.vaadin.flow.server.InvalidRouteConfigurationException;
import com.vaadin.flow.server.MockServletServiceSessionSetup; import com.vaadin.flow.server.MockServletServiceSessionSetup;
import com.vaadin.flow.server.VaadinRequest; import com.vaadin.flow.server.VaadinRequest;
import org.junit.Assert; import static com.vaadin.flow.component.internal.JavaScriptBootstrapUI.CLIENT_NA
import org.junit.Before; VIGATE_TO;
import org.junit.Test; import static com.vaadin.flow.component.internal.JavaScriptBootstrapUI.SERVER_RO
import org.mockito.ArgumentCaptor; UTING;
import org.mockito.Mockito; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class JavaScriptBootstrapUITest { public class JavaScriptBootstrapUITest {
private static final String CLIENT_PUSHSTATE_TO = "setTimeout(() => window.h istory.pushState($0, '', $1))"; private static final String CLIENT_PUSHSTATE_TO = "setTimeout(() => window.h istory.pushState($0, '', $1))";
private MockServletServiceSessionSetup mocks; private MockServletServiceSessionSetup mocks;
private JavaScriptBootstrapUI ui; private JavaScriptBootstrapUI ui;
@PageTitle("app-shell-title") @PageTitle("app-shell-title")
public static class AppShell implements AppShellConfigurator { public static class AppShell implements AppShellConfigurator {
skipping to change at line 208 skipping to change at line 210
assertEquals(Tag.H2, ui.wrapperElement.getChild(0).getChild(0).getTag()) ; assertEquals(Tag.H2, ui.wrapperElement.getChild(0).getChild(0).getTag()) ;
} }
@Test @Test
public void getChildren_should_notReturnAnEmptyList() { public void getChildren_should_notReturnAnEmptyList() {
ui.connectClient("foo", "bar", "/clean", ""); ui.connectClient("foo", "bar", "/clean", "");
assertEquals(1, ui.getChildren().count()); assertEquals(1, ui.getChildren().count());
} }
@Test @Test
public void addRemoveComponent_clientSideRouting_addsToBody() {
final Element uiElement = ui.getElement();
ui.connectClient("foo", "bar", "/clean", "");
// router outlet is a virtual child that is not reflected on element lev
el
assertEquals(1, ui.getChildren().count());
assertEquals(0, uiElement.getChildCount());
assertEquals(0, ui.getElement().getChildCount());
final RouterLink routerLink = new RouterLink();
ui.add(routerLink);
assertEquals(2, ui.getChildren().count());
assertEquals(1, ui.getElement().getChildCount());
assertEquals(1, uiElement.getChildCount());
ui.add(new RouterLink());
assertEquals(3, ui.getChildren().count());
assertEquals(2, ui.getElement().getChildCount());
assertEquals(2, uiElement.getChildCount());
ui.remove(routerLink);
assertEquals(2, ui.getChildren().count());
assertEquals(1, ui.getElement().getChildCount());
assertEquals(1, uiElement.getChildCount());
}
@Test
public void addRemoveComponent_serverSideRouting_addsDirectlyToUI() {
Mockito.when(mocks.getSession().getAttribute(SERVER_ROUTING))
.thenReturn(Boolean.TRUE);
assertEquals(0, ui.getElement().getChildCount());
assertEquals(0, ui.getChildren().count());
// use any server side route
ui.navigate("product");
assertEquals(1, ui.getElement().getChildCount());
assertEquals(1, ui.getChildren().count());
final RouterLink routerLink = new RouterLink();
ui.add(routerLink);
assertEquals(2, ui.getElement().getChildCount());
assertEquals(2, ui.getChildren().count());
ui.remove(routerLink);
assertEquals(1, ui.getElement().getChildCount());
assertEquals(1, ui.getChildren().count());
}
@Test
public void addComponent_clientSideRouterAndNavigation_componentsRemain() {
final Element uiElement = ui.getElement();
// trigger route via client
ui.connectClient("foo", "bar", "/clean", "");
final RouterLink routerLink = new RouterLink();
ui.add(routerLink);
assertEquals(2, ui.getChildren().count());
assertEquals(1, ui.getElement().getChildCount());
assertEquals(1, uiElement.getChildCount());
ui.navigate("product");
assertEquals(2, ui.getChildren().count());
assertEquals(1, ui.getElement().getChildCount());
assertEquals(1, uiElement.getChildCount());
}
@Test
public void addComponent_serverSideRouterAndNavigation_componentsRemain() {
Mockito.when(mocks.getSession().getAttribute(SERVER_ROUTING))
.thenReturn(Boolean.TRUE);
final Element uiElement = ui.getElement();
ui.navigate("clean");
final RouterLink routerLink = new RouterLink();
ui.add(routerLink);
assertEquals(2, ui.getChildren().count());
assertEquals(2, ui.getElement().getChildCount());
assertEquals(2, uiElement.getChildCount());
ui.navigate("product");
assertEquals(2, ui.getChildren().count());
assertEquals(2, ui.getElement().getChildCount());
assertEquals(2, uiElement.getChildCount());
}
@Test
public void should_prevent_navigation_on_dirty() { public void should_prevent_navigation_on_dirty() {
ui.connectClient("foo", "bar", "/dirty", ""); ui.connectClient("foo", "bar", "/dirty", "");
assertEquals(Tag.SPAN, ui.wrapperElement.getChild(0).getTag()); assertEquals(Tag.SPAN, ui.wrapperElement.getChild(0).getTag());
assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()) ; assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()) ;
// clean view cannot be rendered after dirty // clean view cannot be rendered after dirty
ui.connectClient("foo", "bar", "/clean", ""); ui.connectClient("foo", "bar", "/clean", "");
assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()) ; assertEquals(Tag.H1, ui.wrapperElement.getChild(0).getChild(0).getTag()) ;
// an error route cannot be rendered after dirty // an error route cannot be rendered after dirty
 End of changes. 6 change blocks. 
14 lines changed or deleted 112 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)