Search in sources :

Example 76 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 77 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 78 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 79 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 80 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)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