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));
}
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());
}
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());
}
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());
}
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);
}
Aggregations