Search in sources :

Example 66 with Component

use of com.vaadin.flow.component.Component in project flow by vaadin.

the class PolymerTemplateTest method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    executionOrder.clear();
    executionParams.clear();
    Field customElements = CustomElementRegistry.class.getDeclaredField("customElements");
    customElements.setAccessible(true);
    customElements.set(CustomElementRegistry.getInstance(), new AtomicReference<>());
    Map<String, Class<? extends Component>> map = new HashMap<>();
    map.put("child-template", TemplateChild.class);
    map.put("ffs", TestPolymerTemplate.class);
    map.put("execution-child", ExecutionChild.class);
    CustomElementRegistry.getInstance().setCustomElements(map);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    UI ui = new UI() {

        private Page page = new Page(this) {

            @Override
            public ExecutionCanceler executeJavaScript(String expression, Serializable... parameters) {
                executionOrder.add(expression);
                executionParams.add(parameters);
                return () -> true;
            }
        };

        @Override
        public VaadinSession getSession() {
            return session;
        }

        @Override
        public Page getPage() {
            return page;
        }
    };
    VaadinService service = Mockito.mock(VaadinService.class);
    when(session.getService()).thenReturn(service);
    DefaultInstantiator instantiator = new DefaultInstantiator(service);
    when(service.getInstantiator()).thenReturn(instantiator);
    UI.setCurrent(ui);
}
Also used : Serializable(java.io.Serializable) VaadinSession(com.vaadin.flow.server.VaadinSession) HashMap(java.util.HashMap) Page(com.vaadin.flow.component.page.Page) DefaultInstantiator(com.vaadin.flow.di.DefaultInstantiator) Field(java.lang.reflect.Field) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) Component(com.vaadin.flow.component.Component) Before(org.junit.Before)

Aggregations

Component (com.vaadin.flow.component.Component)66 Test (org.junit.Test)9 Element (com.vaadin.flow.dom.Element)7 UI (com.vaadin.flow.component.UI)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 HasElement (com.vaadin.flow.component.HasElement)2 NativeButton (com.vaadin.flow.component.html.NativeButton)2 VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)2 AfterNavigationEvent (com.vaadin.flow.router.AfterNavigationEvent)2 BeforeEnterEvent (com.vaadin.flow.router.BeforeEnterEvent)2 BeforeLeaveEvent (com.vaadin.flow.router.BeforeLeaveEvent)2 ContinueNavigationAction (com.vaadin.flow.router.BeforeLeaveEvent.ContinueNavigationAction)2 Location (com.vaadin.flow.router.Location)2 LocationChangeEvent (com.vaadin.flow.router.LocationChangeEvent)2 NavigationEvent (com.vaadin.flow.router.NavigationEvent)2 RouterLayout (com.vaadin.flow.router.RouterLayout)2 ErrorStateRenderer (com.vaadin.flow.router.internal.ErrorStateRenderer)2 ViewClassLocator (com.vaadin.flow.uitest.servlet.ViewClassLocator)2 Optional (java.util.Optional)2