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