Search in sources :

Example 51 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ComponentTest method mapToComponentWhichHasComponentField.

@Test
public void mapToComponentWhichHasComponentField() {
    Element e = new Element("div");
    TestComponentWhichHasComponentField c = Component.from(e, TestComponentWhichHasComponentField.class);
    Element buttonElement = c.getElement().getChild(0);
    Assert.assertEquals(e, c.getElement());
    Assert.assertNotEquals(e, buttonElement);
    Assert.assertEquals("button", buttonElement.getTag());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 52 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ComponentTest method setElementTwice.

@Test(expected = IllegalStateException.class)
public void setElementTwice() {
    Component c = new Component(null) {
    };
    Element element = ElementFactory.createDiv();
    Component.setElement(c, element);
    Component.setElement(c, element);
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 53 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ComponentTest method synchronizePropertyWithPropertyName.

@Test
public void synchronizePropertyWithPropertyName() {
    SynchronizePropertyOnChangeGivenPropertyComponent component = new SynchronizePropertyOnChangeGivenPropertyComponent();
    Element element = component.getElement();
    assertSynchronizedProperties(element, "bar");
    assertSynchronizedPropertiesEvents(element, "change");
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 54 with Element

use of com.vaadin.flow.dom.Element in project flow by vaadin.

the class ComponentTest method wrappedComponentGetChildren.

@Test(expected = IllegalStateException.class)
public void wrappedComponentGetChildren() {
    Element div = new Element("div");
    Element button = new Element("button");
    div.appendChild(button);
    button.as(TestButton.class);
    div.as(TestDiv.class).getChildren();
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 55 with Element

use of com.vaadin.flow.dom.Element 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

Element (com.vaadin.flow.dom.Element)377 Test (org.junit.Test)322 UI (com.vaadin.flow.component.UI)42 StateNode (com.vaadin.flow.internal.StateNode)32 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)29 Style (com.vaadin.flow.dom.Style)25 StreamResource (com.vaadin.flow.server.StreamResource)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 ArrayList (java.util.ArrayList)14 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)13 JsonObject (elemental.json.JsonObject)12 WeakReference (java.lang.ref.WeakReference)12 URI (java.net.URI)11 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)10 Registration (com.vaadin.flow.shared.Registration)10 JsonValue (elemental.json.JsonValue)10 ShadowRoot (com.vaadin.flow.dom.ShadowRoot)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 ChildElementConsumer (com.vaadin.flow.dom.ChildElementConsumer)8 AttachExistingElementFeature (com.vaadin.flow.internal.nodefeature.AttachExistingElementFeature)8