Search in sources :

Example 16 with Element

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

the class AddDivUI method addDiv.

private void addDiv() {
    Element bodyElement = getElement();
    Element div = ElementFactory.createDiv("Hello world at " + System.currentTimeMillis() + " (" + msgId++ + ")");
    bodyElement.insertChild(0, div);
    if (msgId % 100 == 0) {
        System.out.println("Pushed id " + msgId + " to " + ip);
    }
// FIXME Enable when remove works
// while (bodyElement.getChildCount() > 20) {
// bodyElement.removeChild(20);
// }
}
Also used : Element(com.vaadin.flow.dom.Element)

Example 17 with Element

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

the class EventUtilTest method getImplementingComponents_elementHasVirtualChildren.

@Test
public void getImplementingComponents_elementHasVirtualChildren() throws Exception {
    Element node = new Element("root");
    node.appendChild(new Element("main"), new Element("menu"));
    Element nested = new Element("nested");
    nested.appendChild(new Element("nested-child"), new Element("nested-child-2"));
    node.getStateProvider().appendVirtualChild(node.getNode(), nested, NodeProperties.TEMPLATE_IN_TEMPLATE, "");
    Component.from(nested, EnterObserver.class);
    List<Element> elements = new ArrayList<>();
    EventUtil.inspectHierarchy(node, elements);
    List<BeforeEnterObserver> listenerComponents = EventUtil.getImplementingComponents(elements.stream(), BeforeEnterObserver.class).collect(Collectors.toList());
    Assert.assertEquals("Wrong amount of listener instances found", 1, listenerComponents.size());
}
Also used : Element(com.vaadin.flow.dom.Element) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with Element

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

the class EventUtilTest method collectLocaleChangeObserverFromElement.

@Test
public void collectLocaleChangeObserverFromElement() throws Exception {
    Element node = new Element("root");
    node.appendChild(new Element("main"), new Element("menu"));
    Element nested = new Element("nested-locale");
    nested.appendChild(new Element("nested-child"), new Element("nested-child-2"));
    node.appendChild(nested);
    Component.from(nested, Locale.class);
    List<LocaleChangeObserver> beforeNavigationObservers = EventUtil.collectLocaleChangeObservers(node);
    Assert.assertEquals("Wrong amount of listener instances found", 1, beforeNavigationObservers.size());
}
Also used : Element(com.vaadin.flow.dom.Element) LocaleChangeObserver(com.vaadin.flow.i18n.LocaleChangeObserver) Test(org.junit.Test)

Example 19 with Element

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

the class EventUtilTest method collectBeforeNavigationObserversFromElement.

@Test
public void collectBeforeNavigationObserversFromElement() throws Exception {
    Element node = new Element("root");
    node.appendChild(new Element("main"), new Element("menu"));
    Element nested = new Element("nested");
    nested.appendChild(new Element("nested-child"), new Element("nested-child-2"));
    node.appendChild(nested);
    Component.from(nested, LeaveObserver.class);
    List<BeforeLeaveObserver> beforeNavigationObservers = EventUtil.collectBeforeLeaveObservers(node);
    Assert.assertEquals("Wrong amount of listener instances found", 1, beforeNavigationObservers.size());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 20 with Element

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

the class InternalServerErrorTest method nonProductionMode_hasLogBinding_showStacktraceAndNoWarning.

@Test
public void nonProductionMode_hasLogBinding_showStacktraceAndNoWarning() {
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    InternalServerError testInstance = new InternalServerError() {

        @Override
        protected boolean hasLogBinding() {
            return true;
        }
    };
    testInstance.setErrorParameter(event, new ErrorParameter<>(new NullPointerException("foo")));
    Assert.assertEquals("2 elements should be shown: exception text and exception stacktrace", 2, testInstance.getElement().getChildCount());
    Element stacktrace = testInstance.getElement().getChild(1);
    Assert.assertEquals("pre", stacktrace.getTag());
    Assert.assertTrue(stacktrace.getText().contains(NullPointerException.class.getName()));
    Assert.assertTrue(stacktrace.getText().contains("foo"));
}
Also used : Element(com.vaadin.flow.dom.Element) 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