Search in sources :

Example 96 with Element

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

the class TemplateElementStateProviderTest method testHardcodedStyleAttribute.

@Test
public void testHardcodedStyleAttribute() {
    Element element = createElement("<div style='display:none'></div>");
    Assert.assertEquals(1, element.getAttributeNames().count());
    // Test the same after attributes have been migrated to an override node
    element.setProperty("foo", "bar");
    Assert.assertEquals(1, element.getAttributeNames().count());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 97 with Element

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

the class TemplateElementStateProviderTest method setProperty_regularProperty_elementDelegatesPropertyToOverrideNode.

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

Example 98 with Element

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

the class TemplateElementStateProviderTest method removeAttribute_templateHasOneMoreAttribute_hasNoAttribute.

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

Example 99 with Element

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

the class TemplateElementStateProviderTest method testRemoveOverrideChildByIndex.

@Test
public void testRemoveOverrideChildByIndex() {
    Element child = ElementFactory.createAnchor();
    Element parent = createElement("<div></div>");
    parent.appendChild(child);
    parent.removeChild(0);
    Assert.assertEquals(0, parent.getChildCount());
    Assert.assertFalse(parent.getChildren().findFirst().isPresent());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 100 with Element

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

the class TemplateElementStateProviderTest method removeAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode.

@Test
public void removeAttribute_regularAttribute_elementDelegatesAttributeToOverrideNode() {
    TemplateNode node = TemplateParser.parse("<div></div>", new NullTemplateResolver());
    Element element = createElement(node);
    element.setAttribute("attr", "foo");
    element.removeAttribute("attr");
    StateNode overrideNode = element.getNode().getFeature(TemplateOverridesMap.class).get(node, false);
    Assert.assertFalse(BasicElementStateProvider.get().hasAttribute(overrideNode, "attr"));
    List<String> attrs = BasicElementStateProvider.get().getAttributeNames(overrideNode).collect(Collectors.toList());
    Assert.assertEquals(0, attrs.size());
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TemplateOverridesMap(com.vaadin.flow.internal.nodefeature.TemplateOverridesMap) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) 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