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());
}
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());
}
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]))));
}
}
Aggregations