Search in sources :

Example 11 with TestViewRenderer

use of com.vaadin.flow.router.legacy.TestViewRenderer in project flow by vaadin.

the class ViewRendererTest method testViewTitle_nullPageTitleGenerated_noTitleUpdate.

@Test(expected = AssertionError.class)
public void testViewTitle_nullPageTitleGenerated_noTitleUpdate() {
    setPageTitleGenerator(lce -> null);
    new TestViewRenderer(DynamicTitleView.class).handle(dummyEvent);
}
Also used : TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) Test(org.junit.Test)

Example 12 with TestViewRenderer

use of com.vaadin.flow.router.legacy.TestViewRenderer in project flow by vaadin.

the class ViewRendererTest method testViewInstantiationCustomization.

@Test
public void testViewInstantiationCustomization() {
    // override default implementation of reusing the views if possible
    ViewRenderer renderer = new TestViewRenderer(TestView.class, ParentView.class) {

        @Override
        protected <T extends View> T getView(Class<T> viewType, NavigationEvent event) {
            // always return a new view
            return ReflectTools.createInstance(viewType);
        }
    };
    renderer.handle(dummyEvent);
    View view1 = dummyEvent.getUI().getInternals().getActiveViewChain().get(0);
    View parentView1 = dummyEvent.getUI().getInternals().getActiveViewChain().get(1);
    renderer.handle(dummyEvent);
    View view2 = dummyEvent.getUI().getInternals().getActiveViewChain().get(0);
    View parentView2 = dummyEvent.getUI().getInternals().getActiveViewChain().get(1);
    Assert.assertNotSame(view1, view2);
    Assert.assertNotSame(parentView1, parentView2);
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) ViewRenderer(com.vaadin.flow.router.legacy.ViewRenderer) TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) HasChildView(com.vaadin.flow.router.legacy.HasChildView) View(com.vaadin.flow.router.legacy.View) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) Test(org.junit.Test)

Example 13 with TestViewRenderer

use of com.vaadin.flow.router.legacy.TestViewRenderer in project flow by vaadin.

the class ViewRendererTest method testStatusCode.

@Test
public void testStatusCode() {
    TestViewRenderer renderer = new TestViewRenderer(StatusCodeView.class);
    int statusCode = renderer.handle(dummyEvent);
    // StatusCodeView increments default status code with 1
    Assert.assertEquals(201, statusCode);
}
Also used : TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) Test(org.junit.Test)

Example 14 with TestViewRenderer

use of com.vaadin.flow.router.legacy.TestViewRenderer in project flow by vaadin.

the class ViewRendererTest method reuseFirstParentView.

@Test
public void reuseFirstParentView() {
    new TestViewRenderer(TestView.class, ParentView.class, AnotherParentView.class).handle(dummyEvent);
    List<View> firstChain = ui.getInternals().getActiveViewChain();
    new TestViewRenderer(AnotherTestView.class, AnotherParentView.class).handle(dummyEvent);
    List<View> secondChain = ui.getInternals().getActiveViewChain();
    // Last item in each chain should be reused
    Assert.assertSame(firstChain.get(2), secondChain.get(1));
}
Also used : TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) HasChildView(com.vaadin.flow.router.legacy.HasChildView) View(com.vaadin.flow.router.legacy.View) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) Test(org.junit.Test)

Example 15 with TestViewRenderer

use of com.vaadin.flow.router.legacy.TestViewRenderer in project flow by vaadin.

the class ViewRendererTest method testReuse_orderChanged.

@Test
public void testReuse_orderChanged() {
    new TestViewRenderer(TestView.class, ParentView.class, AnotherParentView.class).handle(dummyEvent);
    List<View> firstChain = ui.getInternals().getActiveViewChain();
    new TestViewRenderer(TestView.class, AnotherParentView.class, ParentView.class).handle(dummyEvent);
    List<View> secondChain = ui.getInternals().getActiveViewChain();
    Assert.assertEquals(Arrays.asList(firstChain.get(0), firstChain.get(2), firstChain.get(1)), secondChain);
}
Also used : TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) HasChildView(com.vaadin.flow.router.legacy.HasChildView) View(com.vaadin.flow.router.legacy.View) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) Test(org.junit.Test)

Aggregations

TestViewRenderer (com.vaadin.flow.router.legacy.TestViewRenderer)17 Test (org.junit.Test)17 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)7 HasChildView (com.vaadin.flow.router.legacy.HasChildView)7 View (com.vaadin.flow.router.legacy.View)7 Element (com.vaadin.flow.dom.Element)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 DefaultPageTitleGenerator (com.vaadin.flow.router.legacy.DefaultPageTitleGenerator)1 ViewRenderer (com.vaadin.flow.router.legacy.ViewRenderer)1