Search in sources :

Example 41 with Element

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

the class TemplateElementStateProviderTest method removeProperty_templateHasAttribute_hasNoProperty.

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

Example 42 with Element

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

the class TemplateElementStateProviderTest method setProperty_regularProperty_hasPropertyAndHasProperValue.

@Test
public void setProperty_regularProperty_hasPropertyAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("prop", "foo");
    Assert.assertTrue(element.hasProperty("prop"));
    Assert.assertEquals("foo", element.getProperty("prop"));
    List<String> props = element.getPropertyNames().collect(Collectors.toList());
    Assert.assertEquals(1, props.size());
    Assert.assertEquals("prop", props.get(0));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 43 with Element

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

the class TemplateElementStateProviderTest method templateInChildSlot.

@Test
public void templateInChildSlot() {
    Element parent = createElement("<div>@child@</div>");
    Element child = createElement("<span>The text</span>");
    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 44 with Element

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

the class TemplateElementStateProviderTest method setRegularProperty_templateHasBoundProperty_hasPropertyAndHasProperValue.

@Test
public void setRegularProperty_templateHasBoundProperty_hasPropertyAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div [foo]='bar'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setProperty("prop", "foo");
    Assert.assertTrue(element.hasProperty("prop"));
    Assert.assertEquals("foo", element.getProperty("prop"));
    Set<String> props = element.getPropertyNames().collect(Collectors.toSet());
    Assert.assertEquals(2, props.size());
    Assert.assertTrue(props.contains("foo"));
    Assert.assertTrue(props.contains("prop"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 45 with Element

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

the class TemplateElementStateProviderTest method emptyChildSlot.

@Test
public void emptyChildSlot() {
    Element parent = createElement("<div>@child@</div>");
    Assert.assertEquals(0, parent.getChildCount());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Aggregations

Element (com.vaadin.flow.dom.Element)421 Test (org.junit.Test)332 StateNode (com.vaadin.flow.internal.StateNode)36 UI (com.vaadin.flow.component.UI)33 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)29 HasElement (com.vaadin.flow.component.HasElement)24 Style (com.vaadin.flow.dom.Style)22 JsonObject (elemental.json.JsonObject)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 ArrayList (java.util.ArrayList)18 Component (com.vaadin.flow.component.Component)16 JsonValue (elemental.json.JsonValue)15 DomEvent (com.vaadin.flow.dom.DomEvent)12 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)11 VaadinSession (com.vaadin.flow.server.VaadinSession)11 Assert (org.junit.Assert)11 Tag (com.vaadin.flow.component.Tag)10 ElementFactory (com.vaadin.flow.dom.ElementFactory)10