Search in sources :

Example 1 with TestLayout

use of com.vaadin.flow.component.CompositeNestedTest.TestLayout in project flow by vaadin.

the class CompositeTest method setup.

@Before
public void setup() {
    compositeWithComponent = new CompositeWithComponent() {

        @Override
        public String toString() {
            return "Composite";
        }
    };
    layoutWithSingleComponentComposite = new TestLayout() {

        @Override
        public String toString() {
            return "Layout";
        }
    };
    layoutWithSingleComponentComposite.addComponent(compositeWithComponent);
    ((TracksAttachDetach) componentInsideLayoutInsideComposite).track();
    compositeWithComponent.track();
    layoutInsideComposite.track();
    layoutWithSingleComponentComposite.track();
    Assert.assertNull(VaadinService.getCurrent());
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    VaadinService.setCurrent(service);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) TestLayout(com.vaadin.flow.component.CompositeNestedTest.TestLayout) TracksAttachDetach(com.vaadin.flow.component.ComponentTest.TracksAttachDetach) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Before(org.junit.Before)

Example 2 with TestLayout

use of com.vaadin.flow.component.CompositeNestedTest.TestLayout in project flow by vaadin.

the class CompositeTest method testOnAttachOnDetachAndEventsOrder.

@Test
public void testOnAttachOnDetachAndEventsOrder() {
    List<Integer> triggered = new ArrayList<>();
    Component component = new Component(new Element("div")) {

        @Override
        protected void onAttach(AttachEvent attachEvent) {
            triggered.add(1);
        }

        @Override
        protected void onDetach(DetachEvent detachEvent) {
            triggered.add(-1);
        }
    };
    component.addAttachListener(event -> triggered.add(2));
    component.addDetachListener(event -> triggered.add(-2));
    Composite<Component> compositeInsideComposite = new Composite<Component>() {

        @Override
        protected Component initContent() {
            return component;
        }

        @Override
        protected void onAttach(AttachEvent attachEvent) {
            triggered.add(3);
        }

        @Override
        protected void onDetach(DetachEvent detachEvent) {
            triggered.add(-3);
        }
    };
    compositeInsideComposite.addAttachListener(event -> triggered.add(4));
    compositeInsideComposite.addDetachListener(event -> triggered.add(-4));
    Composite<Component> composite = new Composite<Component>() {

        @Override
        protected Component initContent() {
            return compositeInsideComposite;
        }

        @Override
        protected void onAttach(AttachEvent attachEvent) {
            triggered.add(5);
        }

        @Override
        protected void onDetach(DetachEvent detachEvent) {
            triggered.add(-5);
        }
    };
    composite.addAttachListener(event -> triggered.add(6));
    composite.addDetachListener(event -> triggered.add(-6));
    UI ui = new UI();
    ui.add(composite);
    TestUtil.assertArrays(triggered.toArray(), new Integer[] { 1, 2, 3, 4, 5, 6 });
    triggered.clear();
    ui.remove(composite);
    TestUtil.assertArrays(triggered.toArray(), new Integer[] { -1, -2, -3, -4, -5, -6 });
    TestLayout container = createTestLayout();
    ui.add(container, composite);
    triggered.clear();
    container.addComponent(composite);
    TestUtil.assertArrays(triggered.toArray(), new Integer[] { -1, -2, -3, -4, -5, -6, 1, 2, 3, 4, 5, 6 });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(com.vaadin.flow.dom.Element) ArrayList(java.util.ArrayList) TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) TestLayout(com.vaadin.flow.component.CompositeNestedTest.TestLayout) Test(org.junit.Test)

Aggregations

TestLayout (com.vaadin.flow.component.CompositeNestedTest.TestLayout)2 TestComponent (com.vaadin.flow.component.ComponentTest.TestComponent)1 TracksAttachDetach (com.vaadin.flow.component.ComponentTest.TracksAttachDetach)1 Element (com.vaadin.flow.dom.Element)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 VaadinService (com.vaadin.flow.server.VaadinService)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Before (org.junit.Before)1 Test (org.junit.Test)1