Search in sources :

Example 1 with View

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

the class ViewRendererTest method reuseSingleView.

@Test
public void reuseSingleView() {
    new TestViewRenderer(TestView.class).handle(dummyEvent);
    List<View> firstChain = ui.getInternals().getActiveViewChain();
    TestView view = (TestView) firstChain.get(0);
    Assert.assertEquals(1, view.locations.size());
    new TestViewRenderer(TestView.class).handle(dummyEvent);
    Assert.assertEquals(2, view.locations.size());
    List<View> secondChain = ui.getInternals().getActiveViewChain();
    Assert.assertNotSame(firstChain, secondChain);
    Assert.assertSame(view, secondChain.get(0));
}
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 2 with View

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

the class ViewRendererTest method showNestedView.

@Test
public void showNestedView() {
    new TestViewRenderer(TestView.class, ParentView.class, AnotherParentView.class).handle(dummyEvent);
    List<View> viewChain = ui.getInternals().getActiveViewChain();
    Assert.assertEquals(3, viewChain.size());
    Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), viewChain.stream().map(Object::getClass).collect(Collectors.toList()));
    Element element = null;
    for (View view : viewChain) {
        Assert.assertEquals(Arrays.asList(dummyEvent.getLocation()), ((TestView) view).locations);
        Element viewElement = view.getElement();
        if (element != null) {
            Assert.assertEquals(viewElement, element.getParent());
        }
        element = viewElement;
    }
    Assert.assertEquals(ui.getElement(), element.getParent());
    Assert.assertEquals(1, ui.getElement().getChildCount());
}
Also used : TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) Element(com.vaadin.flow.dom.Element) 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 3 with View

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

the class ViewRendererTest method testViewReroute.

@Test
public void testViewReroute() {
    TestViewRenderer renderer = new TestViewRenderer(RerouteView.class);
    int statusCode = renderer.handle(dummyEvent);
    Assert.assertEquals(404, statusCode);
    List<View> activeViewChain = ui.getInternals().getActiveViewChain();
    Assert.assertEquals(1, activeViewChain.size());
    Assert.assertSame(DefaultErrorView.class, activeViewChain.get(0).getClass());
}
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 4 with View

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

the class ViewRendererTest method showNestedView.

@Test
public void showNestedView() {
    new TestViewRenderer(TestView.class, ParentView.class, AnotherParentView.class).handle(dummyEvent);
    List<View> viewChain = ui.getInternals().getActiveViewChain();
    Assert.assertEquals(3, viewChain.size());
    Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), viewChain.stream().map(Object::getClass).collect(Collectors.toList()));
    Element element = null;
    for (View view : viewChain) {
        Assert.assertEquals(Arrays.asList(dummyEvent.getLocation()), ((TestView) view).locations);
        Element viewElement = view.getElement();
        if (element != null) {
            Assert.assertEquals(viewElement, element.getParent());
        }
        element = viewElement;
    }
    Assert.assertEquals(ui.getElement(), element.getParent());
    Assert.assertEquals(1, ui.getElement().getChildCount());
}
Also used : Element(com.vaadin.flow.dom.Element) HasChildView(com.vaadin.flow.router.legacy.HasChildView) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) View(com.vaadin.flow.router.legacy.View) Test(org.junit.Test)

Example 5 with View

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

the class ViewRendererTest method showSimpleView.

@Test
public void showSimpleView() {
    new TestViewRenderer(TestView.class).handle(dummyEvent);
    List<View> viewChain = ui.getInternals().getActiveViewChain();
    Assert.assertEquals(1, viewChain.size());
    View viewInstance = viewChain.get(0);
    Assert.assertSame(TestView.class, viewInstance.getClass());
    Assert.assertEquals(ui.getElement(), viewInstance.getElement().getParent());
    Assert.assertEquals(1, ui.getElement().getChildCount());
    Assert.assertEquals(Arrays.asList(dummyEvent.getLocation()), ((TestView) viewInstance).locations);
}
Also used : HasChildView(com.vaadin.flow.router.legacy.HasChildView) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) View(com.vaadin.flow.router.legacy.View) Test(org.junit.Test)

Aggregations

HasChildView (com.vaadin.flow.router.legacy.HasChildView)11 View (com.vaadin.flow.router.legacy.View)11 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)10 Test (org.junit.Test)10 TestViewRenderer (com.vaadin.flow.router.legacy.TestViewRenderer)7 Element (com.vaadin.flow.dom.Element)3 NavigationEvent (com.vaadin.flow.router.NavigationEvent)2 ViewRenderer (com.vaadin.flow.router.legacy.ViewRenderer)2 HasElement (com.vaadin.flow.component.HasElement)1 HashMap (java.util.HashMap)1