Search in sources :

Example 71 with Element

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

the class TemplateElementStateProviderTest method textInChildSlot.

@Test
public void textInChildSlot() {
    Element parent = createElement("<div>@child@</div>");
    Element child = Element.createText("The text");
    parent.getNode().getFeature(TemplateMap.class).setChild(child.getNode());
    Assert.assertEquals(1, parent.getChildCount());
    Assert.assertEquals(1, parent.getChildren().count());
    Assert.assertEquals(parent, child.getParent());
    Assert.assertEquals("The text", parent.getTextRecursively());
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 72 with Element

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

the class TemplateElementStateProviderTest method populatedChildSlot.

@Test
public void populatedChildSlot() {
    Element div = createElement("<div><span>@child@</span></div>");
    Element span = div.getChild(0);
    Element child = ElementFactory.createSpan("child");
    div.getNode().getFeature(TemplateMap.class).setChild(child.getNode());
    Assert.assertEquals(1, span.getChildCount());
    Assert.assertEquals(child, span.getChild(0));
    Assert.assertEquals(span, child.getParent());
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 73 with Element

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

the class TemplateElementStateProviderTest method clearChildSlot_resetChild.

public void clearChildSlot_resetChild() {
    Element parent = createElement("<div>@child@</div>");
    Element child = ElementFactory.createSpan("child");
    TemplateMap templateMap = parent.getNode().getFeature(TemplateMap.class);
    templateMap.setChild(child.getNode());
    Assert.assertEquals(1, parent.getChildCount());
    templateMap.setChild(null);
    Assert.assertEquals(0, parent.getChildCount());
    Assert.assertEquals(0, parent.getChildren().count());
    Assert.assertNull(child.getParent());
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) Element(com.vaadin.flow.dom.Element)

Example 74 with Element

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

the class TemplateElementStateProviderTest method removeAttribute_templateHasAttribute_hasNoAttribute.

@Test
public void removeAttribute_templateHasAttribute_hasNoAttribute() {
    TemplateNode node = TemplateParser.parse("<div foo='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.removeAttribute("foo");
    Assert.assertFalse(element.hasAttribute("foo"));
    List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
    Assert.assertEquals(0, attrs.size());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 75 with Element

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

the class TemplateElementStateProviderTest method testAppendOverrideChild.

@Test
public void testAppendOverrideChild() {
    Element child = ElementFactory.createAnchor();
    Element parent = createElement("<div></div>");
    parent.appendChild(child);
    List<Element> children = parent.getChildren().collect(Collectors.toList());
    Assert.assertEquals(1, children.size());
    Assert.assertEquals(child, children.get(0));
    Assert.assertEquals(parent, child.getParent());
}
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