Search in sources :

Example 1 with TemplateElementStateProvider

use of com.vaadin.flow.dom.impl.TemplateElementStateProvider 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 2 with TemplateElementStateProvider

use of com.vaadin.flow.dom.impl.TemplateElementStateProvider in project flow by vaadin.

the class AngularTemplateIncludeBuilderTest method templateWithMultipleIncludes.

@Test
public void templateWithMultipleIncludes() {
    // <div>
    // <span>Main template</span>
    // @include subfolder/includes-from-parent.html@
    // </div>
    // <div>
    // @include ../sub.html @
    // </div>
    // <div>
    // <span>Sub template</span>
    // </div>
    MultipleIncludeTemplate template = new MultipleIncludeTemplate();
    ElementTemplateNode node = ((TemplateElementStateProvider) template.getElement().getStateProvider()).getTemplateNode();
    Element element = template.getElement();
    Assert.assertEquals("root-template", element.getTag());
    Element firstSubTemplateElement = filterOutTextChildren(element).get(0);
    ElementTemplateNode firstSubTemplateElementNode = ((TemplateElementStateProvider) firstSubTemplateElement.getStateProvider()).getTemplateNode();
    Assert.assertEquals("includes-from-parent", firstSubTemplateElement.getTag());
    Assert.assertEquals(node, firstSubTemplateElementNode.getParent().get());
    Element secondSubTemplateElement = filterOutTextChildren(firstSubTemplateElement).get(0);
    ElementTemplateNode secondSubTemplateElementNode = ((TemplateElementStateProvider) secondSubTemplateElement.getStateProvider()).getTemplateNode();
    Assert.assertEquals("div", secondSubTemplateElement.getTag());
    Assert.assertEquals(firstSubTemplateElementNode, secondSubTemplateElementNode.getParent().get());
    Element span = filterOutTextChildren(secondSubTemplateElement).get(0);
    Assert.assertEquals("span", span.getTag());
    Assert.assertEquals("Sub template", span.getTextRecursively());
    Assert.assertEquals(secondSubTemplateElementNode, ((TemplateElementStateProvider) span.getStateProvider()).getTemplateNode().getParent().get());
}
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 3 with TemplateElementStateProvider

use of com.vaadin.flow.dom.impl.TemplateElementStateProvider in project flow by vaadin.

the class TemplateElementStateProviderTest method requiredNodeFeatures.

@Test
@SuppressWarnings("unchecked")
public void requiredNodeFeatures() {
    Class<? extends NodeFeature>[] requiredFeatures = new Class[] { TemplateOverridesMap.class };
    TemplateElementStateProvider provider = (TemplateElementStateProvider) createElement("<div></div").getStateProvider();
    // Test that a node with all required features is accepted
    Assert.assertTrue(provider.supports(new StateNode(requiredFeatures)));
    // Test that removing any feature makes it non-accepted
    for (int i = 0; i < requiredFeatures.length; i++) {
        List<Class<? extends NodeFeature>> list = new ArrayList<>(Arrays.asList(requiredFeatures));
        list.remove(i);
        Assert.assertFalse(provider.supports(new StateNode(list.toArray(new Class[0]))));
    }
}
Also used : TemplateOverridesMap(com.vaadin.flow.internal.nodefeature.TemplateOverridesMap) NodeFeature(com.vaadin.flow.internal.nodefeature.NodeFeature) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) TemplateElementStateProvider(com.vaadin.flow.dom.impl.TemplateElementStateProvider) Test(org.junit.Test)

Aggregations

TemplateElementStateProvider (com.vaadin.flow.dom.impl.TemplateElementStateProvider)3 Test (org.junit.Test)3 Element (com.vaadin.flow.dom.Element)2 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)2 StateNode (com.vaadin.flow.internal.StateNode)1 NodeFeature (com.vaadin.flow.internal.nodefeature.NodeFeature)1 TemplateOverridesMap (com.vaadin.flow.internal.nodefeature.TemplateOverridesMap)1 ArrayList (java.util.ArrayList)1