Search in sources :

Example 11 with Page

use of com.vaadin.flow.component.page.Page in project flow by vaadin.

the class JavaScriptBootstrapUITest method should_not_notify_clientRoute_when_navigatingToTheSame.

@Test
public void should_not_notify_clientRoute_when_navigatingToTheSame() {
    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);
    ui.navigate("clean/");
    Mockito.verify(page, Mockito.never()).executeJs(Mockito.anyString(), Mockito.anyString());
}
Also used : Page(com.vaadin.flow.component.page.Page) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 12 with Page

use of com.vaadin.flow.component.page.Page 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());
}
Also used : StateTree(com.vaadin.flow.internal.StateTree) StateNode(com.vaadin.flow.internal.StateNode) Page(com.vaadin.flow.component.page.Page) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 13 with Page

use of com.vaadin.flow.component.page.Page in project flow by vaadin.

the class PolymerTemplateTest method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws SecurityException, IllegalArgumentException {
    executionOrder.clear();
    executionParams.clear();
    VaadinSession session = Mockito.mock(VaadinSession.class);
    ui = new UI() {

        private Page page = new Page(this) {

            @Override
            public PendingJavaScriptResult executeJs(String expression, Serializable... parameters) {
                executionOrder.add(expression);
                executionParams.add(parameters);
                return null;
            }
        };

        @Override
        public VaadinSession getSession() {
            return session;
        }

        @Override
        public Page getPage() {
            return page;
        }
    };
    VaadinService service = Mockito.mock(VaadinService.class);
    when(session.getService()).thenReturn(service);
    DefaultInstantiator instantiator = new DefaultInstantiator(service);
    when(service.getInstantiator()).thenReturn(instantiator);
    UI.setCurrent(ui);
}
Also used : DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) Serializable(java.io.Serializable) VaadinSession(com.vaadin.flow.server.VaadinSession) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) Page(com.vaadin.flow.component.page.Page) Before(org.junit.Before)

Aggregations

Page (com.vaadin.flow.component.page.Page)13 Location (com.vaadin.flow.router.Location)7 Test (org.junit.Test)7 UI (com.vaadin.flow.component.UI)5 Router (com.vaadin.flow.router.Router)5 Serializable (java.io.Serializable)5 Component (com.vaadin.flow.component.Component)4 NavigationEvent (com.vaadin.flow.router.NavigationEvent)4 HasElement (com.vaadin.flow.component.HasElement)3 ExtendedClientDetails (com.vaadin.flow.component.page.ExtendedClientDetails)3 History (com.vaadin.flow.component.page.History)3 PendingJavaScriptResult (com.vaadin.flow.component.page.PendingJavaScriptResult)3 RouterLayout (com.vaadin.flow.router.RouterLayout)3 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)3 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)3 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)3 RouteRegistry (com.vaadin.flow.server.RouteRegistry)3 AlwaysLockedVaadinSession (com.vaadin.tests.util.AlwaysLockedVaadinSession)3 MockUI (com.vaadin.tests.util.MockUI)3 ArrayList (java.util.ArrayList)3