Search in sources :

Example 26 with Element

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

the class MapSyncRpcHandlerTest method syncJSON_jsonIsNotListItemAndNotPropertyValue_propertySetToJSON.

@Test
public void syncJSON_jsonIsNotListItemAndNotPropertyValue_propertySetToJSON() throws Exception {
    // Let's use element's ElementPropertyMap for testing.
    TestComponent component = new TestComponent();
    Element element = component.getElement();
    UI ui = new UI();
    ui.add(component);
    StateNode node = element.getNode();
    TestComponent anotherComonent = new TestComponent();
    StateNode anotherNode = anotherComonent.getElement().getNode();
    ElementPropertyMap.getModel(node).setUpdateFromClientFilter(name -> true);
    // Use the model node id for JSON object which represents a value to
    // update
    JsonObject json = Json.createObject();
    json.put("nodeId", anotherNode.getId());
    // send sync request
    sendSynchronizePropertyEvent(element, ui, "foo", json);
    Serializable testPropertyValue = node.getFeature(ElementPropertyMap.class).getProperty("foo");
    Assert.assertNotSame(anotherNode, testPropertyValue);
    Assert.assertTrue(testPropertyValue instanceof JsonValue);
}
Also used : TestComponent(com.vaadin.flow.component.ComponentTest.TestComponent) Serializable(java.io.Serializable) UI(com.vaadin.flow.component.UI) Element(com.vaadin.flow.dom.Element) StateNode(com.vaadin.flow.internal.StateNode) JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) ElementPropertyMap(com.vaadin.flow.internal.nodefeature.ElementPropertyMap) Test(org.junit.Test)

Example 27 with Element

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

the class CustomElementRegistryInitializerTest method creatingElementsWhenMultipleRegisteredCustomTagNamesInRegistryGetCorrectComponentWired.

@Test
public void creatingElementsWhenMultipleRegisteredCustomTagNamesInRegistryGetCorrectComponentWired() throws ServletException {
    customElementRegistryInitializer.onStartup(Stream.of(ValidCustomElement.class, ValidExtendingElement.class, CustomPolymerElement.class).collect(Collectors.toSet()), null);
    Element customElement = new Element("custom-element");
    Assert.assertTrue("CustomElement didn't have a Component", customElement.getComponent().isPresent());
    Assert.assertEquals("CustomElement got unexpected Component", ValidCustomElement.class, customElement.getComponent().get().getClass());
    Element polymerElement = new Element("custom-polymer-element");
    Assert.assertTrue("PolymerElement didn't have a Component", polymerElement.getComponent().isPresent());
    Assert.assertEquals("PolymerElement got unexpected Component", CustomPolymerElement.class, polymerElement.getComponent().get().getClass());
}
Also used : Element(com.vaadin.flow.dom.Element) Test(org.junit.Test)

Example 28 with Element

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

the class AngularTemplateIncludeBuilderTest method templateWithInclude.

@Test
public void templateWithInclude() {
    // <div>
    // <span>Main template</span>
    // @include sub.html@
    // </div>
    // <div>
    // <span>Sub template</span>
    // </div>
    IncludeTemplate template = new IncludeTemplate();
    ElementTemplateNode parentTemplateNode = ((TemplateElementStateProvider) template.getElement().getStateProvider()).getTemplateNode();
    Element element = template.getElement();
    Assert.assertEquals("div", element.getTag());
    List<Element> children = filterOutTextChildren(element);
    Assert.assertEquals("span", children.get(0).getTag());
    Assert.assertEquals("Main template", element.getChild(1).getTextRecursively());
    Element subTemplateElement = children.get(1);
    Assert.assertEquals("div", subTemplateElement.getTag());
    // template node should have the main template as the parent #1176
    ElementTemplateNode includedTemplateNode = ((TemplateElementStateProvider) subTemplateElement.getStateProvider()).getTemplateNode();
    Assert.assertEquals(parentTemplateNode, includedTemplateNode.getParent().get());
    Element span = filterOutTextChildren(subTemplateElement).get(0);
    Assert.assertEquals("span", span.getTag());
    Assert.assertEquals("Sub template", span.getTextRecursively());
}
Also used : Element(com.vaadin.flow.dom.Element) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateElementStateProvider(com.vaadin.flow.dom.impl.TemplateElementStateProvider) Test(org.junit.Test)

Example 29 with Element

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

the class AngularTemplateNodeTest method childElementLookup.

@Test
public void childElementLookup() {
    TemplateNode templateNode = parse("<span><div id='foo'><div></span>");
    Element div = getElement(templateNode).getChild(0);
    Element foundDiv = templateNode.findElement(div.getNode(), "foo").get();
    Assert.assertEquals(div, foundDiv);
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

Example 30 with Element

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

the class AngularTemplateNodeTest method singleElementLookup.

@Test
public void singleElementLookup() {
    TemplateNode templateNode = parse("<div id='foo'><div>");
    Element div = getElement(templateNode);
    Element foundDiv = templateNode.findElement(div.getNode(), "foo").get();
    Assert.assertEquals(div, foundDiv);
}
Also used : TemplateNode(com.vaadin.flow.template.angular.TemplateNode) Element(com.vaadin.flow.dom.Element) Test(org.junit.Test) TemplateElementStateProviderTest(com.vaadin.flow.dom.TemplateElementStateProviderTest)

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