use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class JavaScriptBootstrapUITest method addRemoveComponent_serverSideRouting_addsDirectlyToUI.
@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());
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class JavaScriptBootstrapUITest method addComponent_clientSideRouterAndNavigation_componentsRemain.
@Test
public void addComponent_clientSideRouterAndNavigation_componentsRemain() {
final Element uiElement = ui.getElement();
// trigger route via client
ui.connectClient("foo", "bar", "/clean", "", null);
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());
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class AbstractDnDUnitTest method testExtension_mobileDnDpolyfillScriptInjected.
@Test
public void testExtension_mobileDnDpolyfillScriptInjected() {
ui.getInternals().dumpPendingJavaScriptInvocations();
RouterLink component = new RouterLink();
ui.add(component);
runStaticCreateMethodForExtension(component);
List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = ui.getInternals().dumpPendingJavaScriptInvocations();
Assert.assertEquals(1, pendingJavaScriptInvocations.size());
PendingJavaScriptInvocation pendingJavaScriptInvocation = pendingJavaScriptInvocations.get(0);
// the urls are switched to "" by the mocked service method
String fake = String.format(DnDUtilHelper.MOBILE_DND_INJECT_SCRIPT, "", "");
Assert.assertEquals(fake, pendingJavaScriptInvocation.getInvocation().getExpression());
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class AbstractDnDUnitTest method testExtension_activated_usageStatisticsEntryAdded.
@Test
public void testExtension_activated_usageStatisticsEntryAdded() {
runStaticCreateMethodForExtension(new RouterLink());
Assert.assertTrue("No usage statistics for generic dnd reported", UsageStatistics.getEntries().anyMatch(entry -> entry.getName().contains("generic-dnd")));
}
use of com.vaadin.flow.router.RouterLink in project flow by vaadin.
the class DropTargetTest method testDragAndDrop_serverSideDragData.
@Test
public void testDragAndDrop_serverSideDragData() {
RouterLink source = new RouterLink();
ui.add(source);
DragSource<RouterLink> dragSource = DragSource.create(source);
RouterLink target = new RouterLink();
ui.add(target);
DropTarget<RouterLink> dropTarget = DropTarget.create(target);
dragSource.setDragData("FOOBAR");
AtomicReference<DropEvent<RouterLink>> eventCapture = new AtomicReference<>();
dropTarget.addDropListener(eventCapture::set);
ComponentUtil.fireEvent(source, new DragStartEvent<>(source, true));
DropEvent<RouterLink> dropEvent = new DropEvent<>(target, true, "all");
ComponentUtil.fireEvent(target, dropEvent);
DropEvent<RouterLink> actualEvent = eventCapture.get();
Assert.assertEquals(dropEvent, actualEvent);
Assert.assertEquals("FOOBAR", actualEvent.getDragData().orElse(null));
Assert.assertEquals(source, actualEvent.getDragSourceComponent().orElse(null));
// not firing end event for this test but it should be fine as the drag
// data and active source is overridden
ComponentUtil.fireEvent(source, new DragStartEvent<>(source, true));
dragSource.setDragData("another");
ComponentUtil.fireEvent(target, dropEvent);
actualEvent = eventCapture.get();
Assert.assertEquals(dropEvent, actualEvent);
Assert.assertEquals("another", actualEvent.getDragData().orElse(null));
Assert.assertEquals(source, actualEvent.getDragSourceComponent().orElse(null));
}
Aggregations