Search in sources :

Example 66 with Element

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

the class ElementUtilTest method attachToNull.

@Test(expected = IllegalArgumentException.class)
public void attachToNull() {
    Element e = ElementFactory.createDiv();
    ElementUtil.setComponent(e, null);
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 67 with Element

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

the class ElementUtilTest method attachTwiceToComponent.

@Test(expected = IllegalStateException.class)
public void attachTwiceToComponent() {
    Element e = ElementFactory.createDiv();
    Component c = Mockito.mock(Component.class);
    ElementUtil.setComponent(e, c);
    ElementUtil.setComponent(e, c);
}
Also used : Element(com.vaadin.flow.dom.Element) Component(com.vaadin.flow.component.Component) Test(org.junit.Test)

Example 68 with Element

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

the class TemplateElementStateProviderTest method testNestedTemplateElements.

@Test
public void testNestedTemplateElements() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("parent").addChild(new ElementTemplateBuilder("child0")).addChild(new ElementTemplateBuilder("child1"));
    Element element = createElement(builder);
    Assert.assertEquals(2, element.getChildCount());
    Element child0 = element.getChild(0);
    Assert.assertEquals("child0", child0.getTag());
    Assert.assertEquals(element, child0.getParent());
    Element child1 = element.getChild(1);
    Assert.assertEquals("child1", child1.getTag());
    Assert.assertEquals(element, child1.getParent());
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 69 with Element

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

the class TemplateElementStateProviderTest method removeAttribute_templateHasBoundAttribute_hasNoAttributeAndHasBoundAttribute.

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

Example 70 with Element

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

the class TemplateElementStateProviderTest method setProperty_boundProperty_throwException.

@Test(expected = IllegalArgumentException.class)
public void setProperty_boundProperty_throwException() {
    Element element = createElement("<div [prop]='value'></div>");
    element.setProperty("prop", "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