Search in sources :

Example 21 with RouterLink

use of com.vaadin.flow.router.RouterLink in project flow by vaadin.

the class ShortcutsTest method setShortcutListenOnElementLocatorJs_registrationDoesNotRemoveModifiedData_nullClearsAlways.

@Test
public void setShortcutListenOnElementLocatorJs_registrationDoesNotRemoveModifiedData_nullClearsAlways() {
    final RouterLink routerLink = new RouterLink();
    final String locator = "foobar";
    final Registration registration = Shortcuts.setShortcutListenOnElement(locator, routerLink);
    Assert.assertEquals(locator, ComponentUtil.getData(routerLink, Shortcuts.ELEMENT_LOCATOR_JS_KEY));
    Shortcuts.setShortcutListenOnElement("another", routerLink);
    registration.remove();
    Assert.assertEquals("another", ComponentUtil.getData(routerLink, Shortcuts.ELEMENT_LOCATOR_JS_KEY));
    final Registration nullRegistration = Shortcuts.setShortcutListenOnElement(null, routerLink);
    Assert.assertNull(ComponentUtil.getData(routerLink, Shortcuts.ELEMENT_LOCATOR_JS_KEY));
    nullRegistration.remove();
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) Registration(com.vaadin.flow.shared.Registration) Test(org.junit.Test)

Example 22 with RouterLink

use of com.vaadin.flow.router.RouterLink in project flow by vaadin.

the class JavaScriptBootstrapUITest method addRemoveComponent_clientSideRouting_addsToBody.

@Test
public void addRemoveComponent_clientSideRouting_addsToBody() {
    final Element uiElement = ui.getElement();
    ui.connectClient("foo", "bar", "/clean", "", null);
    // router outlet is a virtual child that is not reflected on element
    // level
    assertEquals(1, ui.getChildren().count());
    assertEquals(0, uiElement.getChildCount());
    assertEquals(0, ui.getElement().getChildCount());
    final RouterLink routerLink = new RouterLink();
    ui.add(routerLink);
    assertEquals(2, ui.getChildren().count());
    assertEquals(1, ui.getElement().getChildCount());
    assertEquals(1, uiElement.getChildCount());
    ui.add(new RouterLink());
    assertEquals(3, ui.getChildren().count());
    assertEquals(2, ui.getElement().getChildCount());
    assertEquals(2, uiElement.getChildCount());
    ui.remove(routerLink);
    assertEquals(2, ui.getChildren().count());
    assertEquals(1, ui.getElement().getChildCount());
    assertEquals(1, uiElement.getChildCount());
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 23 with RouterLink

use of com.vaadin.flow.router.RouterLink in project flow by vaadin.

the class JavaScriptBootstrapUITest method addComponent_serverSideRouterAndNavigation_componentsRemain.

@Test
public void addComponent_serverSideRouterAndNavigation_componentsRemain() {
    Mockito.when(mocks.getSession().getAttribute(SERVER_ROUTING)).thenReturn(Boolean.TRUE);
    final Element uiElement = ui.getElement();
    ui.navigate("clean");
    final RouterLink routerLink = new RouterLink();
    ui.add(routerLink);
    assertEquals(2, ui.getChildren().count());
    assertEquals(2, ui.getElement().getChildCount());
    assertEquals(2, uiElement.getChildCount());
    ui.navigate("product");
    assertEquals(2, ui.getChildren().count());
    assertEquals(2, ui.getElement().getChildCount());
    assertEquals(2, uiElement.getChildCount());
}
Also used : RouterLink(com.vaadin.flow.router.RouterLink) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 24 with RouterLink

use of com.vaadin.flow.router.RouterLink in project flow by vaadin.

the class ComponentEventBusTest method mappedDomEventWithComponentEventData_clientReportsConcreteComponents_mapsComponents.

@Test
public void mappedDomEventWithComponentEventData_clientReportsConcreteComponents_mapsComponents() {
    final MockUI ui = new MockUI();
    final TestComponent component = new TestComponent();
    final TestComponent child = new TestComponent();
    final RouterLink routerLink = new RouterLink();
    component.getElement().appendChild(child.getElement());
    child.getElement().appendChild(routerLink.getElement());
    ui.add(component);
    final EventTracker<MappedDomEventWithRouterLinkData> listener = new EventTracker<>();
    component.addListener(MappedDomEventWithRouterLinkData.class, listener);
    fireDomEvent(component, "dom-event", createStateNodeIdData("component", child.getElement().getNode().getId(), "router.link", routerLink.getElement().getNode().getId()));
    listener.assertEventCalled(component, true);
    Assert.assertEquals(routerLink, listener.getEvent().getRouterLink());
    Assert.assertEquals(child, listener.getEvent().getComponent());
}
Also used : MockUI(com.vaadin.tests.util.MockUI) RouterLink(com.vaadin.flow.router.RouterLink) TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Example 25 with RouterLink

use of com.vaadin.flow.router.RouterLink in project flow by vaadin.

the class ComponentEventBusTest method mappedDomEventWithComponentEventData_clientReportsMissingComponent_mapsComponentAndNull.

@Test
public void mappedDomEventWithComponentEventData_clientReportsMissingComponent_mapsComponentAndNull() {
    final MockUI ui = new MockUI();
    final TestComponent component = new TestComponent();
    final TestComponent child = new TestComponent();
    final RouterLink routerLink = new RouterLink();
    component.getElement().appendChild(child.getElement());
    child.getElement().appendChild(routerLink.getElement());
    ui.add(component);
    final EventTracker<MappedDomEventWithRouterLinkData> listener = new EventTracker<>();
    component.addListener(MappedDomEventWithRouterLinkData.class, listener);
    // null data will be used if event data is missing
    fireDomEvent(component, "dom-event", createStateNodeIdData("component", routerLink.getElement().getNode().getId()));
    listener.assertEventCalled(component, true);
    Assert.assertNull(listener.getEvent().getRouterLink());
    Assert.assertEquals(routerLink, listener.getEvent().getComponent());
    listener.reset();
    fireDomEvent(component, "dom-event", createStateNodeIdData("router.link", routerLink.getElement().getNode().getId()));
    listener.assertEventCalled(component, true);
    Assert.assertEquals(routerLink, listener.getEvent().getRouterLink());
    Assert.assertNull(listener.getEvent().getComponent());
    listener.reset();
}
Also used : MockUI(com.vaadin.tests.util.MockUI) RouterLink(com.vaadin.flow.router.RouterLink) TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Test(org.junit.Test)

Aggregations

RouterLink (com.vaadin.flow.router.RouterLink)30 Test (org.junit.Test)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 TestComponent (com.vaadin.flow.component.ComponentTest.TestComponent)3 Element (com.vaadin.flow.dom.Element)3 MockUI (com.vaadin.tests.util.MockUI)3 Component (com.vaadin.flow.component.Component)2 Div (com.vaadin.flow.component.html.Div)2 DependencyList (com.vaadin.flow.component.internal.DependencyList)2 PendingJavaScriptInvocation (com.vaadin.flow.component.internal.PendingJavaScriptInvocation)2 Registration (com.vaadin.flow.shared.Registration)2 Dependency (com.vaadin.flow.shared.ui.Dependency)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 ComponentUtil (com.vaadin.flow.component.ComponentUtil)1 HasComponents (com.vaadin.flow.component.HasComponents)1 Tag (com.vaadin.flow.component.Tag)1 UI (com.vaadin.flow.component.UI)1 DnDUtilHelper (com.vaadin.flow.component.dnd.internal.DnDUtilHelper)1