Search in sources :

Example 36 with Element

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

the class TemplateElementStateProviderTest method emptyChildSlotOrder.

@Test
public void emptyChildSlotOrder() {
    Element parent = createElement("<div><before></before>@child@<after></after></div>");
    Assert.assertEquals(2, parent.getChildCount());
    Assert.assertEquals(Arrays.asList("before", "after"), parent.getChildren().map(Element::getTag).collect(Collectors.toList()));
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 37 with Element

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

the class TemplateElementStateProviderTest method templateStaticStyleAttribute.

@Test
public void templateStaticStyleAttribute() {
    Element element = createElement("<div style='background:blue'></div>");
    Assert.assertEquals("background:blue", element.getAttribute("style"));
    Assert.assertEquals("blue", element.getStyle().get("background"));
    Assert.assertArrayEquals(new Object[] { "style" }, element.getAttributeNames().toArray());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 38 with Element

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

the class TemplateElementStateProviderTest method testElementJsonProperties.

@Test
public void testElementJsonProperties() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("a", new ModelValueBindingProvider("key"));
    Element element = createElement(builder);
    StateNode stateNode = element.getNode();
    JsonObject json = Json.createObject();
    json.put("foo", "bar");
    ModelMap.get(stateNode).setValue("key", json);
    Assert.assertEquals(json, element.getPropertyRaw("a"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a")), element.getPropertyNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) JsonObject(elemental.json.JsonObject) ModelValueBindingProvider(com.vaadin.flow.template.angular.ModelValueBindingProvider) Test(org.junit.Test)

Example 39 with Element

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

the class TemplateElementStateProviderTest method populatedChildSlotOrder.

@Test
public void populatedChildSlotOrder() {
    Element parent = createElement("<div><before></before>@child@<after></after></div>");
    Element child = new Element("child");
    parent.getNode().getFeature(TemplateMap.class).setChild(child.getNode());
    Assert.assertEquals(3, parent.getChildCount());
    Assert.assertEquals(Arrays.asList("before", "child", "after"), parent.getChildren().map(Element::getTag).collect(Collectors.toList()));
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 40 with Element

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

the class TemplateElementStateProviderTest method getBoundAttribute_setRegularAttribute_hasAttributeAndHasProperValue.

@Test
public void getBoundAttribute_setRegularAttribute_hasAttributeAndHasProperValue() {
    TemplateNode node = TemplateParser.parse("<div [attr.attr]='foo'></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("foo", "bar");
    element.getNode().getFeature(ModelMap.class).setValue("foo", "someValue");
    Assert.assertTrue(element.hasAttribute("foo"));
    Assert.assertTrue(element.hasAttribute("attr"));
    Assert.assertEquals("bar", element.getAttribute("foo"));
    Assert.assertEquals("someValue", element.getAttribute("attr"));
    List<String> attrs = element.getAttributeNames().collect(Collectors.toList());
    Assert.assertEquals(2, attrs.size());
    Assert.assertTrue(attrs.contains("attr"));
    Assert.assertTrue(attrs.contains("foo"));
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) 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